/* package whatever; // don't place package name! */
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static final String encoding
= "UTF-8";
String s
= "123456789 a s d f g h j k l ; ' q w e r t y u i o p [ ] \\ 1 2 3 4 5 6 7 8 9 0 - = as df gh jk l; zx cv bn m, ./ qw er ty ui op []"; s += "qwe rty uio p[] asd fgh jkl zxc vbn m,. 123 456 789 1234 5678 90-= qwer tyui op[] asdf ghjk l;zx cvbn m,./";
s += "12345 67890 qwert yuiop asdfg hjklz xcvbn m,khg er xcgvdst 453 gd fyrt634 5 dg e653 545u7r ydf dgfsd fsart sdgdsg";
String compressed
= compress
(s
); System.
out.
println("Original_String_Length = " + s.
length()); System.
out.
println("Compressed_String_Length = " + compressed.
length());
String decompressed
= decompress
(decodeBase64
(compressed
)); System.
out.
println("Decompressed_String_Length = " + decompressed.
length() + " == Original_String_Length (" + s.
length() + ")"); System.
out.
println("Original_String == Decompressed_String = " + (s.
equals(decompressed
) ? "True" : "False")); }
byte[] bytes = str.getBytes(encoding);
deflater.setInput(bytes);
deflater.finish();
byte[] buffer = new byte[1024];
while(!deflater.finished()) {
int count = deflater.deflate(buffer);
bos.write(buffer, 0, count);
}
bos.close();
byte[] output = bos.toByteArray();
return encodeBase64(output);
}
inflater.setInput(bytes);
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
bos.write(buffer, 0, count);
}
bos.close();
byte[] output = bos.toByteArray();
}
BASE64Encoder base64Encoder = new BASE64Encoder();
return base64Encoder.encodeBuffer(bytes).replace("\r\n", "").replace("\n", "");
}
BASE64Decoder base64Decoder = new BASE64Decoder();
return base64Decoder.decodeBuffer(str);
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IHN1bi5taXN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