Stefan Bodewig schrieb:
> On 2009-03-04, Stefan Bodewig <[email protected]> wrote:
>
>> On 2009-03-03, Wolfgang Glas <[email protected]> wrote:
>
>>> The implementation should be be straightforward, shall I prepare a
>>> patch or can you afford doing it at your own?
>
>> Will do it myself.
>
> svn revisions 749906 and 749907
Hello Stefan reviewed you code and found out, that you did not strictly use the
same encoding for filenames and comments in one entry.
A patch, which corrects this behaviour is attached.
Regards,
Wolfgang
Index: src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
===================================================================
--- src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (Revision 750123)
+++ src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (Arbeitskopie)
@@ -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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]