commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1426326 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/
Date Thu, 27 Dec 2012 21:04:23 GMT
Author: bodewig
Date: Thu Dec 27 21:04:23 2012
New Revision: 1426326

URL: http://svn.apache.org/viewvc?rev=1426326&view=rev
Log:
COMPRESS-200 aftermaths, we never guarantee ZipEncoding#encode returned a ByteBuffer with
position() 0 - even though it always in right now

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=1426326&r1=1426325&r2=1426326&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
Thu Dec 27 21:04:23 2012
@@ -354,7 +354,7 @@ public class TarUtils {
         while (b.limit() > length && len > 0) {
             b = encoding.encode(name.substring(0, --len));
         }
-        final int limit = b.limit();
+        final int limit = b.limit() - b.position();
         System.arraycopy(b.array(), b.arrayOffset(), buf, offset, limit);
 
         // Pad any remaining output bytes with NUL

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1426326&r1=1426325&r2=1426326&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Thu Dec 27 21:04:23 2012
@@ -936,7 +936,8 @@ public class ZipArchiveOutputStream exte
         written += SHORT;
 
         // file name
-        writeOut(name.array(), name.arrayOffset(), name.limit());
+        writeOut(name.array(), name.arrayOffset(),
+                 name.limit() - name.position());
         written += name.limit();
 
         // extra field
@@ -959,7 +960,8 @@ public class ZipArchiveOutputStream exte
             ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                        name.array(),
                                                        name.arrayOffset(),
-                                                       name.limit()));
+                                                       name.limit()
+                                                       - name.position()));
         }
 
         String comm = ze.getComment();
@@ -973,7 +975,8 @@ public class ZipArchiveOutputStream exte
                 ze.addExtraField(new UnicodeCommentExtraField(comm,
                                                               commentB.array(),
                                                               commentB.arrayOffset(),
-                                                              commentB.limit())
+                                                              commentB.limit()
+                                                              - commentB.position())
                                  );
             }
         }
@@ -1107,7 +1110,8 @@ public class ZipArchiveOutputStream exte
         written += WORD;
 
         // file name
-        writeOut(name.array(), name.arrayOffset(), name.limit());
+        writeOut(name.array(), name.arrayOffset(),
+                 name.limit() - name.position());
         written += name.limit();
 
         // extra field
@@ -1115,7 +1119,8 @@ public class ZipArchiveOutputStream exte
         written += extra.length;
 
         // file comment
-        writeOut(commentB.array(), commentB.arrayOffset(), commentB.limit());
+        writeOut(commentB.array(), commentB.arrayOffset(),
+                 commentB.limit() - commentB.position());
         written += commentB.limit();
     }
 
@@ -1181,7 +1186,8 @@ public class ZipArchiveOutputStream exte
         // ZIP file comment
         ByteBuffer data = this.zipEncoding.encode(comment);
         writeOut(ZipShort.getBytes(data.limit()));
-        writeOut(data.array(), data.arrayOffset(), data.limit());
+        writeOut(data.array(), data.arrayOffset(),
+                 data.limit() - data.position());
     }
 
     private static final byte[] ONE = ZipLong.getBytes(1L);

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=1426326&r1=1426325&r2=1426326&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
Thu Dec 27 21:04:23 2012
@@ -272,7 +272,8 @@ public class UTF8ZipFilesTest extends Ab
                 ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                            en.array(),
                                                            en.arrayOffset(),
-                                                           en.limit()));
+                                                           en.limit()
+                                                           - en.position()));
             }
 
             zos.putArchiveEntry(ze);
@@ -288,7 +289,8 @@ public class UTF8ZipFilesTest extends Ab
                 ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                            en.array(),
                                                            en.arrayOffset(),
-                                                           en.limit()));
+                                                           en.limit()
+                                                           - en.position()));
             }
 
             zos.putArchiveEntry(ze);
@@ -305,7 +307,8 @@ public class UTF8ZipFilesTest extends Ab
                 ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                            en.array(),
                                                            en.arrayOffset(),
-                                                           en.limit()));
+                                                           en.limit()
+                                                           - en.position()));
             }
 
             zos.putArchiveEntry(ze);
@@ -364,7 +367,8 @@ public class UTF8ZipFilesTest extends Ab
             ByteBuffer ne = enc.encode(ze.getName());
 
             CRC32 crc = new CRC32();
-            crc.update(ne.array(),ne.arrayOffset(),ne.limit());
+            crc.update(ne.array(), ne.arrayOffset(),
+                       ne.limit() - ne.position());
 
             assertEquals(crc.getValue(), ucpf.getNameCRC32());
             assertEquals(expectedName, new String(ucpf.getUnicodeName(),



Mime
View raw message