1 /*
2 * Copyright (c) 2003, 2011, 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
90 Object _nunp;
91
92
93 public String toString() {
94 return Utils.getVersionString();
95 }
96
97 //Driver routines
98
99 // The unpack worker...
100 /**
101 * Takes a packed-stream InputStream, and writes to a JarOutputStream. Internally
102 * the entire buffer must be read, it may be more efficient to read the packed-stream
103 * to a file and pass the File object, in the alternate method described below.
104 * <p>
105 * Closes its input but not its output. (The output can accumulate more elements.)
106 * @param in an InputStream.
107 * @param out a JarOutputStream.
108 * @exception IOException if an error is encountered.
109 */
110 public void unpack(InputStream in, JarOutputStream out) throws IOException {
111 if (in == null) {
112 throw new NullPointerException("null input");
113 }
114 if (out == null) {
115 throw new NullPointerException("null output");
116 }
117 assert(Utils.currentInstance.get() == null);
118 TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
119 ? null
120 : TimeZone.getDefault();
121
122 try {
123 Utils.currentInstance.set(this);
124 if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
125 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
126 BufferedInputStream in0 = new BufferedInputStream(in);
127 if (Utils.isJarMagic(Utils.readMagic(in0))) {
128 if (verbose > 0)
129 Utils.log.info("Copying unpacked JAR file...");
130 Utils.copyJarFile(new JarInputStream(in0), out);
135 } else {
136 (new NativeUnpack(this)).run(in0, out);
137 in0.close();
138 Utils.markJarFile(out);
139 }
140 } finally {
141 _nunp = null;
142 Utils.currentInstance.set(null);
143 if (tz != null) TimeZone.setDefault(tz);
144 }
145 }
146
147 /**
148 * Takes an input File containing the pack file, and generates a JarOutputStream.
149 * <p>
150 * Does not close its output. (The output can accumulate more elements.)
151 * @param in a File.
152 * @param out a JarOutputStream.
153 * @exception IOException if an error is encountered.
154 */
155 public void unpack(File in, JarOutputStream out) throws IOException {
156 if (in == null) {
157 throw new NullPointerException("null input");
158 }
159 if (out == null) {
160 throw new NullPointerException("null output");
161 }
162 // Use the stream-based implementation.
163 // %%% Reconsider if native unpacker learns to memory-map the file.
164 try (FileInputStream instr = new FileInputStream(in)) {
165 unpack(instr, out);
166 }
167 if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
168 in.delete();
169 }
170 }
171
172 private class DoUnpack {
173 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
174
175 {
|
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
90 Object _nunp;
91
92
93 public String toString() {
94 return Utils.getVersionString();
95 }
96
97 //Driver routines
98
99 // The unpack worker...
100 /**
101 * Takes a packed-stream InputStream, and writes to a JarOutputStream. Internally
102 * the entire buffer must be read, it may be more efficient to read the packed-stream
103 * to a file and pass the File object, in the alternate method described below.
104 * <p>
105 * Closes its input but not its output. (The output can accumulate more elements.)
106 * @param in an InputStream.
107 * @param out a JarOutputStream.
108 * @exception IOException if an error is encountered.
109 */
110 public synchronized void unpack(InputStream in, JarOutputStream out) throws IOException {
111 if (in == null) {
112 throw new NullPointerException("null input");
113 }
114 if (out == null) {
115 throw new NullPointerException("null output");
116 }
117 assert(Utils.currentInstance.get() == null);
118 TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE))
119 ? null
120 : TimeZone.getDefault();
121
122 try {
123 Utils.currentInstance.set(this);
124 if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
125 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
126 BufferedInputStream in0 = new BufferedInputStream(in);
127 if (Utils.isJarMagic(Utils.readMagic(in0))) {
128 if (verbose > 0)
129 Utils.log.info("Copying unpacked JAR file...");
130 Utils.copyJarFile(new JarInputStream(in0), out);
135 } else {
136 (new NativeUnpack(this)).run(in0, out);
137 in0.close();
138 Utils.markJarFile(out);
139 }
140 } finally {
141 _nunp = null;
142 Utils.currentInstance.set(null);
143 if (tz != null) TimeZone.setDefault(tz);
144 }
145 }
146
147 /**
148 * Takes an input File containing the pack file, and generates a JarOutputStream.
149 * <p>
150 * Does not close its output. (The output can accumulate more elements.)
151 * @param in a File.
152 * @param out a JarOutputStream.
153 * @exception IOException if an error is encountered.
154 */
155 public synchronized void unpack(File in, JarOutputStream out) throws IOException {
156 if (in == null) {
157 throw new NullPointerException("null input");
158 }
159 if (out == null) {
160 throw new NullPointerException("null output");
161 }
162 // Use the stream-based implementation.
163 // %%% Reconsider if native unpacker learns to memory-map the file.
164 try (FileInputStream instr = new FileInputStream(in)) {
165 unpack(instr, out);
166 }
167 if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
168 in.delete();
169 }
170 }
171
172 private class DoUnpack {
173 final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
174
175 {
|