Author: bodewig
Date: Sat Jul 23 05:20:57 2011
New Revision: 1149802
URL: http://svn.apache.org/viewvc?rev=1149802&view=rev
Log:
merge collected changes from trunk
Added:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveSparseEntry.java
- copied unchanged from r1149800,
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveSparseEntry.java
Modified:
commons/proper/compress/branches/zip64/ (props changed)
commons/proper/compress/branches/zip64/src/changes/changes.xml
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/
(props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
(contents, props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
(props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/
(props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
(props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
(contents, props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(contents, props changed)
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
(props changed)
commons/proper/compress/branches/zip64/src/site/xdoc/examples.xml
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
(props changed)
Propchange: commons/proper/compress/branches/zip64/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1 +1 @@
-/commons/proper/compress/trunk:1149599,1149615
+/commons/proper/compress/trunk:1149597-1149800
Modified: commons/proper/compress/branches/zip64/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/changes/changes.xml?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
--- commons/proper/compress/branches/zip64/src/changes/changes.xml (original)
+++ commons/proper/compress/branches/zip64/src/changes/changes.xml Sat Jul 23
05:20:57 2011
@@ -45,6 +45,16 @@ The <action> type attribute can be add,u
</properties>
<body>
<release version="1.2" date="as in SVN" description="Release 1.2">
+ <action issue="COMPRESS-145" type="fix" date="2011-07-23"
+ due-tue="Patrick Dreyer">
+ TarArchiveInputStream now detects sparse entries and properly
+ reports it cannot extract their contents.
+ </action>
+ <action issue="COMPRESS-123" type="add" date="2011-07-23">
+ ZipArchiveEntry has a new method getRawName that provides the
+ original bytes that made up the name. This may allow user
+ code to detect the encoding.
+ </action>
<action issue="COMPRESS-130" type="fix" date="2011-07-20">
The Javadoc for ZipArchiveInputStream#skip now matches the
implementation, the code has been made more defensive.
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
Sat Jul 23 05:20:57 2011
@@ -42,10 +42,10 @@ import org.apache.commons.compress.archi
*
* This specifies that an ar archive entry header contains 60 bytes.
*
- * Due to the limitation of the file name length to 16 bytes GNU and BSD has
- * their own variants of this format. This formats are currently not supported
- * and file names with a bigger size than 16 bytes are not possible at the
- * moment.
+ * Due to the limitation of the file name length to 16 bytes GNU and
+ * BSD has their own variants of this format. Currently Commons
+ * Compress can read but not write the GNU variant and doesn't support
+ * the BSD variant at all.
*
* @see http://www.freebsd.org/cgi/man.cgi?query=ar&sektion=5
*
@@ -62,7 +62,7 @@ public class ArArchiveEntry implements A
/**
* SVR4/GNU adds a trailing / to names; BSD does not.
* They also vary in how names longer than 16 characters are represented.
- * (Not yet supported by this implementation)
+ * (Not yet fully supported by this implementation)
*/
private final String name;
private final int userId;
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/tar:741089
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
Sat Jul 23 05:20:57 2011
@@ -19,6 +19,7 @@
package org.apache.commons.compress.archivers.tar;
import java.io.File;
+import java.nio.ByteBuffer;
import java.util.Date;
import java.util.Locale;
@@ -78,6 +79,30 @@ import org.apache.commons.compress.archi
* New-style GNU tar files are slightly different from the above.
* </pre>
*
+ * <p>
+ * The C structure for a old GNU Tar Entry's header is:
+ * <pre>
+ * struct oldgnu_header {
+ * char unused_pad1[345]; // TarConstants.PAD1LEN_GNU - offset 0
+ * char atime[12]; // TarConstants.ATIMELEN_GNU - offset 345
+ * char ctime[12]; // TarConstants.CTIMELEN_GNU - offset 357
+ * char offset[12]; // TarConstants.OFFSETLEN_GNU - offset 369
+ * char longnames[4]; // TarConstants.LONGNAMESLEN_GNU - offset 381
+ * char unused_pad2; // TarConstants.PAD2LEN_GNU - offset 385
+ * struct sparse sp[4]; // TarConstants.SPARSELEN_GNU - offset 386
+ * char isextended; // TarConstants.ISEXTENDEDLEN_GNU - offset 482
+ * char realsize[12]; // TarConstants.REALSIZELEN_GNU - offset 483
+ * char unused_pad[17]; // TarConstants.PAD3LEN_GNU - offset 495
+ * };
+ * </pre>
+ * Whereas, "struct sparse" is:
+ * <pre>
+ * struct sparse {
+ * char offset[12]; // offset 0
+ * char numbytes[12]; // offset 12
+ * };
+ * </pre>
+ *
* @NotThreadSafe
*/
@@ -123,6 +148,12 @@ public class TarArchiveEntry implements
/** The entry's minor device number. */
private int devMinor;
+ /** If an extension sparse header follows. */
+ private boolean isExtended;
+
+ /** The entry's real size in case of a sparse file. */
+ private long realSize;
+
/** The entry's file reference */
private File file;
@@ -228,7 +259,7 @@ public class TarArchiveEntry implements
public TarArchiveEntry(File file) {
this(file, normalizeFileName(file.getPath(), false));
}
-
+
/**
* Construct an entry for a file. File is set to file, and the
* header is constructed from information from the file.
@@ -251,7 +282,7 @@ public class TarArchiveEntry implements
if (nameLength == 0 || fileName.charAt(nameLength - 1) != '/') {
this.name = fileName + "/";
} else {
- this.name = fileName;
+ this.name = fileName;
}
this.size = 0;
} else {
@@ -538,6 +569,33 @@ public class TarArchiveEntry implements
this.size = size;
}
+ /**
+ * Indicates in case of a sparse file if an extension sparse header
+ * follows.
+ *
+ * @return true if an extension sparse header follows.
+ */
+ public boolean isExtended() {
+ return isExtended;
+ }
+
+ /**
+ * Get this entry's real file size in case of a sparse file.
+ *
+ * @return This entry's real file size.
+ */
+ public long getRealSize() {
+ return realSize;
+ }
+
+ /**
+ * Indicate if this entry is a GNU sparse block
+ *
+ * @return true if this is a sparse extension provided by GNU tar
+ */
+ public boolean isGNUSparse() {
+ return linkFlag == LF_GNUTYPE_SPARSE;
+ }
/**
* Indicate if this entry is a GNU long name block
@@ -749,13 +807,34 @@ public class TarArchiveEntry implements
offset += DEVLEN;
devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
offset += DEVLEN;
- String prefix = TarUtils.parseName(header, offset, PREFIXLEN);
- // SunOS tar -E does not add / to directory names, so fix up to be
consistent
- if (isDirectory() && !name.endsWith("/")){
- name = name + "/";
+
+ int type = evaluateType(header);
+ switch (type) {
+ case FORMAT_OLDGNU: {
+ offset += ATIMELEN_GNU;
+ offset += CTIMELEN_GNU;
+ offset += OFFSETLEN_GNU;
+ offset += LONGNAMESLEN_GNU;
+ offset += PAD2LEN_GNU;
+ offset += SPARSELEN_GNU;
+ isExtended = TarUtils.parseBoolean(header, offset);
+ offset += ISEXTENDEDLEN_GNU;
+ realSize = TarUtils.parseOctal(header, offset, REALSIZELEN_GNU);
+ offset += REALSIZELEN_GNU;
+ break;
+ }
+ case FORMAT_POSIX:
+ default: {
+ String prefix = TarUtils.parseName(header, offset, PREFIXLEN);
+ // SunOS tar -E does not add / to directory names, so fix
+ // up to be consistent
+ if (isDirectory() && !name.endsWith("/")){
+ name = name + "/";
+ }
+ if (prefix.length() > 0){
+ name = prefix + "/" + name;
+ }
}
- if (prefix.length() >0){
- name = prefix + "/" + name;
}
}
@@ -801,5 +880,20 @@ public class TarArchiveEntry implements
}
return fileName;
}
+
+ /**
+ * Evaluate an entry's header format from a header buffer.
+ *
+ * @param header The tar entry header buffer to evaluate the format for.
+ * @return format type
+ */
+ private int evaluateType(byte[] header) {
+ final ByteBuffer magic = ByteBuffer.wrap(header, MAGIC_OFFSET,
MAGICLEN);
+ if (magic.compareTo(ByteBuffer.wrap(MAGIC_GNU.getBytes())) == 0)
+ return FORMAT_OLDGNU;
+ if (magic.compareTo(ByteBuffer.wrap(MAGIC_POSIX.getBytes())) == 0)
+ return FORMAT_POSIX;
+ return 0;
+ }
}
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,3 +1,3 @@
/ant/core/trunk/src/main/org/apache/tools/tar/TarArchiveEntry.java:741089
/ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java:807513,823136
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
Sat Jul 23 05:20:57 2011
@@ -185,23 +185,18 @@ public class TarArchiveInputStream exten
readBuf = null;
}
- byte[] headerBuf = buffer.readRecord();
-
- if (headerBuf == null) {
- hasHitEOF = true;
- } else if (buffer.isEOFRecord(headerBuf)) {
- hasHitEOF = true;
- }
+ byte[] headerBuf = getRecord();
if (hasHitEOF) {
currEntry = null;
- } else {
- currEntry = new TarArchiveEntry(headerBuf);
- entryOffset = 0;
- entrySize = currEntry.getSize();
+ return null;
}
- if (currEntry != null && currEntry.isGNULongNameEntry()) {
+ currEntry = new TarArchiveEntry(headerBuf);
+ entryOffset = 0;
+ entrySize = currEntry.getSize();
+
+ if (currEntry.isGNULongNameEntry()) {
// read in the name
StringBuffer longName = new StringBuffer();
byte[] buf = new byte[SMALL_BUFFER_SIZE];
@@ -223,13 +218,45 @@ public class TarArchiveInputStream exten
currEntry.setName(longName.toString());
}
- if (currEntry != null && currEntry.isPaxHeader()){ // Process Pax
headers
+ if (currEntry.isPaxHeader()){ // Process Pax headers
paxHeaders();
}
+ if (currEntry.isGNUSparse()){ // Process sparse files
+ readGNUSparse();
+ }
+
return currEntry;
}
+ /**
+ * Get the next record in this tar archive. This will skip
+ * over any remaining data in the current entry, if there
+ * is one, and place the input stream at the header of the
+ * next entry.
+ * If there are no more entries in the archive, null will
+ * be returned to indicate that the end of the archive has
+ * been reached.
+ *
+ * @return The next header in the archive, or null.
+ * @throws IOException on error
+ */
+ private byte[] getRecord() throws IOException {
+ if (hasHitEOF) {
+ return null;
+ }
+
+ byte[] headerBuf = buffer.readRecord();
+
+ if (headerBuf == null) {
+ hasHitEOF = true;
+ } else if (buffer.isEOFRecord(headerBuf)) {
+ hasHitEOF = true;
+ }
+
+ return hasHitEOF ? null : headerBuf;
+ }
+
private void paxHeaders() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(this,
"UTF-8"));
Map headers = new HashMap();
@@ -301,6 +328,35 @@ public class TarArchiveInputStream exten
}
}
+ /**
+ * Adds the sparse chunks from the current entry to the sparse chunks,
+ * including any additional sparse entries following the current entry.
+ *
+ * @throws IOException on error
+ *
+ * @todo Sparse files get not yet really processed.
+ */
+ private void readGNUSparse() throws IOException {
+ /* we do not really process sparse files yet
+ sparses = new ArrayList();
+ sparses.addAll(currEntry.getSparses());
+ */
+ if (currEntry.isExtended()) {
+ TarArchiveSparseEntry entry;
+ do {
+ byte[] headerBuf = getRecord();
+ if (hasHitEOF) {
+ currEntry = null;
+ break;
+ }
+ entry = new TarArchiveSparseEntry(headerBuf);
+ /* we do not really process sparse files yet
+ sparses.addAll(entry.getSparses());
+ */
+ } while (entry.isExtended());
+ }
+ }
+
public ArchiveEntry getNextEntry() throws IOException {
return getNextTarEntry();
}
@@ -385,6 +441,19 @@ public class TarArchiveInputStream exten
return totalRead;
}
+ /**
+ * Whether this class is able to read the given entry.
+ *
+ * <p>May return false if the current entry is a sparse file.</p>
+ */
+ public boolean canReadEntryData(ArchiveEntry ae) {
+ if (ae instanceof TarArchiveEntry) {
+ TarArchiveEntry te = (TarArchiveEntry) ae;
+ return !te.isGNUSparse();
+ }
+ return false;
+ }
+
protected final TarArchiveEntry getCurrentEntry() {
return currEntry;
}
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/tar/TarBuffer.java:741089,789556
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
Sat Jul 23 05:20:57 2011
@@ -21,11 +21,23 @@ package org.apache.commons.compress.arch
/**
* This interface contains all the definitions used in the package.
*
+ * For tar formats (FORMAT_OLDGNU, FORMAT_POSIX, etc.) see GNU tar
+ * <I>tar.h</I> type <I>enum archive_format</I>
*/
// CheckStyle:InterfaceIsTypeCheck OFF (bc)
public interface TarConstants {
/**
+ * GNU format as per before tar 1.12.
+ */
+ int FORMAT_OLDGNU = 2;
+
+ /**
+ * Pure Posix format.
+ */
+ int FORMAT_POSIX = 3;
+
+ /**
* The length of the name field in a header buffer.
*/
int NAMELEN = 100;
@@ -102,6 +114,66 @@ public interface TarConstants {
int PREFIXLEN = 155;
/**
+ * The length of the access time field in an old GNU header buffer.
+ *
+ */
+ int ATIMELEN_GNU = 12;
+
+ /**
+ * The length of the created time field in an old GNU header buffer.
+ *
+ */
+ int CTIMELEN_GNU = 12;
+
+ /**
+ * The length of the multivolume start offset field in an old GNU header
buffer.
+ *
+ */
+ int OFFSETLEN_GNU = 12;
+
+ /**
+ * The length of the long names field in an old GNU header buffer.
+ *
+ */
+ int LONGNAMESLEN_GNU = 4;
+
+ /**
+ * The length of the padding field in an old GNU header buffer.
+ *
+ */
+ int PAD2LEN_GNU = 1;
+
+ /**
+ * The sum of the length of all sparse headers in an old GNU header
buffer.
+ *
+ */
+ int SPARSELEN_GNU = 96;
+
+ /**
+ * The length of the is extension field in an old GNU header buffer.
+ *
+ */
+ int ISEXTENDEDLEN_GNU = 1;
+
+ /**
+ * The length of the real size field in an old GNU header buffer.
+ *
+ */
+ int REALSIZELEN_GNU = 12;
+
+ /**
+ * The sum of the length of all sparse headers in a sparse header buffer.
+ *
+ */
+ int SPARSELEN_GNU_SPARSE = 504;
+
+ /**
+ * The length of the is extension field in a sparse header buffer.
+ *
+ */
+ int ISEXTENDEDLEN_GNU_SPARSE = 1;
+
+ /**
* LF_ constants represent the "link flag" of an entry, or more commonly,
* the "entry type". This is the "old way" of indicating a normal file.
*/
@@ -152,6 +224,12 @@ public interface TarConstants {
*/
byte LF_GNUTYPE_LONGNAME = (byte) 'L';
+ /**
+ * Sparse file type.
+ * @since Apache Commons Compress 1.1.1
+ */
+ byte LF_GNUTYPE_SPARSE = (byte) 'S';
+
// See
"http://www.opengroup.org/onlinepubs/009695399/utilities/pax.html#tag_04_100_13_02"
/**
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
Sat Jul 23 05:20:57 2011
@@ -106,6 +106,21 @@ public class TarUtils {
return result;
}
+ /**
+ * Parse a boolean byte from a buffer.
+ * Leading spaces and NUL are ignored.
+ * The buffer may contain trailing spaces or NULs.
+ *
+ * @param buffer The buffer from which to parse.
+ * @param offset The offset into the buffer from which to parse.
+ * @param length The maximum number of bytes to parse - must be at least 1
byte.
+ * @return The boolean value of the bytes.
+ * @throws IllegalArgumentException if an invalid byte is detected.
+ */
+ public static boolean parseBoolean(final byte[] buffer, final int offset) {
+ return (buffer[offset] == 1);
+ }
+
// Helper method to generate the exception message
private static String exceptionMessage(byte[] buffer, final int offset,
final int length, int current, final byte currentByte) {
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/zip:738844,739300,741089
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip:1149597-1149800
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1 +1 @@
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
Sat Jul 23 05:20:57 2011
@@ -82,6 +82,7 @@ public class ZipArchiveEntry extends jav
private LinkedHashMap/*<ZipShort, ZipExtraField>*/ extraFields = null;
private UnparseableExtraFieldData unparseableExtra = null;
private String name = null;
+ private byte[] rawName = null;
private GeneralPurposeBit gpb = new GeneralPurposeBit();
/**
@@ -526,6 +527,34 @@ public class ZipArchiveEntry extends jav
}
/**
+ * Package private setter that sets the name using the raw bytes
+ * and the string created from it by guessing or suing the
+ * configured encoding.
+ */
+ void setName(String name, byte[] rawName) {
+ setName(name);
+ this.rawName = rawName;
+ }
+
+ /**
+ * Returns the raw bytes that made up the name before it has been
+ * converted using the configured or guessed encoding.
+ *
+ * <p>This method will return null if this instance has not been
+ * read from an archive.</p>
+ *
+ * @since Apache Commons Compress 1.2
+ */
+ public byte[] getRawName() {
+ if (rawName != null) {
+ byte[] b = new byte[rawName.length];
+ System.arraycopy(rawName, 0, b, 0, rawName.length);
+ return b;
+ }
+ return null;
+ }
+
+ /**
* Get the hashCode of the entry.
* This uses the name as the hashcode.
* @return a hashcode.
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java:745537
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Sat Jul 23 05:20:57 2011
@@ -195,7 +195,7 @@ public class ZipArchiveInputStream exten
byte[] fileName = new byte[fileNameLen];
readFully(fileName);
- current.setName(entryEncoding.decode(fileName));
+ current.setName(entryEncoding.decode(fileName), fileName);
byte[] extraData = new byte[extraLen];
readFully(extraData);
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1 +1 @@
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java:1149597-1149800
Modified:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Sat Jul 23 05:20:57 2011
@@ -450,7 +450,7 @@ public class ZipFile {
byte[] fileName = new byte[fileNameLen];
archive.readFully(fileName);
- ze.setName(entryEncoding.decode(fileName));
+ ze.setName(entryEncoding.decode(fileName), fileName);
// LFH offset,
OffsetEntry offset = new OffsetEntry();
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java:738844,738853,739300,741089,747002,1146020
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:1149597-1149800
Propchange:
commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java:741089
-/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java:1149599,1149615
+/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java:1149597-1149800
Modified: commons/proper/compress/branches/zip64/src/site/xdoc/examples.xml
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/site/xdoc/examples.xml?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
--- commons/proper/compress/branches/zip64/src/site/xdoc/examples.xml (original)
+++ commons/proper/compress/branches/zip64/src/site/xdoc/examples.xml Sat Jul
23 05:20:57 2011
@@ -95,6 +95,14 @@ LOOP UNTIL entry.getSize() HAS BEEN READ
}
]]></source>
+ <p>Traditionally the AR format doesn't allow file names longer
+ than 16 characters. There are two variants that circumvent
+ this limitation in different ways, the GNU/SRV4 and the BSD
+ variant. Currently Commons Compress can only read archives
+ using the GNU/SRV4 variant, it doesn't support writing
+ archives with file names longer than 16 characters at
+ all.</p>
+
</subsection>
<subsection name="cpio">
Modified:
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=1149802&r1=1149801&r2=1149802&view=diff
==============================================================================
---
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
(original)
+++
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
Sat Jul 23 05:20:57 2011
@@ -192,6 +192,35 @@ public class UTF8ZipFilesTest extends Ab
}
}
+ public void testRawNameReadFromZipFile()
+ throws IOException, URISyntaxException {
+ URL zip = getClass().getResource("/utf8-7zip-test.zip");
+ File archive = new File(new URI(zip.toString()));
+ ZipFile zf = null;
+ try {
+ zf = new ZipFile(archive, CP437, false);
+ assertRawNameOfAcsiiTxt(zf.getEntry(ASCII_TXT));
+ } finally {
+ ZipFile.closeQuietly(zf);
+ }
+ }
+
+ public void testRawNameReadFromStream()
+ throws IOException, URISyntaxException {
+ URL zip = getClass().getResource("/utf8-7zip-test.zip");
+ FileInputStream archive =
+ new FileInputStream(new File(new URI(zip.toString())));
+ ZipArchiveInputStream zi = null;
+ try {
+ zi = new ZipArchiveInputStream(archive, CP437, false);
+ assertRawNameOfAcsiiTxt((ZipArchiveEntry) zi.getNextEntry());
+ } finally {
+ if (zi != null) {
+ zi.close();
+ }
+ }
+ }
+
private static void testFileRoundtrip(String encoding, boolean withEFS,
boolean withExplicitUnicodeExtra)
throws IOException {
@@ -343,5 +372,15 @@ public class UTF8ZipFilesTest extends Ab
}
+ private static void assertRawNameOfAcsiiTxt(ZipArchiveEntry ze) {
+ byte[] b = ze.getRawName();
+ assertNotNull(b);
+ final int len = ASCII_TXT.length();
+ assertEquals(len, b.length);
+ for (int i = 0; i < len; i++) {
+ assertEquals("Byte " + i, (byte) ASCII_TXT.charAt(i), b[i]);
+ }
+ assertNotSame(b, ze.getRawName());
+ }
}
Propchange:
commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul 23 05:20:57 2011
@@ -1,2 +1,2 @@
/ant/core/trunk/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java:745537
-/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java:1149599,1149615
+/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java:1149597-1149800