Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 31687 invoked from network); 19 May 2009 15:37:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 May 2009 15:37:36 -0000 Received: (qmail 5547 invoked by uid 500); 19 May 2009 15:37:35 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 5456 invoked by uid 500); 19 May 2009 15:37:35 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 5446 invoked by uid 99); 19 May 2009 15:37:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 15:37:34 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=FORGED_MUA_OUTLOOK,HTML_MESSAGE,MSOE_MID_WRONG_CASE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [212.62.68.42] (HELO mx1.dts-online.net) (212.62.68.42) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 15:37:23 +0000 Received: from localhost (unknown [127.0.0.1]) by mx1.dts-online.net (Postfix) with ESMTP id 77F1B4FC747 for ; Tue, 19 May 2009 17:37:03 +0200 (CEST) Received: from mx1.dts-online.net ([127.0.0.1]) by localhost (gkar.dts-online.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 59332-35 for ; Tue, 19 May 2009 17:36:52 +0200 (CEST) Received: from smtp.beldts.intra (unknown [212.98.165.53]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.dts-online.net (Postfix) with ESMTP id 93A0A3435A5 for ; Tue, 19 May 2009 17:36:52 +0200 (CEST) Received: from aborisevich.beldts.intra ([192.168.129.174] helo=aborisevich) by smtp.beldts.intra with smtp (Exim 4.69) (envelope-from ) id 1M6RN5-0003g8-OJ for dev@ant.apache.org; Tue, 19 May 2009 18:36:51 +0300 From: "aborisevich" To: Subject: Including national characters int Tar Entry names into archive. Date: Tue, 19 May 2009 18:31:57 +0300 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00DA_01C9D8B0.17208260" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Message-Id: <20090519153703.77F1B4FC747@mx1.dts-online.net> X-Virus-Checked: Checked by ClamAV on apache.org ------=_NextPart_000_00DA_01C9D8B0.17208260 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Hello everyone. I have found the next bug using present = org.apache.tools.tar package. Tar Archive was created on one system (for = example Windows XP - default charset CP-1251). This tar archive = contains TarEntries were named with using national characters like = German umlauts. Than this archive file was copied on Linux system = (default charset UTF-8) - after unpackin this archive file there - = information was lost (TarEntries names were lost). There is possible = solution for this problem. Index: ant-core/src/main/org/apache/tools/tar/TarInputStream.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ant-core/src/main/org/apache/tools/tar/TarInputStream.java (revision = 776302) +++ ant-core/src/main/org/apache/tools/tar/TarInputStream.java (working = copy) @@ -264,10 +264,10 @@ if (currEntry !=3D null && currEntry.isGNULongNameEntry()) { // read in the name StringBuffer longName =3D new StringBuffer(); - byte[] buf =3D new byte[SMALL_BUFFER_SIZE]; + byte[] buf =3D new byte[(int)currEntry.getSize()]; int length =3D 0; while ((length =3D read(buf)) >=3D 0) { - longName.append(new String(buf, 0, length)); + longName.append(new String(buf, 0, length, "UTF-8")); } getNextEntry(); if (currEntry =3D=3D null) { Index: ant-core/src/main/org/apache/tools/tar/TarOutputStream.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ant-core/src/main/org/apache/tools/tar/TarOutputStream.java = (revision 776302) +++ ant-core/src/main/org/apache/tools/tar/TarOutputStream.java (working = copy) @@ -179,9 +179,10 @@ TarEntry longLinkEntry =3D new = TarEntry(TarConstants.GNU_LONGLINK, = TarConstants.LF_GNUTYPE_LONGNAME); =20 - longLinkEntry.setSize(entry.getName().length() + 1); + byte[] nameBytes =3D entry.getName().getBytes("UTF-8"); + longLinkEntry.setSize(nameBytes.length + 1); putNextEntry(longLinkEntry); - write(entry.getName().getBytes()); + write(nameBytes); write(0); closeEntry(); } else if (longFileMode !=3D LONGFILE_TRUNCATE) { Index: ant-core/src/main/org/apache/tools/tar/TarUtils.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ant-core/src/main/org/apache/tools/tar/TarUtils.java (revision = 776302) +++ ant-core/src/main/org/apache/tools/tar/TarUtils.java (working copy) @@ -23,6 +23,8 @@ =20 package org.apache.tools.tar; =20 +import java.io.UnsupportedEncodingException; + /** * This class provides static utility methods to work with byte = streams. * @@ -79,15 +81,21 @@ * @return The header's entry name. */ public static StringBuffer parseName(byte[] header, int offset, int = length) { - StringBuffer result =3D new StringBuffer(length); + StringBuffer result =3D null; + int nameLen =3D length; + int end =3D offset + length; - for (int i =3D offset; i < end; ++i) { - if (header[i] =3D=3D 0) { + if(header[i] =3D=3D 0) { + nameLen =3D i - offset; break; } + } =20 - result.append((char) header[i]); + try { + result =3D new StringBuffer(new String(header, offset, = nameLen, "UTF-8")); + } catch(UnsupportedEncodingException e) { + e.printStackTrace(); } =20 return result; @@ -103,18 +111,23 @@ * @return The number of bytes in a header's entry name. */ public static int getNameBytes(StringBuffer name, byte[] buf, int = offset, int length) { - int i; + int nameLength =3D -1; + try + { + byte nameBytes[] =3D name.toString().getBytes("UTF-8"); + nameLength =3D nameBytes.length ; + System.arraycopy(nameBytes, 0, buf, offset, nameLength); + } catch(UnsupportedEncodingException e) { + e.printStackTrace(); + } =20 - for (i =3D 0; i < length && i < name.length(); ++i) { - buf[offset + i] =3D (byte) name.charAt(i); - } =20 - for (; i < length; ++i) { - buf[offset + i] =3D 0; - } + for (; nameLength < length; ++nameLength) { + buf[offset + nameLength] =3D 0; + } =20 - return offset + length; - } + return offset + length; + } =20 /** * Parse an octal integer from a header buffer. Best Regards. Alexander Borisevich =20 BelDTS Minsk Belarus ------=_NextPart_000_00DA_01C9D8B0.17208260--