mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-14 03:32:06 +01:00
Use NO_WRAP/DONT_BREAK_LINES when doing Base64 encoding
This commit is contained in:
parent
34bc13bec7
commit
51083b014e
4 changed files with 15 additions and 7 deletions
|
@ -26,6 +26,8 @@ public class AndroidBase64Encoder implements org.jivesoftware.smack.util.stringe
|
|||
|
||||
private static AndroidBase64Encoder instance = new AndroidBase64Encoder();
|
||||
|
||||
private static final int BASE64_ENCODER_FLAGS = Base64.NO_WRAP;
|
||||
|
||||
private AndroidBase64Encoder() {
|
||||
// Use getInstance()
|
||||
}
|
||||
|
@ -46,12 +48,12 @@ public class AndroidBase64Encoder implements org.jivesoftware.smack.util.stringe
|
|||
|
||||
@Override
|
||||
public String encodeToString(byte[] input, int offset, int len) {
|
||||
return Base64.encodeToString(input, offset, len, Base64.DEFAULT);
|
||||
return Base64.encodeToString(input, offset, len, BASE64_ENCODER_FLAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encode(byte[] input, int offset, int len) {
|
||||
return Base64.encode(input, offset, len, Base64.DEFAULT);
|
||||
return Base64.encode(input, offset, len, BASE64_ENCODER_FLAGS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ public class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
|||
|
||||
private static AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();
|
||||
|
||||
private static final int BASE64_ENCODER_FLAGS = Base64.URL_SAFE | Base64.NO_WRAP;
|
||||
|
||||
private AndroidBase64UrlSafeEncoder() {
|
||||
// Use getInstance()
|
||||
}
|
||||
|
@ -42,7 +44,7 @@ public class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
|||
@Override
|
||||
public String encode(String string) {
|
||||
try {
|
||||
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), Base64.URL_SAFE);
|
||||
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException("UTF-8 not supported", e);
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ public class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
|||
|
||||
@Override
|
||||
public String decode(String string) {
|
||||
byte[] bytes = Base64.decode(string, Base64.URL_SAFE);
|
||||
byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS);
|
||||
try {
|
||||
return new String(bytes, StringUtils.UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
|
|
@ -28,6 +28,8 @@ public class Java7Base64Encoder implements org.jivesoftware.smack.util.stringenc
|
|||
|
||||
private static Java7Base64Encoder instance = new Java7Base64Encoder();
|
||||
|
||||
private static int BASE64_ENCODER_FLAGS = Base64.URL_SAFE;
|
||||
|
||||
private Java7Base64Encoder() {
|
||||
// Use getInstance()
|
||||
}
|
||||
|
@ -48,7 +50,7 @@ public class Java7Base64Encoder implements org.jivesoftware.smack.util.stringenc
|
|||
|
||||
@Override
|
||||
public String encodeToString(byte[] input, int offset, int len) {
|
||||
return Base64.encodeBytes(input, offset, len);
|
||||
return Base64.encodeBytes(input, offset, len, BASE64_ENCODER_FLAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,8 @@ public class Java7Base64UrlSafeEncoder implements StringEncoder {
|
|||
|
||||
private static Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();
|
||||
|
||||
private static int BASE64_ENCODER_FLAGS = Base64.URL_SAFE | Base64.DONT_BREAK_LINES;
|
||||
|
||||
private Java7Base64UrlSafeEncoder() {
|
||||
// Use getInstance()
|
||||
}
|
||||
|
@ -43,11 +45,11 @@ public class Java7Base64UrlSafeEncoder implements StringEncoder {
|
|||
}
|
||||
|
||||
public String encode(String s) {
|
||||
return Base64.encodeBytes(s.getBytes(), Base64.URL_SAFE);
|
||||
return Base64.encodeBytes(s.getBytes(), BASE64_ENCODER_FLAGS);
|
||||
}
|
||||
|
||||
public String decode(String s) {
|
||||
return new String(Base64.decode(s, Base64.URL_SAFE));
|
||||
return new String(Base64.decode(s, BASE64_ENCODER_FLAGS));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue