Author: sebb Date: Tue Apr 14 23:21:52 2009 New Revision: 764999 URL: http://svn.apache.org/viewvc?rev=764999&view=rev Log: COMPRESS-63 - replace dependency on default charset with ASCII where appropriate; add TODOs where the required charset is not yet clear.
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java Tue Apr 14 23:21:52 2009 @@ -23,6 +23,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.utils.ArchiveUtils; /** * Implements the "ar" archive format as an input stream. @@ -73,7 +74,7 @@ } if (offset == 0) { - final byte[] expected = ArArchiveEntry.HEADER.getBytes(); + final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.HEADER); final byte[] realized = new byte[expected.length]; final int read = read(realized); if (read != expected.length) { @@ -81,7 +82,7 @@ } for (int i = 0; i < expected.length; i++) { if (expected[i] != realized[i]) { - throw new IOException("invalid header " + new String(realized)); + throw new IOException("invalid header " + ArchiveUtils.toAsciiString(realized)); } } } @@ -112,7 +113,7 @@ read(length); { - final byte[] expected = ArArchiveEntry.TRAILER.getBytes(); + final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.TRAILER); final byte[] realized = new byte[expected.length]; final int read = read(realized); if (read != expected.length) { @@ -132,7 +133,7 @@ if (temp.endsWith("/")){ temp=temp.substring(0, temp.length()-1); } - currentEntry = new ArArchiveEntry(temp, + currentEntry = new ArArchiveEntry(temp, // TODO is it correct to use the default charset here? Long.parseLong(new String(length) .trim())); return currentEntry; Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java Tue Apr 14 23:21:52 2009 @@ -24,6 +24,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveOutputStream; +import org.apache.commons.compress.utils.ArchiveUtils; /** * Implements the "ar" archive format as an output stream. @@ -43,7 +44,7 @@ } private long writeArchiveHeader() throws IOException { - byte [] header = ArArchiveEntry.HEADER.getBytes(); + byte [] header = ArchiveUtils.toAsciiBytes(ArArchiveEntry.HEADER); out.write(header); return header.length; } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java Tue Apr 14 23:21:52 2009 @@ -24,6 +24,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.utils.ArchiveUtils; /** * CPIOArchiveInputStream is a stream for reading cpio streams. All formats of @@ -175,7 +176,7 @@ System.arraycopy(magic, 0, tmp, 0, magic.length); System.arraycopy(more_magic, 0, tmp, magic.length, more_magic.length); - String magicString = new String(tmp); + String magicString = ArchiveUtils.toAsciiString(tmp); if (magicString.equals(MAGIC_NEW)) { this.entry = readNewEntry(false); } else if (magicString.equals(MAGIC_NEW_CRC)) { @@ -288,7 +289,7 @@ throws IOException { byte tmpBuffer[] = new byte[length]; readFully(tmpBuffer, 0, tmpBuffer.length); - return Long.parseLong(new String(tmpBuffer), radix); + return Long.parseLong(ArchiveUtils.toAsciiString(tmpBuffer), radix); } private CpioArchiveEntry readNewEntry(final boolean hasCrc) Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java Tue Apr 14 23:21:52 2009 @@ -26,6 +26,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveOutputStream; +import org.apache.commons.compress.utils.ArchiveUtils; /** * CPIOArchiveOutputStream is a stream for writing CPIO streams. All formats of @@ -167,15 +168,15 @@ private void writeHeader(final CpioArchiveEntry e) throws IOException { switch (e.getFormat()) { case FORMAT_NEW: - out.write(MAGIC_NEW.getBytes()); + out.write(ArchiveUtils.toAsciiBytes(MAGIC_NEW)); writeNewEntry(e); break; case FORMAT_NEW_CRC: - out.write(MAGIC_NEW_CRC.getBytes()); + out.write(ArchiveUtils.toAsciiBytes(MAGIC_NEW_CRC)); writeNewEntry(e); break; case FORMAT_OLD_ASCII: - out.write(MAGIC_OLD_ASCII.getBytes()); + out.write(ArchiveUtils.toAsciiBytes(MAGIC_OLD_ASCII)); writeOldAsciiEntry(e); break; case FORMAT_OLD_BINARY: @@ -372,12 +373,12 @@ } else { tmpStr = tmp.substring(tmp.length() - length); } - out.write(tmpStr.getBytes()); + out.write(tmpStr.getBytes()); // TODO is it correct to use the default charset here? } private void writeCString(final String str) throws IOException { out.write(str.getBytes()); - out.write('\0'); + out.write('\0'); // TODO is it correct to use the default charset here? } public ArchiveEntry createArchiveEntry(File inputFile, String entryName) 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=764999&r1=764998&r2=764999&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 Tue Apr 14 23:21:52 2009 @@ -158,7 +158,7 @@ TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK, TarConstants.LF_GNUTYPE_LONGNAME); - final byte[] nameBytes = entry.getName().getBytes(); + final byte[] nameBytes = entry.getName().getBytes(); // TODO is it correct to use the default charset here? longLinkEntry.setSize(nameBytes.length + 1); // +1 for NUL putArchiveEntry(longLinkEntry); write(nameBytes); Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java Tue Apr 14 23:21:52 2009 @@ -101,7 +101,7 @@ + WORD // SizDev + 2 // UID + 2 // GID - + getLinkedFile().getBytes().length); + + getLinkedFile().getBytes().length); // TODO is it correct to use the default charset here? } /** @@ -122,7 +122,7 @@ byte[] data = new byte[getLocalFileDataLength().getValue() - WORD]; System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); - byte[] linkArray = getLinkedFile().getBytes(); + byte[] linkArray = getLinkedFile().getBytes(); // TODO is it correct to use the default charset here? // CheckStyle:MagicNumber OFF System.arraycopy(ZipLong.getBytes(linkArray.length), 0, data, 2, WORD); @@ -280,7 +280,7 @@ link = ""; } else { System.arraycopy(tmp, 10, linkArray, 0, linkArray.length); - link = new String(linkArray); + link = new String(linkArray); // TODO is it correct to use the default charset here? } // CheckStyle:MagicNumber ON setDirectory((newMode & DIR_FLAG) != 0); Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java?rev=764999&r1=764998&r2=764999&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FallbackZipEncoding.java Tue Apr 14 23:21:52 2009 @@ -75,7 +75,7 @@ */ public ByteBuffer encode(String name) throws IOException { if (this.charset == null) { - return ByteBuffer.wrap(name.getBytes()); + return ByteBuffer.wrap(name.getBytes()); // TODO is it correct to use the default charset here? } else { return ByteBuffer.wrap(name.getBytes(this.charset)); } @@ -87,7 +87,7 @@ */ public String decode(byte[] data) throws IOException { if (this.charset == null) { - return new String(data); + return new String(data); // TODO is it correct to use the default charset here? } else { return new String(data,this.charset); }