Reading from a ZipInputStream into a ByteArrayOutputStream

后端 未结 10 1546
旧时难觅i
旧时难觅i 2021-02-05 08:14

I am trying to read a single file from a java.util.zip.ZipInputStream, and copy it into a java.io.ByteArrayOutputStream (so that I can then create a

10条回答
  •  面向向阳花
    2021-02-05 08:36

    You could implement your own wrapper around the ZipInputStream that ignores close() and hand that off to the third-party library.

    thirdPartyLib.handleZipData(new CloseIgnoringInputStream(zipStream));
    
    
    class CloseIgnoringInputStream extends InputStream
    {
        private ZipInputStream stream;
    
        public CloseIgnoringInputStream(ZipInputStream inStream)
        {
            stream = inStream;
        }
    
        public int read() throws IOException {
            return stream.read();
        }
    
        public void close()
        {
            //ignore
        }
    
        public void reallyClose() throws IOException
        {
            stream.close();
        }
    }
    

提交回复
热议问题