Guest User

Untitled

a guest
Oct 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package com.vmykhailyk.compression.deflate;
  2.  
  3. import org.apache.commons.codec.binary.Base64;
  4.  
  5. import java.io.ByteArrayOutputStream;
  6. import java.util.zip.DataFormatException;
  7. import java.util.zip.Inflater;
  8.  
  9. public class DeflateDecompressor {
  10. private Inflater decompressor;
  11. private ByteArrayOutputStream outputStream;
  12.  
  13. public DeflateDecompressor() {
  14. decompressor = new Inflater();
  15. outputStream = new ByteArrayOutputStream();
  16. }
  17.  
  18. public String decompress(String data) {
  19. try {
  20. decompressor.reset();
  21. outputStream.reset();
  22. decompressor.setInput(Base64.decodeBase64(data));
  23.  
  24. byte[] buffer = new byte[1024];
  25. while (!decompressor.finished()) {
  26. int dataLength = decompressor.inflate(buffer);
  27. outputStream.write(buffer, 0, dataLength);
  28. }
  29.  
  30. return new String(outputStream.toByteArray(), "UTF-8");
  31. } catch (DataFormatException e) {
  32. e.printStackTrace();
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. return null;
  37. }
  38. }
Add Comment
Please, Sign In to add comment