1 7 package java.util.jar; 8 9 import java.util.SortedMap ; 10 import java.io.InputStream ; 11 import java.io.OutputStream ; 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.beans.PropertyChangeListener ; 15 import java.beans.PropertyChangeEvent ; 16 import java.security.AccessController ; 17 import java.security.PrivilegedAction ; 18 19 20 21 22 94 public abstract class Pack200 { 95 private Pack200() {} 97 118 public synchronized static Packer newPacker() { 119 return (Packer) newInstance(PACK_PROVIDER); 120 } 121 122 123 143 144 public static Unpacker newUnpacker() { 145 return (Unpacker) newInstance(UNPACK_PROVIDER); 146 } 147 148 197 public interface Packer { 198 222 String SEGMENT_LIMIT = "pack.segment.limit"; 223 224 236 String KEEP_FILE_ORDER = "pack.keep.file.order"; 237 238 239 253 String EFFORT = "pack.effort"; 254 255 274 String DEFLATE_HINT = "pack.deflate.hint"; 275 276 299 String MODIFICATION_TIME = "pack.modification.time"; 300 301 327 String PASS_FILE_PFX = "pack.pass.file."; 328 329 331 353 String UNKNOWN_ATTRIBUTE = "pack.unknown.attribute"; 354 355 385 String CLASS_ATTRIBUTE_PFX = "pack.class.attribute."; 386 387 396 String FIELD_ATTRIBUTE_PFX = "pack.field.attribute."; 397 398 407 String METHOD_ATTRIBUTE_PFX = "pack.method.attribute."; 408 409 418 String CODE_ATTRIBUTE_PFX = "pack.code.attribute."; 419 420 431 String PROGRESS = "pack.progress"; 432 433 437 String KEEP = "keep"; 438 439 446 String PASS = "pass"; 447 448 455 String STRIP = "strip"; 456 457 464 String ERROR = "error"; 465 466 470 String TRUE = "true"; 471 472 476 String FALSE = "false"; 477 478 481 String LATEST = "latest"; 482 483 510 SortedMap <String ,String > properties(); 511 512 520 void pack(JarFile in, OutputStream out) throws IOException ; 521 522 536 void pack(JarInputStream in, OutputStream out) throws IOException ; 537 538 546 void addPropertyChangeListener(PropertyChangeListener listener) ; 547 548 555 void removePropertyChangeListener(PropertyChangeListener listener); 556 557 } 558 559 569 public interface Unpacker { 570 571 574 String KEEP = "keep"; 575 576 579 String TRUE = "true"; 580 581 584 String FALSE = "false"; 585 586 594 String DEFLATE_HINT = "unpack.deflate.hint"; 595 596 597 598 609 String PROGRESS = "unpack.progress"; 610 611 635 SortedMap <String ,String > properties(); 636 637 650 void unpack(InputStream in, JarOutputStream out) throws IOException ; 651 652 661 void unpack(File in, JarOutputStream out) throws IOException ; 662 663 671 void addPropertyChangeListener(PropertyChangeListener listener) ; 672 673 680 void removePropertyChangeListener(PropertyChangeListener listener); 681 } 682 683 685 private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer"; 686 private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker"; 687 688 private static Class packerImpl; 689 private static Class unpackerImpl; 690 691 private synchronized static Object newInstance(String prop) { 692 String implName = "(unknown)"; 693 try { 694 Class impl = (prop == PACK_PROVIDER)? packerImpl: unpackerImpl; 695 if (impl == null) { 696 implName = (String ) 698 java.security.AccessController.doPrivileged 699 (new sun.security.action.GetPropertyAction(prop,"")); 700 if (implName != null && !implName.equals("")) 701 impl = Class.forName(implName); 702 else if (prop == PACK_PROVIDER) 703 impl = com.sun.java.util.jar.pack.PackerImpl.class; 704 else 705 impl = com.sun.java.util.jar.pack.UnpackerImpl.class; 706 } 707 return impl.newInstance(); 709 } catch (ClassNotFoundException e) { 710 throw new Error ("Class not found: " + implName + 711 ":\ncheck property " + prop + 712 " in your properties file.", e); 713 } catch (InstantiationException e) { 714 throw new Error ("Could not instantiate: " + implName + 715 ":\ncheck property " + prop + 716 " in your properties file.", e); 717 } catch (IllegalAccessException e) { 718 throw new Error ("Cannot access class: " + implName + 719 ":\ncheck property " + prop + 720 " in your properties file.", e); 721 } 722 } 723 724 } 725 726 | Popular Tags |