< prev index next >

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

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  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 
  33 
  34 /**
  35  * Transforms a JAR file to or from a packed stream in Pack200 format.
  36  * Please refer to Network Transfer Format JSR 200 Specification at
  37  * <a href=http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html>http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html</a>
  38  * <p>
  39  * Typically the packer engine is used by application developers
  40  * to deploy or host JAR files on a website.
  41  * The unpacker  engine is used by deployment applications to
  42  * transform the byte-stream back to JAR format.
  43  * <p>
  44  * Here is an example using  packer and unpacker:
  45  * <pre>{@code
  46  *    import java.util.jar.Pack200;
  47  *    import java.util.jar.Pack200.*;
  48  *    ...
  49  *    // Create the Packer object
  50  *    Packer packer = Pack200.newPacker();
  51  *


 677          * @param out a JarOutputStream.
 678          * @exception IOException if an error is encountered.
 679          */
 680         void unpack(File in, JarOutputStream out) throws IOException;
 681     }
 682 
 683     // Private stuff....
 684 
 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 static synchronized Object newInstance(String prop) {
 692         String implName = "(unknown)";
 693         try {
 694             Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 695             if (impl == null) {
 696                 // The first time, we must decide which class to use.
 697                 implName = java.security.AccessController.doPrivileged(
 698                     new sun.security.action.GetPropertyAction(prop,""));
 699                 if (implName != null && !implName.equals(""))
 700                     impl = Class.forName(implName);
 701                 else if (PACK_PROVIDER.equals(prop))
 702                     impl = com.sun.java.util.jar.pack.PackerImpl.class;
 703                 else
 704                     impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
 705             }
 706             // We have a class.  Now instantiate it.
 707             return impl.newInstance();
 708         } catch (ClassNotFoundException e) {
 709             throw new Error("Class not found: " + implName +
 710                                 ":\ncheck property " + prop +
 711                                 " in your properties file.", e);
 712         } catch (InstantiationException e) {
 713             throw new Error("Could not instantiate: " + implName +
 714                                 ":\ncheck property " + prop +
 715                                 " in your properties file.", e);
 716         } catch (IllegalAccessException e) {
 717             throw new Error("Cannot access class: " + implName +
 718                                 ":\ncheck property " + prop +


  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 sun.security.action.GetPropertyAction;
  33 
  34 
  35 /**
  36  * Transforms a JAR file to or from a packed stream in Pack200 format.
  37  * Please refer to Network Transfer Format JSR 200 Specification at
  38  * <a href=http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html>http://jcp.org/aboutJava/communityprocess/review/jsr200/index.html</a>
  39  * <p>
  40  * Typically the packer engine is used by application developers
  41  * to deploy or host JAR files on a website.
  42  * The unpacker  engine is used by deployment applications to
  43  * transform the byte-stream back to JAR format.
  44  * <p>
  45  * Here is an example using  packer and unpacker:
  46  * <pre>{@code
  47  *    import java.util.jar.Pack200;
  48  *    import java.util.jar.Pack200.*;
  49  *    ...
  50  *    // Create the Packer object
  51  *    Packer packer = Pack200.newPacker();
  52  *


 678          * @param out a JarOutputStream.
 679          * @exception IOException if an error is encountered.
 680          */
 681         void unpack(File in, JarOutputStream out) throws IOException;
 682     }
 683 
 684     // Private stuff....
 685 
 686     private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
 687     private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
 688 
 689     private static Class<?> packerImpl;
 690     private static Class<?> unpackerImpl;
 691 
 692     private static synchronized Object newInstance(String prop) {
 693         String implName = "(unknown)";
 694         try {
 695             Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
 696             if (impl == null) {
 697                 // The first time, we must decide which class to use.
 698                 implName = GetPropertyAction.getProperty(prop,"");

 699                 if (implName != null && !implName.equals(""))
 700                     impl = Class.forName(implName);
 701                 else if (PACK_PROVIDER.equals(prop))
 702                     impl = com.sun.java.util.jar.pack.PackerImpl.class;
 703                 else
 704                     impl = com.sun.java.util.jar.pack.UnpackerImpl.class;
 705             }
 706             // We have a class.  Now instantiate it.
 707             return impl.newInstance();
 708         } catch (ClassNotFoundException e) {
 709             throw new Error("Class not found: " + implName +
 710                                 ":\ncheck property " + prop +
 711                                 " in your properties file.", e);
 712         } catch (InstantiationException e) {
 713             throw new Error("Could not instantiate: " + implName +
 714                                 ":\ncheck property " + prop +
 715                                 " in your properties file.", e);
 716         } catch (IllegalAccessException e) {
 717             throw new Error("Cannot access class: " + implName +
 718                                 ":\ncheck property " + prop +
< prev index next >