commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1549131 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
Date Sun, 08 Dec 2013 19:14:26 GMT
Author: bodewig
Date: Sun Dec  8 19:14:25 2013
New Revision: 1549131

URL: http://svn.apache.org/r1549131
Log:
COMPRESS-242 make X5455_ExtendedTimestamp more convenient

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1549131&r1=1549130&r2=1549131&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sun Dec  8 19:14:25 2013
@@ -63,6 +63,13 @@ The <action> type attribute can be add,u
       <action issue="COMPRESS-245" type="fix" date="2013-12-06">
         TarArchiveInputStream could fail to read an archive completely.
       </action> 
+      <action issue="COMPRESS-242" type="fix" date="2013-12-08">
+        The time-setters in X5455_ExtendedTimestamp now set the
+        corresponding flags explicitly - i.e. they set the bit if the
+        valus is not-null and reset it otherwise.  This may cause
+        incompatibilities if you use setFlags to unset a bit and later
+        set the time to a non-null value - the flag will now be set.
+      </action> 
     </release>
     <release version="1.6" date="2013-10-26"
              description="Release 1.6">

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java?rev=1549131&r1=1549130&r2=1549131&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
Sun Dec  8 19:14:25 2013
@@ -85,9 +85,21 @@ public class X5455_ExtendedTimestamp imp
     private static final ZipShort HEADER_ID = new ZipShort(0x5455);
     private static final long serialVersionUID = 1L;
 
-    static final byte MODIFY_TIME_BIT = 1;
-    static final byte ACCESS_TIME_BIT = 2;
-    static final byte CREATE_TIME_BIT = 4;
+    /**
+     * The bit set inside the flags by when the last modification time
+     * is present in this extra field.
+     */
+    public static final byte MODIFY_TIME_BIT = 1;
+    /**
+     * The bit set inside the flags by when the lasr access time is
+     * present in this extra field.
+     */
+    public static final byte ACCESS_TIME_BIT = 2;
+    /**
+     * The bit set inside the flags by when the original creation time
+     * is present in this extra field.
+     */
+    public static final byte CREATE_TIME_BIT = 4;
 
     // The 3 boolean fields (below) come from this flags byte.  The remaining 5 bits
     // are ignored according to the current version of the spec (December 2012).
@@ -397,7 +409,12 @@ public class X5455_ExtendedTimestamp imp
      *
      * @param l ZipLong of the modify time (seconds per epoch)
      */
-    public void setModifyTime(ZipLong l) { this.modifyTime = l; }
+    public void setModifyTime(ZipLong l) {
+        bit0_modifyTimePresent = l != null;
+        flags = (byte) (l != null ? (flags | MODIFY_TIME_BIT)
+                        : (flags & ~MODIFY_TIME_BIT));
+        this.modifyTime = l;
+    }
 
     /**
      * <p>
@@ -411,7 +428,12 @@ public class X5455_ExtendedTimestamp imp
      *
      * @param l ZipLong of the access time (seconds per epoch)
      */
-    public void setAccessTime(ZipLong l) { this.accessTime = l; }
+    public void setAccessTime(ZipLong l) {
+        bit1_accessTimePresent = l != null;
+        flags = (byte) (l != null ? (flags | ACCESS_TIME_BIT)
+                        : (flags & ~ACCESS_TIME_BIT));
+        this.accessTime = l;
+    }
 
     /**
      * <p>
@@ -425,7 +447,12 @@ public class X5455_ExtendedTimestamp imp
      *
      * @param l ZipLong of the create time (seconds per epoch)
      */
-    public void setCreateTime(ZipLong l) { this.createTime = l; }
+    public void setCreateTime(ZipLong l) {
+        bit2_createTimePresent = l != null;
+        flags = (byte) (l != null ? (flags | CREATE_TIME_BIT)
+                        : (flags & ~CREATE_TIME_BIT));
+        this.createTime = l;
+    }
 
     /**
      * <p>

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java?rev=1549131&r1=1549130&r2=1549131&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
Sun Dec  8 19:14:25 2013
@@ -437,6 +437,27 @@ public class X5455_ExtendedTimestampTest
         zf.close();
     }
 
+    public void testBitsAreSetWithTime() {
+        xf.setModifyJavaTime(new Date(1111));
+        assertTrue(xf.isBit0_modifyTimePresent());
+        assertEquals(1, xf.getFlags());
+        xf.setAccessJavaTime(new Date(2222));
+        assertTrue(xf.isBit1_accessTimePresent());
+        assertEquals(3, xf.getFlags());
+        xf.setCreateJavaTime(new Date(3333));
+        assertTrue(xf.isBit2_createTimePresent());
+        assertEquals(7, xf.getFlags());
+        xf.setModifyJavaTime(null);
+        assertFalse(xf.isBit0_modifyTimePresent());
+        assertEquals(6, xf.getFlags());
+        xf.setAccessJavaTime(null);
+        assertFalse(xf.isBit1_accessTimePresent());
+        assertEquals(4, xf.getFlags());
+        xf.setCreateJavaTime(null);
+        assertFalse(xf.isBit2_createTimePresent());
+        assertEquals(0, xf.getFlags());
+    }
+
     private void parseReparse(
             final ZipLong time,
             final byte[] expectedLocal,
@@ -458,10 +479,10 @@ public class X5455_ExtendedTimestampTest
         System.arraycopy(almostExpectedCentral, 0, expectedCentral, 0, almostExpectedCentral.length);
         expectedCentral[0] = expectedFlags;
 
-        xf.setFlags(providedFlags);
         xf.setModifyTime(time);
         xf.setAccessTime(time);
         xf.setCreateTime(time);
+        xf.setFlags(providedFlags);
         byte[] result = xf.getLocalFileDataData();
         assertTrue(Arrays.equals(expectedLocal, result));
 
@@ -482,10 +503,10 @@ public class X5455_ExtendedTimestampTest
         }
 
         // Do the same as above, but with Central Directory data:
-        xf.setFlags(providedFlags);
         xf.setModifyTime(time);
         xf.setAccessTime(time);
         xf.setCreateTime(time);
+        xf.setFlags(providedFlags);
         result = xf.getCentralDirectoryData();
         assertTrue(Arrays.equals(expectedCentral, result));
 



Mime
View raw message