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 2009/03/05 05:35:32 UTC
svn commit: r750310 -
/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Author: bodewig
Date: Thu Mar 5 04:35:32 2009
New Revision: 750310
URL: http://svn.apache.org/viewvc?rev=750310&view=rev
Log:
ensure the same encoding is used for name and comment in all places. Submitted by Wolfgang Glas
Modified:
commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=750310&r1=750309&r2=750310&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Thu Mar 5 04:35:32 2009
@@ -629,12 +629,16 @@
protected void writeLocalFileHeader(ZipArchiveEntry ze) throws IOException {
boolean encodable = zipEncoding.canEncode(ze.getName());
- ByteBuffer name;
+
+ final ZipEncoding entryEncoding;
+
if (!encodable && fallbackToUTF8) {
- name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName());
+ entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING;
} else {
- name = zipEncoding.encode(ze.getName());
+ entryEncoding = zipEncoding;
}
+
+ ByteBuffer name = entryEncoding.encode(ze.getName());
if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) {
@@ -653,7 +657,7 @@
if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
|| !commentEncodable) {
- ByteBuffer commentB = this.zipEncoding.encode(comm);
+ ByteBuffer commentB = entryEncoding.encode(comm);
ze.addExtraField(new UnicodeCommentExtraField(comm,
commentB.array(),
commentB.arrayOffset(),
@@ -779,12 +783,16 @@
// CheckStyle:MagicNumber ON
// file name length
- ByteBuffer name;
+ final ZipEncoding entryEncoding;
+
if (!encodable && fallbackToUTF8) {
- name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName());
+ entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING;
} else {
- name = zipEncoding.encode(ze.getName());
+ entryEncoding = zipEncoding;
}
+
+ ByteBuffer name = entryEncoding.encode(ze.getName());
+
writeOut(ZipShort.getBytes(name.limit()));
written += SHORT;
@@ -798,12 +806,9 @@
if (comm == null) {
comm = "";
}
- ByteBuffer commentB;
- if (!encodable && fallbackToUTF8) {
- commentB = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(comm);
- } else {
- commentB = zipEncoding.encode(comm);
- }
+
+ ByteBuffer commentB = entryEncoding.encode(comm);
+
writeOut(ZipShort.getBytes(commentB.limit()));
written += SHORT;