I'm stuck with this junit test:
public void test() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream( out );
zipOut.putNextEntry( new ZipEntry( "file" ) );
zipOut.write( (new byte[] { 0x01, 0x02, 0x03 }) );
zipOut.closeEntry();
zipOut.close();
ZipInputStream zipIn = new ZipInputStream( new ByteArrayInputStream( out.toByteArray() ) );
ZipEntry entry = zipIn.getNextEntry();
assertNotNull( entry );
assertEquals( "file", entry.getName() );
assertEquals( 3, entry.getSize() );
}
I'm writing a file with the name "file" and a content of three bytes to a ZipOutputStream. Then I try to read the created data with a ZipInputStream, but the last assert fails, because entry.getSize()
is -1
and not 3
, as expected.
What am I doing wrong here? What do I have to change to restore the content of "file"? I think, I first have to know the length to be able to read the data from the stream?