1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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
537 * All property names beginning with {@code pack.} and
538 * {@code unpack.} are reserved for use by this API.
539 * <p>
540 * Unknown properties may be ignored or rejected with an
541 * unspecified error, and invalid entries may cause an
542 * unspecified error to be thrown.
543 *
544 * <p>
545 * The returned map implements all optional {@link SortedMap} operations
546 * @return A sorted association of property key strings to property
547 * values.
548 */
549 SortedMap<String,String> properties();
550
551 /**
552 * Takes a JarFile and converts it into a Pack200 archive.
553 * <p>
554 * Closes its input but not its output. (Pack200 archives are appendable.)
555 * @param in a JarFile
556 * @param out an OutputStream
557 * @exception IOException if an error is encountered.
558 */
559 void pack(JarFile in, OutputStream out) throws IOException ;
560
561 /**
562 * Takes a JarInputStream and converts it into a Pack200 archive.
563 * <p>
564 * Closes its input but not its output. (Pack200 archives are appendable.)
565 * <p>
566 * The modification time and deflation hint attributes are not available,
567 * for the JAR manifest file and its containing directory.
568 *
569 * @see #MODIFICATION_TIME
570 * @see #DEFLATE_HINT
571 * @param in a JarInputStream
572 * @param out an OutputStream
573 * @exception IOException if an error is encountered.
574 */
575 void pack(JarInputStream in, OutputStream out) throws IOException ;
576 }
577
578 /**
579 * The unpacker engine converts the packed stream to a JAR file.
580 * An instance of the engine can be obtained
581 * using {@link #newUnpacker}.
582 * <p>
583 * Every JAR file produced by this engine will include the string
584 * "{@code PACK200}" as a zip file comment.
585 * This allows a deployer to detect if a JAR archive was packed and unpacked.
586 * <p>
587 * Note: Unless otherwise noted, passing a {@code null} argument to a
588 * constructor or method in this class will cause a {@link NullPointerException}
589 * to be thrown.
590 * <p>
591 * This version of the unpacker is compatible with all previous versions.
592 * @since 1.5
593 * @deprecated This interface is deprecated, and is planned for removal in a
656 * <p>
657 * Unknown properties may be ignored or rejected with an
658 * unspecified error, and invalid entries may cause an
659 * unspecified error to be thrown.
660 *
661 * @return A sorted association of option key strings to option values.
662 */
663 SortedMap<String,String> properties();
664
665 /**
666 * Read a Pack200 archive, and write the encoded JAR to
667 * a JarOutputStream.
668 * The entire contents of the input stream will be read.
669 * It may be more efficient to read the Pack200 archive
670 * to a file and pass the File object, using the alternate
671 * method described below.
672 * <p>
673 * Closes its input but not its output. (The output can accumulate more elements.)
674 * @param in an InputStream.
675 * @param out a JarOutputStream.
676 * @exception IOException if an error is encountered.
677 */
678 void unpack(InputStream in, JarOutputStream out) throws IOException;
679
680 /**
681 * Read a Pack200 archive, and write the encoded JAR to
682 * a JarOutputStream.
683 * <p>
684 * Does not close its output. (The output can accumulate more elements.)
685 * @param in a File.
686 * @param out a JarOutputStream.
687 * @exception IOException if an error is encountered.
688 */
689 void unpack(File in, JarOutputStream out) throws IOException;
690 }
691
692 // Private stuff....
693
694 private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
695 private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
696
697 private static Class<?> packerImpl;
698 private static Class<?> unpackerImpl;
699
700 private static synchronized Object newInstance(String prop) {
701 String implName = "(unknown)";
702 try {
703 Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
704 if (impl == null) {
705 // The first time, we must decide which class to use.
706 implName = GetPropertyAction.privilegedGetProperty(prop,"");
707 if (implName != null && !implName.isEmpty())
|
1 /*
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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
537 * All property names beginning with {@code pack.} and
538 * {@code unpack.} are reserved for use by this API.
539 * <p>
540 * Unknown properties may be ignored or rejected with an
541 * unspecified error, and invalid entries may cause an
542 * unspecified error to be thrown.
543 *
544 * <p>
545 * The returned map implements all optional {@link SortedMap} operations
546 * @return A sorted association of property key strings to property
547 * values.
548 */
549 SortedMap<String,String> properties();
550
551 /**
552 * Takes a JarFile and converts it into a Pack200 archive.
553 * <p>
554 * Closes its input but not its output. (Pack200 archives are appendable.)
555 * @param in a JarFile
556 * @param out an OutputStream
557 * @throws IOException if an error is encountered.
558 */
559 void pack(JarFile in, OutputStream out) throws IOException ;
560
561 /**
562 * Takes a JarInputStream and converts it into a Pack200 archive.
563 * <p>
564 * Closes its input but not its output. (Pack200 archives are appendable.)
565 * <p>
566 * The modification time and deflation hint attributes are not available,
567 * for the JAR manifest file and its containing directory.
568 *
569 * @see #MODIFICATION_TIME
570 * @see #DEFLATE_HINT
571 * @param in a JarInputStream
572 * @param out an OutputStream
573 * @throws IOException if an error is encountered.
574 */
575 void pack(JarInputStream in, OutputStream out) throws IOException ;
576 }
577
578 /**
579 * The unpacker engine converts the packed stream to a JAR file.
580 * An instance of the engine can be obtained
581 * using {@link #newUnpacker}.
582 * <p>
583 * Every JAR file produced by this engine will include the string
584 * "{@code PACK200}" as a zip file comment.
585 * This allows a deployer to detect if a JAR archive was packed and unpacked.
586 * <p>
587 * Note: Unless otherwise noted, passing a {@code null} argument to a
588 * constructor or method in this class will cause a {@link NullPointerException}
589 * to be thrown.
590 * <p>
591 * This version of the unpacker is compatible with all previous versions.
592 * @since 1.5
593 * @deprecated This interface is deprecated, and is planned for removal in a
656 * <p>
657 * Unknown properties may be ignored or rejected with an
658 * unspecified error, and invalid entries may cause an
659 * unspecified error to be thrown.
660 *
661 * @return A sorted association of option key strings to option values.
662 */
663 SortedMap<String,String> properties();
664
665 /**
666 * Read a Pack200 archive, and write the encoded JAR to
667 * a JarOutputStream.
668 * The entire contents of the input stream will be read.
669 * It may be more efficient to read the Pack200 archive
670 * to a file and pass the File object, using the alternate
671 * method described below.
672 * <p>
673 * Closes its input but not its output. (The output can accumulate more elements.)
674 * @param in an InputStream.
675 * @param out a JarOutputStream.
676 * @throws IOException if an error is encountered.
677 */
678 void unpack(InputStream in, JarOutputStream out) throws IOException;
679
680 /**
681 * Read a Pack200 archive, and write the encoded JAR to
682 * a JarOutputStream.
683 * <p>
684 * Does not close its output. (The output can accumulate more elements.)
685 * @param in a File.
686 * @param out a JarOutputStream.
687 * @throws IOException if an error is encountered.
688 */
689 void unpack(File in, JarOutputStream out) throws IOException;
690 }
691
692 // Private stuff....
693
694 private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
695 private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
696
697 private static Class<?> packerImpl;
698 private static Class<?> unpackerImpl;
699
700 private static synchronized Object newInstance(String prop) {
701 String implName = "(unknown)";
702 try {
703 Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
704 if (impl == null) {
705 // The first time, we must decide which class to use.
706 implName = GetPropertyAction.privilegedGetProperty(prop,"");
707 if (implName != null && !implName.isEmpty())
|