Skip to content

Instantly share code, notes, and snippets.

@alexproca
Last active January 4, 2016 13:49
Show Gist options
  • Save alexproca/8630158 to your computer and use it in GitHub Desktop.
Save alexproca/8630158 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipInputStream;
/**
* This class is a wrapper for ZipInputStream.
* If you try to put ZipInputStream in a InputStreamReader you will get
* an error because when close() is called the whole ZipInputStream will
* be closed. For reading only a part from the stream corresponding to a
* ZipEntry, instead of calling stream.close() you should call stream.closeEntry()
*
* @author Alex Proca
*
*/
public class ZipEntryInputStream extends InputStream {
private ZipInputStream stream;
public ZipInputStreamWrapper(ZipInputStream stream)
{
this.stream = stream;
}
public int read() throws IOException
{
return stream.read();
}
public void close() throws IOException
{
stream.closeEntry();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment