1. Compress (string): compress the string by zip, and returns the byte array.
2. Decompress (byte []): restores the compressed byte array to a string.
Purpose: stores strings in 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) return NULL; bytearrayoutputstream = NULL; zipoutputstrea M 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 ();} catch (ioexception localioexception6) {} If (bytearrayoutputstream! = NULL) Try {bytearrayoutputstream. close ();} catch (ioexception localioexception7) {}} return arrayofbyte;} @ suppresswarnings ("UNUSED") public static final string decompress (byte [] paramarrayofbyte) {If (paramarrayofbyte = NULL) return NULL; bytearrayoutputstream = NULL; bytearrayinputstream = NULL; zipinputstream = NULL; string STR; Try {bytearrayoutputstream = new bytearrayoutputstream (); bytearrayinputstream = new bytes (bytes); 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 ();} catch (ioexception localioexception8) {} If (bytearrayinputstream! = NULL) Try {bytearrayinputstream. Close ();} catch (ioexception localioexception9) {} If (bytearrayoutputstream! = NULL) Try {bytearrayoutputstream. Close () ;}catch (ioexception localioexception10) {}} return STR ;}}
from [http://www.open-open.com/lib/view/open1374372029683.html]