15
15
16
16
public final class LZSEncoding {
17
17
18
+ private LZSEncoding () {};
18
19
private static final char [] keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" .toCharArray (),
19
20
keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$" .toCharArray (),
20
21
valStrBase64 = new char []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -32,7 +33,7 @@ public final class LZSEncoding {
32
33
*/
33
34
public static String compressToBase64 (String uncompressed ) {
34
35
if (uncompressed == null )
35
- return "" ;
36
+ return null ;
36
37
String res = _compress (uncompressed , 6 , keyStrBase64 , 0 );
37
38
switch (res .length () & 3 ) { // To produce valid Base64
38
39
default : // When could this happen ?
@@ -58,8 +59,6 @@ public static String decompressFromBase64(String compressed) {
58
59
if (compressed .isEmpty ())
59
60
return "" ;
60
61
final char [] input = compressed .toCharArray ();
61
- // function(index) { return getBaseValue(keyStrBase64,
62
- // input.charAt(index)); }
63
62
return _decompress (input .length , 32 , input , valStrBase64 , 0 );
64
63
}
65
64
@@ -98,7 +97,7 @@ public static String decompressFromUTF16(String compressed) {
98
97
public static String compressToEncodedURIComponent (String uncompressed ) {
99
98
if (uncompressed == null )
100
99
return null ;
101
- return _compress (uncompressed , 6 , keyStrUriSafe , 0 ) + ' ' ;
100
+ return _compress (uncompressed , 6 , keyStrUriSafe , 0 ) + '+ ' ;
102
101
}
103
102
/**
104
103
* Decompresses a String that had been compressed with {@link #compressToEncodedURIComponent(String)}.
@@ -108,7 +107,6 @@ public static String compressToEncodedURIComponent(String uncompressed) {
108
107
public static String decompressFromEncodedURIComponent (String compressed ) {
109
108
if (compressed == null ) return null ;
110
109
if (compressed .isEmpty ()) return "" ;
111
- compressed = compressed .replace (' ' , '+' );
112
110
final char [] input = compressed .toCharArray ();
113
111
return _decompress (input .length , 32 , input , valStrUriSafe , 0 );
114
112
}
0 commit comments