You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2012/12/27 21:54:42 UTC
svn commit: r1426319 - in /commons/proper/compress/trunk/src:
changes/changes.xml
main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
Author: bodewig
Date: Thu Dec 27 20:54:42 2012
New Revision: 1426319
URL: http://svn.apache.org/viewvc?rev=1426319&view=rev
Log:
COMPRESS-200 use the backing array of the returned ByteBuffer properly
Modified:
commons/proper/compress/trunk/src/changes/changes.xml
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.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=1426319&r1=1426318&r2=1426319&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Thu Dec 27 20:54:42 2012
@@ -69,6 +69,11 @@ The <action> type attribute can be add,u
dependency on it has now been marked optional so Compress
itself can still be used in an OSGi context.
</action>
+ <action type="fix" date="2012-12-27" issue="COMPRESS-200">
+ When specifying the encoding explicitly TarArchiveOutputStream
+ would write unreadable names in GNU mode or even cause errors
+ in POSIX mode for file names longer than 66 characters.
+ </action>
</release>
<release version="1.4.1" date="2012-05-23"
description="Release 1.4.1">
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=1426319&r1=1426318&r2=1426319&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Thu Dec 27 20:54:42 2012
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
+import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -266,9 +267,10 @@ public class TarArchiveOutputStream exte
TarArchiveEntry entry = (TarArchiveEntry) archiveEntry;
Map<String, String> paxHeaders = new HashMap<String, String>();
final String entryName = entry.getName();
- final byte[] nameBytes = encoding.encode(entryName).array();
+ final ByteBuffer encodedName = encoding.encode(entryName);
+ final int nameLen = encodedName.limit() - encodedName.position();
boolean paxHeaderContainsPath = false;
- if (nameBytes.length >= TarConstants.NAMELEN) {
+ if (nameLen >= TarConstants.NAMELEN) {
if (longFileMode == LONGFILE_POSIX) {
paxHeaders.put("path", entryName);
@@ -279,9 +281,9 @@ public class TarArchiveOutputStream exte
TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK,
TarConstants.LF_GNUTYPE_LONGNAME);
- longLinkEntry.setSize(nameBytes.length + 1); // +1 for NUL
+ longLinkEntry.setSize(nameLen + 1); // +1 for NUL
putArchiveEntry(longLinkEntry);
- write(nameBytes);
+ write(encodedName.array(), encodedName.arrayOffset(), nameLen);
write(0); // NUL terminator
closeArchiveEntry();
} else if (longFileMode != LONGFILE_TRUNCATE) {