base64 \r\r\n解决

This commit is contained in:
jiangzhongxiang 2019-06-15 18:35:47 +08:00
parent c9cec71a77
commit af08f8c252
1 changed files with 29 additions and 4 deletions

View File

@ -44,10 +44,35 @@ public class Base64Util {
* @return
*/
public static String reencode(String code) {
String str = decode(code);
str = str.replace("\n", "\r\n");
return encode(str);
}
String str = decode(code);
//str = str.replace("\n", "\r\n");
str = replaceLineFeed(str);
return encode(str);
}
private static String replaceLineFeed(String str) {
StringBuilder sb = new StringBuilder();
char[] cs = str.toCharArray();
int len = cs.length;
for (int i = 0; i < len; i++) {
char c = cs[i];
if (c == '\n') {
if (i == 0) {
sb.append('\r').append(c);
} else {
char pre = cs[i - 1];
if (pre == '\r') {
sb.append(c);
} else {
sb.append('\r').append(c);
}
}
} else {
sb.append(c);
}
}
return sb.toString();
}
/**
* 正常编码