Java by API/java.util.jar/Pack200 — различия между версиями

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

Текущая версия на 14:43, 31 мая 2010

PackewPacker()

  
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.jar.JarFile;
import java.util.jar.Pack200;
public class Main {
  public static void main(String[] args) throws Exception {
    JarFile f = new JarFile("a.jar");
    Pack200.Packer packer = Pack200.newPacker();
    OutputStream out = new FileOutputStream("a.pack");
    packer.pack(f, out);
    out.close();
  }
}





PackewUnpacker()

       
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
public class Main {
  public static void main(String[] args) throws Exception {
    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream("outName"));
    InputStream in = new FileInputStream("inName");
    // in = new GZIPInputStream(in);
    unpacker.unpack(in, out);
    out.close();
  }
}





Pack200.Packer.pack(JarFile in, OutputStream out)

   
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.jar.JarFile;
import java.util.jar.Pack200;
public class Main {
  public static void main(String[] args) throws Exception {
    OutputStream out = null;
    JarFile f = new JarFile(args[0]);
    Pack200.Packer packer = Pack200.newPacker();
    out = new FileOutputStream(args[0] + ".pack");
    packer.pack(f, out);
    out.close();
  }
}





Packnpacker.unpack(InputStream in, JarOutputStream out)

       
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
public class Main {
  public static void main(String[] args) throws Exception {
    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream("outName"));
    InputStream in = new FileInputStream("inName");
    // in = new GZIPInputStream(in);
    unpacker.unpack(in, out);
    out.close();
  }
}