commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1211465 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
Date Wed, 07 Dec 2011 15:01:27 GMT
Author: bodewig
Date: Wed Dec  7 15:01:27 2011
New Revision: 1211465

URL: http://svn.apache.org/viewvc?rev=1211465&view=rev
Log:
prove parsing of PAX headers works correctly.  COMPRESS-167

Added:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
  (with props)
Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=1211465&r1=1211464&r2=1211465&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
Wed Dec  7 15:01:27 2011
@@ -272,9 +272,21 @@ public class TarArchiveInputStream exten
                     // make sure GC doesn't close "this" before we are done
                 }
             };
+        Map<String, String> headers = null;
+        try {
+            headers = parsePaxHeaders(br);
+        } finally {
+            // NO-OP but makes FindBugs happy
+            br.close();
+        }
+
+        getNextEntry(); // Get the actual file entry
+        applyPaxHeadersToCurrentEntry(headers);
+    }
+
+    Map<String, String> parsePaxHeaders(Reader br) throws IOException {
         Map<String, String> headers = new HashMap<String, String>();
         // Format is "length keyword=value\n";
-        try {
             while(true){ // get length
                 int ch;
                 int len = 0;
@@ -315,12 +327,10 @@ public class TarArchiveInputStream exten
                     break;
                 }
             }
-        } finally {
-            // NO-OP but makes FindBugs happy
-            br.close();
-        }
+        return headers;
+    }
 
-        getNextEntry(); // Get the actual file entry
+    private void applyPaxHeadersToCurrentEntry(Map<String, String> headers) {
         /*
          * The following headers are defined for Pax.
          * atime, ctime, mtime, charset: cannot use these without changing TarArchiveEntry
fields

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java?rev=1211465&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
(added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
Wed Dec  7 15:01:27 2011
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.commons.compress.archivers.tar;
+
+import java.io.StringReader;
+import java.util.Map;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class TarArchiveInputStreamTest {
+
+    @Test
+    public void readSimplePaxHeader() throws Exception {
+        Map<String, String> headers = new TarArchiveInputStream(null)
+            .parsePaxHeaders(new StringReader("30 atime=1321711775.972059463\n"));
+        assertEquals(1, headers.size());
+        assertEquals("1321711775.972059463", headers.get("atime"));
+    }
+
+    @Test
+    public void readPaxHeaderWithEmbeddedNewline() throws Exception {
+        Map<String, String> headers = new TarArchiveInputStream(null)
+            .parsePaxHeaders(new StringReader("28 comment=line1\nline2\nand3\n"));
+        assertEquals(1, headers.size());
+        assertEquals("line1\nline2\nand3", headers.get("comment"));
+    }
+}
\ No newline at end of file

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message