1 /*
2 * Copyright (c) 2003, 2012, 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
115 }
116 assert(Utils.currentInstance.get() == null);
117 TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
118 ? null
119 : TimeZone.getDefault();
120
121 try {
122 Utils.currentInstance.set(this);
123 if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
124 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
125 BufferedInputStream in0 = new BufferedInputStream(in);
126 if (Utils.isJarMagic(Utils.readMagic(in0))) {
127 if (verbose > 0)
128 Utils.log.info("Copying unpacked JAR file...");
129 Utils.copyJarFile(new JarInputStream(in0), out);
130 } else if (props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
131 (new DoUnpack()).run(in0, out);
132 in0.close();
133 Utils.markJarFile(out);
134 } else {
135 (new NativeUnpack(this)).run(in0, out);
136 in0.close();
137 Utils.markJarFile(out);
138 }
139 } finally {
140 _nunp = null;
141 Utils.currentInstance.set(null);
142 if (tz != null) TimeZone.setDefault(tz);
143 }
144 }
145
146 /**
147 * Takes an input File containing the pack file, and generates a JarOutputStream.
148 * <p>
149 * Does not close its output. (The output can accumulate more elements.)
150 * @param in a File.
151 * @param out a JarOutputStream.
152 * @exception IOException if an error is encountered.
153 */
154 public synchronized void unpack(File in, JarOutputStream out) throws IOException {
155 if (in == null) {
|
1 /*
2 * Copyright (c) 2003, 2013, 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
115 }
116 assert(Utils.currentInstance.get() == null);
117 TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
118 ? null
119 : TimeZone.getDefault();
120
121 try {
122 Utils.currentInstance.set(this);
123 if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
124 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
125 BufferedInputStream in0 = new BufferedInputStream(in);
126 if (Utils.isJarMagic(Utils.readMagic(in0))) {
127 if (verbose > 0)
128 Utils.log.info("Copying unpacked JAR file...");
129 Utils.copyJarFile(new JarInputStream(in0), out);
130 } else if (props.getBoolean(Utils.DEBUG_DISABLE_NATIVE)) {
131 (new DoUnpack()).run(in0, out);
132 in0.close();
133 Utils.markJarFile(out);
134 } else {
135 try {
136 (new NativeUnpack(this)).run(in0, out);
137 } catch (UnsatisfiedLinkError ule) {
138 // failover to java implementation
139 (new DoUnpack()).run(in0, out);
140 }
141 in0.close();
142 Utils.markJarFile(out);
143 }
144 } finally {
145 _nunp = null;
146 Utils.currentInstance.set(null);
147 if (tz != null) TimeZone.setDefault(tz);
148 }
149 }
150
151 /**
152 * Takes an input File containing the pack file, and generates a JarOutputStream.
153 * <p>
154 * Does not close its output. (The output can accumulate more elements.)
155 * @param in a File.
156 * @param out a JarOutputStream.
157 * @exception IOException if an error is encountered.
158 */
159 public synchronized void unpack(File in, JarOutputStream out) throws IOException {
160 if (in == null) {
|