Java IO Tutorial - Java Pack200.newUnpacker()








Syntax

Pack200.newUnpacker() has the following syntax.

public static Pack200.Unpacker newUnpacker()

Example

In the following code shows how to use Pack200.newUnpacker() method.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.GZIPInputStream;
/*from w ww  .  j a  va 2 s .co m*/
public class Main {

  public static void main(String[] args) throws Exception {

    String inName = "abc.pack.gz";
    String outName = "abc";

    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream(outName));
    InputStream in = new FileInputStream(inName);
    if (inName.endsWith(".gz")){
      in = new GZIPInputStream(in);
    }
      
    unpacker.unpack(in, out);
    out.close();
  }
}