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
26 package com.sun.java.util.jar.pack;
27
28 import java.io.BufferedInputStream;
29 import java.io.BufferedOutputStream;
30 import java.io.File;
31 import java.io.FilterOutputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.util.Collections;
36 import java.util.Date;
37 import java.util.jar.JarEntry;
38 import java.util.jar.JarFile;
39 import java.util.jar.JarInputStream;
40 import java.util.jar.JarOutputStream;
41 import java.util.zip.ZipEntry;
42 import sun.util.logging.PlatformLogger;
43
44 class Utils {
45 static final String COM_PREFIX = "com.sun.java.util.jar.pack.";
46 static final String METAINF = "META-INF";
47
48 /*
49 * Outputs various diagnostic support information.
50 * If >0, print summary comments (e.g., constant pool info).
51 * If >1, print unit comments (e.g., processing of classes).
52 * If >2, print many comments (e.g., processing of members).
53 * If >3, print tons of comments (e.g., processing of references).
54 * (installer only)
55 */
56 static final String DEBUG_VERBOSE = COM_PREFIX+"verbose";
116 * decrease the transmitted size of the archive.
117 */
118 static final String PACK_KEEP_CLASS_ORDER = COM_PREFIX+"keep.class.order";
119 /*
120 * This string PACK200 is given as a zip comment on all JAR files
121 * produced by this utility.
122 */
123 static final String PACK_ZIP_ARCHIVE_MARKER_COMMENT = "PACK200";
124
125 /*
126 * behaviour when we hit a class format error, but not necessarily
127 * an unknown attribute, by default it is allowed to PASS.
128 */
129 static final String CLASS_FORMAT_ERROR = COM_PREFIX+"class.format.error";
130
131 // Keep a TLS point to the global data and environment.
132 // This makes it simpler to supply environmental options
133 // to the engine code, especially the native code.
134 static final ThreadLocal<TLGlobals> currentInstance = new ThreadLocal<>();
135
136 // convenience method to access the TL globals
137 static TLGlobals getTLGlobals() {
138 return currentInstance.get();
139 }
140
141 static PropMap currentPropMap() {
142 Object obj = currentInstance.get();
143 if (obj instanceof PackerImpl)
144 return ((PackerImpl)obj).props;
145 if (obj instanceof UnpackerImpl)
146 return ((UnpackerImpl)obj).props;
147 return null;
148 }
149
150 static final boolean nolog
151 = Boolean.getBoolean(COM_PREFIX+"nolog");
152
153 static final boolean SORT_MEMBERS_DESCR_MAJOR
154 = Boolean.getBoolean(COM_PREFIX+"sort.members.descr.major");
155
183 public void warning(String msg) {
184 warning(msg, null);
185 }
186
187 public void info(String msg) {
188 int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
189 if (verbose > 0) {
190 if (nolog) {
191 System.out.println(msg);
192 } else {
193 getLogger().info(msg);
194 }
195 }
196 }
197
198 public void fine(String msg) {
199 int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
200 if (verbose > 0) {
201 System.out.println(msg);
202 }
203 }
204 }
205
206 static final Pack200Logger log
207 = new Pack200Logger("java.util.jar.Pack200");
208
209 // Returns the Max Version String of this implementation
210 static String getVersionString() {
211 return "Pack200, Vendor: " +
212 System.getProperty("java.vendor") +
213 ", Version: " + Constants.MAX_PACKAGE_VERSION;
214 }
215
216 static void markJarFile(JarOutputStream out) throws IOException {
217 out.setComment(PACK_ZIP_ARCHIVE_MARKER_COMMENT);
218 }
219
220 // -0 mode helper
221 static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
222 if (in.getManifest() != null) {
|
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
26 package com.sun.java.util.jar.pack;
27
28 import java.io.BufferedInputStream;
29 import java.io.BufferedOutputStream;
30 import java.io.File;
31 import java.io.FilterOutputStream;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.io.OutputStream;
35 import java.util.Collections;
36 import java.util.Date;
37 import java.util.TimeZone;
38 import java.util.jar.JarEntry;
39 import java.util.jar.JarFile;
40 import java.util.jar.JarInputStream;
41 import java.util.jar.JarOutputStream;
42 import java.util.zip.ZipEntry;
43 import sun.util.logging.PlatformLogger;
44
45 class Utils {
46 static final String COM_PREFIX = "com.sun.java.util.jar.pack.";
47 static final String METAINF = "META-INF";
48
49 /*
50 * Outputs various diagnostic support information.
51 * If >0, print summary comments (e.g., constant pool info).
52 * If >1, print unit comments (e.g., processing of classes).
53 * If >2, print many comments (e.g., processing of members).
54 * If >3, print tons of comments (e.g., processing of references).
55 * (installer only)
56 */
57 static final String DEBUG_VERBOSE = COM_PREFIX+"verbose";
117 * decrease the transmitted size of the archive.
118 */
119 static final String PACK_KEEP_CLASS_ORDER = COM_PREFIX+"keep.class.order";
120 /*
121 * This string PACK200 is given as a zip comment on all JAR files
122 * produced by this utility.
123 */
124 static final String PACK_ZIP_ARCHIVE_MARKER_COMMENT = "PACK200";
125
126 /*
127 * behaviour when we hit a class format error, but not necessarily
128 * an unknown attribute, by default it is allowed to PASS.
129 */
130 static final String CLASS_FORMAT_ERROR = COM_PREFIX+"class.format.error";
131
132 // Keep a TLS point to the global data and environment.
133 // This makes it simpler to supply environmental options
134 // to the engine code, especially the native code.
135 static final ThreadLocal<TLGlobals> currentInstance = new ThreadLocal<>();
136
137 private static TimeZone tz;
138 private static int workingPackerCount = 0;
139
140 // convenience method to access the TL globals
141 static TLGlobals getTLGlobals() {
142 return currentInstance.get();
143 }
144
145 static PropMap currentPropMap() {
146 Object obj = currentInstance.get();
147 if (obj instanceof PackerImpl)
148 return ((PackerImpl)obj).props;
149 if (obj instanceof UnpackerImpl)
150 return ((UnpackerImpl)obj).props;
151 return null;
152 }
153
154 static final boolean nolog
155 = Boolean.getBoolean(COM_PREFIX+"nolog");
156
157 static final boolean SORT_MEMBERS_DESCR_MAJOR
158 = Boolean.getBoolean(COM_PREFIX+"sort.members.descr.major");
159
187 public void warning(String msg) {
188 warning(msg, null);
189 }
190
191 public void info(String msg) {
192 int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
193 if (verbose > 0) {
194 if (nolog) {
195 System.out.println(msg);
196 } else {
197 getLogger().info(msg);
198 }
199 }
200 }
201
202 public void fine(String msg) {
203 int verbose = currentPropMap().getInteger(DEBUG_VERBOSE);
204 if (verbose > 0) {
205 System.out.println(msg);
206 }
207 }
208 }
209
210 static synchronized void changeDefaultTimeZoneToUtc() {
211 if (workingPackerCount++ == 0) {
212 // only first thread saves default TZ
213 tz = TimeZone.getDefault();
214 TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
215 }
216 }
217
218 static synchronized void restoreDefaultTimeZone() {
219 if (--workingPackerCount == 0) {
220 // reset timezone when all the packer/unpacker instances have terminated
221 if (tz != null) TimeZone.setDefault(tz);
222 tz = null;
223 }
224 }
225
226 static final Pack200Logger log
227 = new Pack200Logger("java.util.jar.Pack200");
228
229 // Returns the Max Version String of this implementation
230 static String getVersionString() {
231 return "Pack200, Vendor: " +
232 System.getProperty("java.vendor") +
233 ", Version: " + Constants.MAX_PACKAGE_VERSION;
234 }
235
236 static void markJarFile(JarOutputStream out) throws IOException {
237 out.setComment(PACK_ZIP_ARCHIVE_MARKER_COMMENT);
238 }
239
240 // -0 mode helper
241 static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
242 if (in.getManifest() != null) {
|