[
https://issues.apache.org/jira/browse/COMPRESS-264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13906759#comment-13906759
]
Stefan Bodewig commented on COMPRESS-264:
-----------------------------------------
I haven't tested whether there actually is a bug - I will do so.
But from looking at your code you expect {{in.read()}} to read the entire
content without checking the return code (how many bytes have been read). If
you change the code to repeat reading until read returns -1 - for example using
{{IOUtils.readFully}} [1] - does it then still not read the full contents of
your entry?
[1]
http://commons.apache.org/proper/commons-compress/javadocs/api-1.7/org/apache/commons/compress/utils/IOUtils.html#readFully%28java.io.InputStream,%20byte[]%29
> ZIP reads correctly with commons-compress 1.6, gives NUL bytes in 1.7
> ---------------------------------------------------------------------
>
> Key: COMPRESS-264
> URL: https://issues.apache.org/jira/browse/COMPRESS-264
> Project: Commons Compress
> Issue Type: Bug
> Components: Archivers
> Affects Versions: 1.7
> Environment: Ubuntu precise
> Reporter: Jonathan Nieder
> Priority: Minor
>
> When running the code below, commons-compress 1.6 writes:
> Content of test.txt:
> data
> By comparison, commons-compress 1.7 writes
> Content of test.txt:
> ^@^@^@^@^@
> package com.example.jrn;
> import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
> import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
> import java.io.ByteArrayInputStream;
> import java.io.IOException;
> import java.lang.System;
> /**
> * Hello world!
> *
> */
> public class App {
> public static void main(String[] args) {
> byte[] zip = {
> (byte)0x50, (byte)0x4b, (byte)0x03, (byte)0x04, (byte)0x0a, (byte)0x00,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03, (byte)0x7b,
> (byte)0xd1, (byte)0x42, (byte)0x82, (byte)0xc5, (byte)0xc1, (byte)0xe6,
> (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x00,
> (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x1c, (byte)0x00,
> (byte)0x74, (byte)0x65, (byte)0x73, (byte)0x74, (byte)0x2e, (byte)0x74,
> (byte)0x78, (byte)0x74, (byte)0x55, (byte)0x54, (byte)0x09, (byte)0x00,
> (byte)0x03, (byte)0x56, (byte)0x62, (byte)0xbf, (byte)0x51, (byte)0x2a,
> (byte)0x63, (byte)0xbf, (byte)0x51, (byte)0x75, (byte)0x78, (byte)0x0b,
> (byte)0x00, (byte)0x01, (byte)0x04, (byte)0x01, (byte)0xff, (byte)0x01,
> (byte)0x00, (byte)0x04, (byte)0x88, (byte)0x13, (byte)0x00, (byte)0x00,
> (byte)0x64, (byte)0x61, (byte)0x74, (byte)0x61, (byte)0x0a, (byte)0x50,
> (byte)0x4b, (byte)0x01, (byte)0x02, (byte)0x1e, (byte)0x03, (byte)0x0a,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x03,
> (byte)0x7b, (byte)0xd1, (byte)0x42, (byte)0x82, (byte)0xc5, (byte)0xc1,
> (byte)0xe6, (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x18,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xa0, (byte)0x81, (byte)0x00,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x74, (byte)0x65, (byte)0x73,
> (byte)0x74, (byte)0x2e, (byte)0x74, (byte)0x78, (byte)0x74, (byte)0x55,
> (byte)0x54, (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x56, (byte)0x62,
> (byte)0xbf, (byte)0x51, (byte)0x75, (byte)0x78, (byte)0x0b, (byte)0x00,
> (byte)0x01, (byte)0x04, (byte)0x01, (byte)0xff, (byte)0x01, (byte)0x00,
> (byte)0x04, (byte)0x88, (byte)0x13, (byte)0x00, (byte)0x00, (byte)0x50,
> (byte)0x4b, (byte)0x05, (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x00,
> (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x4e,
> (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x47, (byte)0x00, (byte)0x00,
> (byte)0x00, (byte)0x00, (byte)00
> };
> ByteArrayInputStream bin = new ByteArrayInputStream(zip);
> try {
> ZipArchiveInputStream in = new ZipArchiveInputStream(bin);
> try {
> while (true) {
> ZipArchiveEntry entry = in.getNextZipEntry();
> if (entry == null) {
> break;
> }
> byte[] buf = new byte[(int) entry.getSize()];
> in.read(buf);
> System.out.println("Content of " + entry.getName() + ":");
> System.out.write(buf);
> }
> } finally {
> in.close();
> }
> } catch (IOException e) {
> System.err.println("IOException: " + e);
> }
> }
> }
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)