[Java Common class library ]
Stringcompress (String compression)
Method Description:
1.compress (String): Zip-Compress a string to return an array of bytes
2.decompress (byte[]): Restores a compressed byte array to a string
Use:
Saved to the database Bolb.
Import Java.io.ByteArrayInputStream;
Import Java.io.ByteArrayOutputStream;
Import java.io.IOException;
Import Java.util.zip.ZipEntry;
Import Java.util.zip.ZipInputStream;
Import Java.util.zip.ZipOutputStream; public class Stringcompress {public static final byte[] Compress (String paramstring) {if (paramstring = null) ret
Urn null;
Bytearrayoutputstream bytearrayoutputstream = null;
Zipoutputstream zipoutputstream = null;
Byte[] Arrayofbyte;
try {bytearrayoutputstream = new Bytearrayoutputstream ();
Zipoutputstream = new Zipoutputstream (bytearrayoutputstream);
Zipoutputstream.putnextentry (New ZipEntry ("0"));
Zipoutputstream.write (Paramstring.getbytes ());
Zipoutputstream.closeentry ();
Arrayofbyte = Bytearrayoutputstream.tobytearray ();
catch (IOException localIOException5) {arrayofbyte = null;
finally {if (zipoutputstream!= null) try {zipoutputstream.close (); The catch (IOException localIOException6) {} if (bytearrayouTputstream!= Null) try {bytearrayoutputstream.close ();
The catch (IOException localIOException7) {}} return arrayofbyte; @SuppressWarnings ("unused") public static final String decompress (byte[] paramarrayofbyte) {if (Paramarrayofbyte =
= null) return null;
Bytearrayoutputstream bytearrayoutputstream = null;
Bytearrayinputstream bytearrayinputstream = null;
Zipinputstream zipinputstream = null;
String str;
try {bytearrayoutputstream = new Bytearrayoutputstream ();
Bytearrayinputstream = new Bytearrayinputstream (paramarrayofbyte);
Zipinputstream = new Zipinputstream (bytearrayinputstream);
ZipEntry localzipentry = Zipinputstream.getnextentry ();
byte[] Arrayofbyte = new byte[1024];
int i =-1;
while ((i = Zipinputstream.read (arrayofbyte))!=-1) bytearrayoutputstream.write (arrayofbyte, 0, I);
str = bytearrayoutputstream.tostring ();
catch (IOException localIOException7) {str = null; finally {if (zipinputsTream!= Null) try {zipinputstream.close (); The catch (IOException LocalIOException8) {} if (Bytearrayinputstream!= null) try {BYTEARRAYINPUTSTREAM.C
Lose (); The catch (IOException LocalIOException9) {} if (Bytearrayoutputstream!= null) try {Bytearrayoutputstream
. Close ();
The catch (IOException localIOException10) {}} return str; }
}