Created
December 4, 2012 07:36
-
-
Save hujj0615/4201575 to your computer and use it in GitHub Desktop.
java gzip compress example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void compress(byte[] in) throws IOException { | |
System.out.println("before compress size: " + in.length); | |
byte[] out = null; | |
ByteArrayInputStream bi = new ByteArrayInputStream(in); | |
ByteArrayOutputStream bo = new ByteArrayOutputStream(); | |
GZIPOutputStream go = new GZIPOutputStream(bo); | |
byte[] bb = new byte[1024]; | |
while(bi.read(bb) != -1) | |
go.write(bb); | |
out = bo.toByteArray(); | |
System.out.println("after compress size: " + out.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment