src/share/classes/com/sun/java/util/jar/pack/Utils.java

Print this page

        

@@ -32,10 +32,11 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collections;
 import java.util.Date;
+import java.util.TimeZone;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;

@@ -131,10 +132,13 @@
     // Keep a TLS point to the global data and environment.
     // This makes it simpler to supply environmental options
     // to the engine code, especially the native code.
     static final ThreadLocal<TLGlobals> currentInstance = new ThreadLocal<>();
 
+    private static TimeZone tz;
+    private static int workingPackerCount = 0;
+
     // convenience method to access the TL globals
     static TLGlobals getTLGlobals() {
         return currentInstance.get();
     }
 

@@ -201,10 +205,26 @@
                     System.out.println(msg);
             }
         }
     }
 
+    static synchronized void changeDefaultTimeZoneToUtc() {
+        if (workingPackerCount++ == 0) {
+            // only first thread saves default TZ
+            tz = TimeZone.getDefault();
+            TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+        }
+    }
+
+    static synchronized void restoreDefaultTimeZone() {
+        if (--workingPackerCount == 0) {
+            // reset timezone when all the packer/unpacker instances have terminated
+            if (tz != null) TimeZone.setDefault(tz);
+            tz = null;
+        }
+    }
+
     static final Pack200Logger log
         = new Pack200Logger("java.util.jar.Pack200");
 
     // Returns the Max Version String of this implementation
     static String getVersionString() {