Created
October 18, 2015 12:50
-
-
Save elevenetc/fa1645a2c4468136bc72 to your computer and use it in GitHub Desktop.
Compress.java
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 void compress(byte[] input) { | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); | |
Deflater compressor = new Deflater(); | |
compressor.setLevel(Deflater.BEST_COMPRESSION); | |
compressor.setInput(input); | |
compressor.finish(); | |
byte[] buf = new byte[1024]; | |
while (!compressor.finished()) { | |
int count = compressor.deflate(buf); | |
bos.write(buf, 0, count); | |
} | |
try { | |
bos.close(); | |
} catch (IOException e) { | |
} | |
// Get the compressed data | |
byte[] compressedData = bos.toByteArray(); | |
int compressedLength = compressedData.length; | |
int inputLengthlength = input.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment