I have a little question about stream size. Here's my try :
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ZipOutputStream zipStream = new ZipOutputStream(outStream);
zipStream.close();
outStream.close();
System.err.println(outStream.toByteArray().length);
The result length is always 22. Can you explain me why ? Thank you for your help.
Because a ZipOutputStream is writing the ZIP file format, and the ZIP file format contains metadata that will always be present, even in an empty zip file. Specifically, an empty zip only contains the End of Central Directory Record:
https://en.wikipedia.org/wiki/Zip_(file_format)#Limits
The minimum size of a .ZIP file is 22 bytes. Such empty zip file contains only an End of Central Directory Record (EOCD):
[0x50,0x4B,0x05,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With