Why ZipInputStream can't read the output of ZipOutputStream?

后端 未结 5 1930
夕颜
夕颜 2021-01-18 08:20

I\'m stuck with this junit test:

public void test() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipOutputStream zipOu         


        
5条回答
  •  执念已碎
    2021-01-18 08:54

    I found the answer by myself: entry does not contain the correct size, but with each zipIn.getNextEntry() you get a fresh stream to read the content of your entry from. So simply read the stream up to the end and you have the data of your entry.

    In my junit test the last line could look like this:

    byte[] restoredContent = new byte[ 10 ];
    assertEquals( 3, zipIn.read( restoredContent ) );
    

    Now everything works fine.

提交回复
热议问题