mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +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 AndroidBase64Encoder instance = new AndroidBase64Encoder();
|
||||||
|
|
||||||
|
private static final int BASE64_ENCODER_FLAGS = Base64.NO_WRAP;
|
||||||
|
|
||||||
private AndroidBase64Encoder() {
|
private AndroidBase64Encoder() {
|
||||||
// Use getInstance()
|
// Use getInstance()
|
||||||
}
|
}
|
||||||
|
@ -46,12 +48,12 @@ public class AndroidBase64Encoder implements org.jivesoftware.smack.util.stringe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String encodeToString(byte[] input, int offset, int len) {
|
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
|
@Override
|
||||||
public byte[] encode(byte[] input, int offset, int len) {
|
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 AndroidBase64UrlSafeEncoder instance = new AndroidBase64UrlSafeEncoder();
|
||||||
|
|
||||||
|
private static final int BASE64_ENCODER_FLAGS = Base64.URL_SAFE | Base64.NO_WRAP;
|
||||||
|
|
||||||
private AndroidBase64UrlSafeEncoder() {
|
private AndroidBase64UrlSafeEncoder() {
|
||||||
// Use getInstance()
|
// Use getInstance()
|
||||||
}
|
}
|
||||||
|
@ -42,7 +44,7 @@ public class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
||||||
@Override
|
@Override
|
||||||
public String encode(String string) {
|
public String encode(String string) {
|
||||||
try {
|
try {
|
||||||
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), Base64.URL_SAFE);
|
return Base64.encodeToString(string.getBytes(StringUtils.UTF8), BASE64_ENCODER_FLAGS);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new IllegalStateException("UTF-8 not supported", e);
|
throw new IllegalStateException("UTF-8 not supported", e);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,7 @@ public class AndroidBase64UrlSafeEncoder implements StringEncoder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String decode(String string) {
|
public String decode(String string) {
|
||||||
byte[] bytes = Base64.decode(string, Base64.URL_SAFE);
|
byte[] bytes = Base64.decode(string, BASE64_ENCODER_FLAGS);
|
||||||
try {
|
try {
|
||||||
return new String(bytes, StringUtils.UTF8);
|
return new String(bytes, StringUtils.UTF8);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
|
|
@ -28,6 +28,8 @@ public class Java7Base64Encoder implements org.jivesoftware.smack.util.stringenc
|
||||||
|
|
||||||
private static Java7Base64Encoder instance = new Java7Base64Encoder();
|
private static Java7Base64Encoder instance = new Java7Base64Encoder();
|
||||||
|
|
||||||
|
private static int BASE64_ENCODER_FLAGS = Base64.URL_SAFE;
|
||||||
|
|
||||||
private Java7Base64Encoder() {
|
private Java7Base64Encoder() {
|
||||||
// Use getInstance()
|
// Use getInstance()
|
||||||
}
|
}
|
||||||
|
@ -48,7 +50,7 @@ public class Java7Base64Encoder implements org.jivesoftware.smack.util.stringenc
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String encodeToString(byte[] input, int offset, int len) {
|
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
|
@Override
|
||||||
|
|
|
@ -34,6 +34,8 @@ public class Java7Base64UrlSafeEncoder implements StringEncoder {
|
||||||
|
|
||||||
private static Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();
|
private static Java7Base64UrlSafeEncoder instance = new Java7Base64UrlSafeEncoder();
|
||||||
|
|
||||||
|
private static int BASE64_ENCODER_FLAGS = Base64.URL_SAFE | Base64.DONT_BREAK_LINES;
|
||||||
|
|
||||||
private Java7Base64UrlSafeEncoder() {
|
private Java7Base64UrlSafeEncoder() {
|
||||||
// Use getInstance()
|
// Use getInstance()
|
||||||
}
|
}
|
||||||
|
@ -43,11 +45,11 @@ public class Java7Base64UrlSafeEncoder implements StringEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String encode(String s) {
|
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) {
|
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