src/share/classes/java/util/jar/Pack200.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File jdk Sdiff src/share/classes/java/util/jar

src/share/classes/java/util/jar/Pack200.java

Print this page




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.jar;
  26 

  27 import java.util.SortedMap;
  28 import java.io.InputStream;
  29 import java.io.OutputStream;
  30 import java.io.File;
  31 import java.io.IOException;
  32 import java.beans.PropertyChangeListener;
  33 
  34 
  35 
  36 
  37 /**
  38  * Transforms a JAR file to or from a packed stream in Pack200 format.
  39  * Please refer to Network Transfer Format JSR 200 Specification at
  40  * <a href=http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html>http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html</a>
  41  * <p>
  42  * Typically the packer engine is used by application developers
  43  * to deploy or host JAR files on a website.
  44  * The unpacker  engine is used by deployment applications to
  45  * transform the byte-stream back to JAR format.
  46  * <p>


 557         /**
 558          * Takes a JarInputStream and converts it into a Pack200 archive.
 559          * <p>
 560          * Closes its input but not its output.  (Pack200 archives are appendable.)
 561          * <p>
 562          * The modification time and deflation hint attributes are not available,
 563          * for the JAR manifest file and its containing directory.
 564          *
 565          * @see #MODIFICATION_TIME
 566          * @see #DEFLATE_HINT
 567          * @param in a JarInputStream
 568          * @param out an OutputStream
 569          * @exception IOException if an error is encountered.
 570          */
 571         void pack(JarInputStream in, OutputStream out) throws IOException ;
 572 
 573         /**
 574          * Registers a listener for PropertyChange events on the properties map.
 575          * This is typically used by applications to update a progress bar.
 576          *




 577          * @see #properties
 578          * @see #PROGRESS
 579          * @param listener  An object to be invoked when a property is changed.
 580          * @deprecated The dependency on {@code PropertyChangeListener} creates
 581          *             a significant impediment to future modularization of the
 582          *             Java platform. This method will be removed in a future
 583          *             release.
 584          *             Applications that need to monitor progress of the packer
 585          *             can poll the value of the {@link #PROGRESS PROGRESS}
 586          *             property instead.
 587          */
 588         @Deprecated
 589         void addPropertyChangeListener(PropertyChangeListener listener) ;


 590 
 591         /**
 592          * Remove a listener for PropertyChange events, added by
 593          * the {@link #addPropertyChangeListener}.
 594          *




 595          * @see #addPropertyChangeListener
 596          * @param listener  The PropertyChange listener to be removed.
 597          * @deprecated The dependency on {@code PropertyChangeListener} creates
 598          *             a significant impediment to future modularization of the
 599          *             Java platform. This method will be removed in a future
 600          *             release.
 601          */
 602         @Deprecated
 603         void removePropertyChangeListener(PropertyChangeListener listener);
 604 

 605     }
 606 
 607     /**
 608      * The unpacker engine converts the packed stream to a JAR file.
 609      * An instance of the engine can be obtained
 610      * using {@link #newUnpacker}.
 611      * <p>
 612      * Every JAR file produced by this engine will include the string
 613      * "<tt>PACK200</tt>" as a zip file comment.
 614      * This allows a deployer to detect if a JAR archive was packed and unpacked.
 615      * <p>
 616      * Note: Unless otherwise noted, passing a <tt>null</tt> argument to a
 617      * constructor or method in this class will cause a {@link NullPointerException}
 618      * to be thrown.
 619      * <p>
 620      * This version of the unpacker is compatible with all previous versions.
 621      * @since 1.5
 622      */
 623     public interface Unpacker {
 624 


 701          * @param out a JarOutputStream.
 702          * @exception IOException if an error is encountered.
 703          */
 704         void unpack(InputStream in, JarOutputStream out) throws IOException;
 705 
 706         /**
 707          * Read a Pack200 archive, and write the encoded JAR to
 708          * a JarOutputStream.
 709          * <p>
 710          * Does not close its output.  (The output can accumulate more elements.)
 711          * @param in a File.
 712          * @param out a JarOutputStream.
 713          * @exception IOException if an error is encountered.
 714          */
 715         void unpack(File in, JarOutputStream out) throws IOException;
 716 
 717         /**
 718          * Registers a listener for PropertyChange events on the properties map.
 719          * This is typically used by applications to update a progress bar.
 720          *




 721          * @see #properties
 722          * @see #PROGRESS
 723          * @param listener  An object to be invoked when a property is changed.
 724          * @deprecated The dependency on {@code PropertyChangeListener} creates
 725          *             a significant impediment to future modularization of the
 726          *             Java platform. This method will be removed in a future
 727          *             release.
 728          *             Applications that need to monitor progress of the
 729          *             unpacker can poll the value of the {@link #PROGRESS
 730          *             PROGRESS} property instead.
 731          */
 732         @Deprecated
 733         void addPropertyChangeListener(PropertyChangeListener listener) ;


 734 
 735         /**
 736          * Remove a listener for PropertyChange events, added by
 737          * the {@link #addPropertyChangeListener}.
 738          *




 739          * @see #addPropertyChangeListener
 740          * @param listener  The PropertyChange listener to be removed.
 741          * @deprecated The dependency on {@code PropertyChangeListener} creates
 742          *             a significant impediment to future modularization of the
 743          *             Java platform. This method will be removed in a future
 744          *             release.
 745          */
 746         @Deprecated
 747         void removePropertyChangeListener(PropertyChangeListener listener);


 748     }
 749 
 750     // Private stuff....
 751 
 752     private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
 753     private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
 754 
 755     private static Class<?> packerImpl;
 756     private static Class<?> unpackerImpl;
 757 
 758     private synchronized static Object newInstance(String prop) {
 759         String implName = "(unknown)";
 760         try {
 761             Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 762             if (impl == null) {
 763                 // The first time, we must decide which class to use.
 764                 implName = java.security.AccessController.doPrivileged(
 765                     new sun.security.action.GetPropertyAction(prop,""));
 766                 if (implName != null && !implName.equals(""))
 767                     impl = Class.forName(implName);




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.jar;
  26 
  27 import java.util.Objects;
  28 import java.util.SortedMap;
  29 import java.io.InputStream;
  30 import java.io.OutputStream;
  31 import java.io.File;
  32 import java.io.IOException;
  33 import java.beans.PropertyChangeListener;
  34 
  35 
  36 
  37 
  38 /**
  39  * Transforms a JAR file to or from a packed stream in Pack200 format.
  40  * Please refer to Network Transfer Format JSR 200 Specification at
  41  * <a href=http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html>http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html</a>
  42  * <p>
  43  * Typically the packer engine is used by application developers
  44  * to deploy or host JAR files on a website.
  45  * The unpacker  engine is used by deployment applications to
  46  * transform the byte-stream back to JAR format.
  47  * <p>


 558         /**
 559          * Takes a JarInputStream and converts it into a Pack200 archive.
 560          * <p>
 561          * Closes its input but not its output.  (Pack200 archives are appendable.)
 562          * <p>
 563          * The modification time and deflation hint attributes are not available,
 564          * for the JAR manifest file and its containing directory.
 565          *
 566          * @see #MODIFICATION_TIME
 567          * @see #DEFLATE_HINT
 568          * @param in a JarInputStream
 569          * @param out an OutputStream
 570          * @exception IOException if an error is encountered.
 571          */
 572         void pack(JarInputStream in, OutputStream out) throws IOException ;
 573 
 574         /**
 575          * Registers a listener for PropertyChange events on the properties map.
 576          * This is typically used by applications to update a progress bar.
 577          *
 578          * <p><b>WARNING:</b> This method is not a declared method of this interface
 579          * in a subset Profile of Java SE. In other words, this method does not exist
 580          * on runtimes that only implement a profile of Java SE.</p>
 581 
 582          * @see #properties
 583          * @see #PROGRESS
 584          * @param listener  An object to be invoked when a property is changed.
 585          * @deprecated The dependency on {@code PropertyChangeListener} creates
 586          *             a significant impediment to future modularization of the
 587          *             Java platform. This method will be removed in a future
 588          *             release.
 589          *             Applications that need to monitor progress of the packer
 590          *             can poll the value of the {@link #PROGRESS PROGRESS}
 591          *             property instead.
 592          */
 593         @Deprecated
 594         default void addPropertyChangeListener(PropertyChangeListener listener) {
 595             Objects.requireNonNull(listener);
 596         }
 597 
 598         /**
 599          * Remove a listener for PropertyChange events, added by
 600          * the {@link #addPropertyChangeListener}.
 601          *
 602          * <p><b>WARNING:</b> This method is not a declared method of this interface
 603          * in a subset Profile of Java SE. In other words, this method does not exist
 604          * on runtimes that only implement a profile of Java SE.</p>
 605          *
 606          * @see #addPropertyChangeListener
 607          * @param listener  The PropertyChange listener to be removed.
 608          * @deprecated The dependency on {@code PropertyChangeListener} creates
 609          *             a significant impediment to future modularization of the
 610          *             Java platform. This method will be removed in a future
 611          *             release.
 612          */
 613         @Deprecated
 614         default void removePropertyChangeListener(PropertyChangeListener listener) {
 615             Objects.requireNonNull(listener);
 616         }
 617     }
 618 
 619     /**
 620      * The unpacker engine converts the packed stream to a JAR file.
 621      * An instance of the engine can be obtained
 622      * using {@link #newUnpacker}.
 623      * <p>
 624      * Every JAR file produced by this engine will include the string
 625      * "<tt>PACK200</tt>" as a zip file comment.
 626      * This allows a deployer to detect if a JAR archive was packed and unpacked.
 627      * <p>
 628      * Note: Unless otherwise noted, passing a <tt>null</tt> argument to a
 629      * constructor or method in this class will cause a {@link NullPointerException}
 630      * to be thrown.
 631      * <p>
 632      * This version of the unpacker is compatible with all previous versions.
 633      * @since 1.5
 634      */
 635     public interface Unpacker {
 636 


 713          * @param out a JarOutputStream.
 714          * @exception IOException if an error is encountered.
 715          */
 716         void unpack(InputStream in, JarOutputStream out) throws IOException;
 717 
 718         /**
 719          * Read a Pack200 archive, and write the encoded JAR to
 720          * a JarOutputStream.
 721          * <p>
 722          * Does not close its output.  (The output can accumulate more elements.)
 723          * @param in a File.
 724          * @param out a JarOutputStream.
 725          * @exception IOException if an error is encountered.
 726          */
 727         void unpack(File in, JarOutputStream out) throws IOException;
 728 
 729         /**
 730          * Registers a listener for PropertyChange events on the properties map.
 731          * This is typically used by applications to update a progress bar.
 732          *
 733          * <p><b>WARNING:</b> This method is not a declared method of this interface
 734          * in a subset Profile of Java SE. In other words, this method does not exist
 735          * on runtimes that only implement a profile of Java SE.</p>
 736          *
 737          * @see #properties
 738          * @see #PROGRESS
 739          * @param listener  An object to be invoked when a property is changed.
 740          * @deprecated The dependency on {@code PropertyChangeListener} creates
 741          *             a significant impediment to future modularization of the
 742          *             Java platform. This method will be removed in a future
 743          *             release.
 744          *             Applications that need to monitor progress of the
 745          *             unpacker can poll the value of the {@link #PROGRESS
 746          *             PROGRESS} property instead.
 747          */
 748         @Deprecated
 749         default void addPropertyChangeListener(PropertyChangeListener listener) {
 750             Objects.requireNonNull(listener);
 751         }
 752 
 753         /**
 754          * Remove a listener for PropertyChange events, added by
 755          * the {@link #addPropertyChangeListener}.
 756          *
 757          * <p><b>WARNING:</b> This method is not a declared method of this interface
 758          * in a subset Profile of Java SE. In other words, this method does not exist
 759          * on runtimes that only implement a profile of Java SE.</p>
 760          *
 761          * @see #addPropertyChangeListener
 762          * @param listener  The PropertyChange listener to be removed.
 763          * @deprecated The dependency on {@code PropertyChangeListener} creates
 764          *             a significant impediment to future modularization of the
 765          *             Java platform. This method will be removed in a future
 766          *             release.
 767          */
 768         @Deprecated
 769         default void removePropertyChangeListener(PropertyChangeListener listener) {
 770             Objects.requireNonNull(listener);
 771         }
 772     }
 773 
 774     // Private stuff....
 775 
 776     private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
 777     private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
 778 
 779     private static Class<?> packerImpl;
 780     private static Class<?> unpackerImpl;
 781 
 782     private synchronized static Object newInstance(String prop) {
 783         String implName = "(unknown)";
 784         try {
 785             Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 786             if (impl == null) {
 787                 // The first time, we must decide which class to use.
 788                 implName = java.security.AccessController.doPrivileged(
 789                     new sun.security.action.GetPropertyAction(prop,""));
 790                 if (implName != null && !implName.equals(""))
 791                     impl = Class.forName(implName);


src/share/classes/java/util/jar/Pack200.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File