jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java
changeset 7171 ee97f78e7482
parent 6313 470912c9e214
child 7192 445c518364c4
equal deleted inserted replaced
7170:285c02ecbb8a 7171:ee97f78e7482
    90      * Closes its input but not its output.  (The output can accumulate more elements.)
    90      * Closes its input but not its output.  (The output can accumulate more elements.)
    91      * @param in an InputStream.
    91      * @param in an InputStream.
    92      * @param out a JarOutputStream.
    92      * @param out a JarOutputStream.
    93      * @exception IOException if an error is encountered.
    93      * @exception IOException if an error is encountered.
    94      */
    94      */
    95     public void unpack(InputStream in0, JarOutputStream out) throws IOException {
    95     public void unpack(InputStream in, JarOutputStream out) throws IOException {
       
    96         if (in == null) {
       
    97             throw new NullPointerException("null input");
       
    98         }
       
    99         if (out == null) {
       
   100             throw new NullPointerException("null output");
       
   101         }
    96         assert(Utils.currentInstance.get() == null);
   102         assert(Utils.currentInstance.get() == null);
    97         TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
   103         TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
    98                       ? null
   104                       ? null
    99                       : TimeZone.getDefault();
   105                       : TimeZone.getDefault();
   100 
   106 
   101         try {
   107         try {
   102             Utils.currentInstance.set(this);
   108             Utils.currentInstance.set(this);
   103             if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
   109             if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
   104             final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
   110             final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
   105             BufferedInputStream in = new BufferedInputStream(in0);
   111             BufferedInputStream in0 = new BufferedInputStream(in);
   106             if (Utils.isJarMagic(Utils.readMagic(in))) {
   112             if (Utils.isJarMagic(Utils.readMagic(in0))) {
   107                 if (verbose > 0)
   113                 if (verbose > 0)
   108                     Utils.log.info("Copying unpacked JAR file...");
   114                     Utils.log.info("Copying unpacked JAR file...");
   109                 Utils.copyJarFile(new JarInputStream(in), out);
   115                 Utils.copyJarFile(new JarInputStream(in0), out);
   110             } else if (props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
   116             } else if (props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
   111                 (new DoUnpack()).run(in, out);
   117                 (new DoUnpack()).run(in0, out);
   112                 in.close();
   118                 in0.close();
   113                 Utils.markJarFile(out);
   119                 Utils.markJarFile(out);
   114             } else {
   120             } else {
   115                 (new NativeUnpack(this)).run(in, out);
   121                 (new NativeUnpack(this)).run(in0, out);
   116                 in.close();
   122                 in0.close();
   117                 Utils.markJarFile(out);
   123                 Utils.markJarFile(out);
   118             }
   124             }
   119         } finally {
   125         } finally {
   120             _nunp = null;
   126             _nunp = null;
   121             Utils.currentInstance.set(null);
   127             Utils.currentInstance.set(null);
   130      * @param in a File.
   136      * @param in a File.
   131      * @param out a JarOutputStream.
   137      * @param out a JarOutputStream.
   132      * @exception IOException if an error is encountered.
   138      * @exception IOException if an error is encountered.
   133      */
   139      */
   134     public void unpack(File in, JarOutputStream out) throws IOException {
   140     public void unpack(File in, JarOutputStream out) throws IOException {
       
   141         if (in == null) {
       
   142             throw new NullPointerException("null input");
       
   143         }
       
   144         if (out == null) {
       
   145             throw new NullPointerException("null output");
       
   146         }
   135         // Use the stream-based implementation.
   147         // Use the stream-based implementation.
   136         // %%% Reconsider if native unpacker learns to memory-map the file.
   148         // %%% Reconsider if native unpacker learns to memory-map the file.
   137         FileInputStream instr = new FileInputStream(in);
   149         FileInputStream instr = new FileInputStream(in);
   138         unpack(instr, out);
   150         unpack(instr, out);
   139         if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
   151         if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {