Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 678F9E80B for ; Thu, 27 Dec 2012 20:55:04 +0000 (UTC) Received: (qmail 3490 invoked by uid 500); 27 Dec 2012 20:55:04 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 3417 invoked by uid 500); 27 Dec 2012 20:55:04 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 3408 invoked by uid 99); 27 Dec 2012 20:55:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2012 20:55:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2012 20:55:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1A040238896F; Thu, 27 Dec 2012 20:54:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1426319 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Date: Thu, 27 Dec 2012 20:54:42 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121227205443.1A040238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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. + + 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. + 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 paxHeaders = new HashMap(); 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) {