Java by API/java.util.zip/Inflater

Материал из Java эксперт
Перейти к: навигация, поиск

Inflater: inflate(byte[] b)

   <source lang="java">

import java.io.ByteArrayOutputStream; import java.util.zip.Inflater; public class Main {

 public static void main(String[] argv) throws Exception {
   byte[] compressedData = null;
   Inflater decompressor = new Inflater();
   decompressor.setInput(compressedData);
   ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
   byte[] buf = new byte[1024];
   while (!decompressor.finished()) {
     int count = decompressor.inflate(buf);
     bos.write(buf, 0, count);
   }
   bos.close();
   byte[] decompressedData = bos.toByteArray();
 }

}

 </source>
   
  
 
  



Inflater: setInput(byte[] b)

   <source lang="java">

import java.io.ByteArrayOutputStream; import java.util.zip.Inflater; public class Main {

 public static void main(String[] argv) throws Exception {
   byte[] compressedData = null;
   Inflater decompressor = new Inflater();
   decompressor.setInput(compressedData);
   ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
   byte[] buf = new byte[1024];
   while (!decompressor.finished()) {
     int count = decompressor.inflate(buf);
     bos.write(buf, 0, count);
   }
   bos.close();
   byte[] decompressedData = bos.toByteArray();
 }

}

 </source>
   
  
 
  



new Inflater()

   <source lang="java">

import java.io.ByteArrayOutputStream; import java.util.zip.Inflater; public class Main {

 public static void main(String[] argv) throws Exception {
   byte[] compressedData = null;
   Inflater decompressor = new Inflater();
   decompressor.setInput(compressedData);
   ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
   byte[] buf = new byte[1024];
   while (!decompressor.finished()) {
     int count = decompressor.inflate(buf);
     bos.write(buf, 0, count);
   }
   bos.close();
   byte[] decompressedData = bos.toByteArray();
 }

}

 </source>