Skip to content

Instantly share code, notes, and snippets.

@hujj0615
Created December 4, 2012 07:36
Show Gist options
  • Save hujj0615/4201575 to your computer and use it in GitHub Desktop.
Save hujj0615/4201575 to your computer and use it in GitHub Desktop.
java gzip compress example
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