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 2018/07/11 17:01:40 UTC
commons-compress git commit: COMPRESS-459 no reason to encode the
name twice
Repository: commons-compress
Updated Branches:
refs/heads/master 430e12676 -> 6f8c4960c
COMPRESS-459 no reason to encode the name twice
This reverts commit c8ee9f781900f874b075433141de779723b3e110.
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/6f8c4960
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/6f8c4960
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/6f8c4960
Branch: refs/heads/master
Commit: 6f8c4960c2af25b7e4b36473d81fe652490dbbeb
Parents: 430e126
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed Jul 11 18:59:32 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed Jul 11 19:00:21 2018 +0200
----------------------------------------------------------------------
.../archivers/cpio/CpioArchiveEntry.java | 22 +++++++-------------
.../archivers/cpio/CpioArchiveOutputStream.java | 5 +++--
2 files changed, 10 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6f8c4960/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
index 6aeb7ce..79e7542 100644
--- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
@@ -18,13 +18,11 @@
*/
package org.apache.commons.compress.archivers.cpio;
-import java.nio.ByteBuffer;
import java.io.File;
-import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Date;
import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipEncoding;
/**
* A cpio archive consists of a sequence of files. There are several types of
@@ -470,7 +468,7 @@ public class CpioArchiveEntry implements CpioConstants, ArchiveEntry {
* Get the number of bytes needed to pad the header to the alignment boundary.
*
* @deprecated This method doesn't properly work for multi-byte encodings. And
- * creates corrupt archives. Use {@link #getHeaderPadCount(ZipEncoding)}
+ * creates corrupt archives. Use {@link #getHeaderPadCount(Charset)}
* or {@link #getHeaderPadCount(long)} in any case.
* @return the number of bytes needed to pad the header (0,1,2,3)
*/
@@ -482,25 +480,19 @@ public class CpioArchiveEntry implements CpioConstants, ArchiveEntry {
/**
* Get the number of bytes needed to pad the header to the alignment boundary.
*
- * @param encoding
- * The encoding used to encode the entry name in the stream.
+ * @param charset
+ * The character set used to encode the entry name in the stream.
* @return the number of bytes needed to pad the header (0,1,2,3)
* @since 1.18
*/
- public int getHeaderPadCount(ZipEncoding encoding) {
+ public int getHeaderPadCount(Charset charset) {
if (name == null) {
return 0;
}
- if (encoding == null) {
+ if (charset == null) {
return getHeaderPadCount(name.length());
}
- try {
- final ByteBuffer buf = encoding.encode(name);
- return getHeaderPadCount(buf.limit() - buf.position());
- } catch (IOException ex) {
- // won't happen as the output stream has already encoded the name without error
- throw new RuntimeException("cannot encode " + name, ex);
- }
+ return getHeaderPadCount(name.getBytes(charset).length);
}
/**
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6f8c4960/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
index 73cf714..ab29b46 100644
--- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashMap;
@@ -304,7 +305,7 @@ public class CpioArchiveOutputStream extends ArchiveOutputStream implements
writeAsciiLong(name.length + 1L, 8, 16);
writeAsciiLong(entry.getChksum(), 8, 16);
writeCString(name);
- pad(entry.getHeaderPadCount(zipEncoding));
+ pad(entry.getHeaderPadCount(name.length));
}
private void writeOldAsciiEntry(final CpioArchiveEntry entry)
@@ -367,7 +368,7 @@ public class CpioArchiveOutputStream extends ArchiveOutputStream implements
writeBinaryLong(name.length + 1L, 2, swapHalfWord);
writeBinaryLong(entry.getSize(), 4, swapHalfWord);
writeCString(name);
- pad(entry.getHeaderPadCount(zipEncoding));
+ pad(entry.getHeaderPadCount(name.length));
}
/*(non-Javadoc)