Java Utililty Methods Unzip InputStream

List of utility methods to do Unzip InputStream

Description

The list of methods to do Unzip InputStream are organized into topic(s).

Method

ByteArrayInputStreamdecompress(ByteArrayInputStream xzStream)
Compression temporarily disabled due to problems on full hd devices. Decompress a previously compressed Xz stream
ByteArrayInputStream xzInputStream = xzStream;
byte firstByte = (byte) xzInputStream.read();
byte[] buffer = new byte[xzInputStream.available()];
buffer[0] = firstByte;
xzInputStream.read(buffer, 1, buffer.length - 2);
xzInputStream.close();
return new ByteArrayInputStream(buffer);
voiddecompress(final int type, final InputStream is, final OutputStream os)
Decompress stream from different formats
switch (type) {
case COMPRESSION_GZIP: {
    GZIPInputStream gzipped = new GZIPInputStream(is);
    try {
        write(gzipped, os);
    } finally {
        closeQuietly(gzipped);
case COMPRESSION_DEFLATE: {
    InflaterOutputStream inflated = new InflaterOutputStream(os, new Inflater(false));
    try {
        write(is, inflated);
        inflated.flush();
    } finally {
        closeQuietly(inflated);
case COMPRESSION_ZIP: {
    ZipInputStream zipped = new ZipInputStream(is);
    try {
        write(zipped, os);
    } finally {
        closeQuietly(zipped);
default:
    throw new NoSuchMethodException();
voiddecompress(InputStream input, File destDir)
decompress
ZipInputStream zin = new ZipInputStream(input);
ZipEntry entry = null;
byte[] buffer = new byte[1024];
while ((entry = zin.getNextEntry()) != null) {
    File f = new File(destDir, entry.getName());
    if (entry.isDirectory()) {
        f.mkdirs();
        continue;
...
InputStreamdecompress(InputStream inputStream)
decompress
inputStream = new BufferedInputStream(inputStream);
inputStream.mark(1024);
try {
    inputStream = new GZIPInputStream(inputStream);
} catch (IOException e) {
    inputStream.reset();
return inputStream;
...
voiddecompress(InputStream is, OutputStream os)
decompress
InflaterInputStream gis = new InflaterInputStream(is);
int count;
byte data[] = new byte[BUFFER];
while ((count = gis.read(data, 0, BUFFER)) != -1) {
    os.write(data, 0, count);
gis.close();
voiddecompressFile(InputStream is, OutputStream os)
decompress File
InflaterInputStream iis = new InflaterInputStream(is);
try {
    int i = 1024;
    byte[] buf = new byte[i];
    while ((i = iis.read(buf, 0, i)) > 0) {
        os.write(buf, 0, i);
} catch (IOException e) {
...
InputStreamdecompressStream(InputStream input)
decompress Stream
PushbackInputStream pb = new PushbackInputStream(input, 2); 
byte[] signature = new byte[2];
try {
    pb.read(signature); 
    pb.unread(signature); 
} catch (Exception e) {
if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) 
...
voiddecompressZipArchive(final File zipFile, final File rootDirectoryToUnZip)
Takes a zip file and decompress it to the given root directory.
final int BUFFER = 2048;
if (rootDirectoryToUnZip.exists() && rootDirectoryToUnZip.isFile()) {
    throw new IllegalArgumentException("Passed argument points to an existing file not a directory.");
if (!rootDirectoryToUnZip.exists()) {
    rootDirectoryToUnZip.mkdir();
final FileInputStream fis = new FileInputStream(zipFile);
...
voidunzip(InputStream from, String to, String pattern)
unzip
if (from == null || to == null)
    return;
try {
    ZipInputStream zs = new ZipInputStream(from);
    ZipEntry ze;
    while ((ze = zs.getNextEntry()) != null) {
        String fname = to + '/' + ze.getName();
        boolean match = (pattern == null || ze.getName().matches(pattern));
...
byte[]unzip(InputStream in)
unzip
GZIPInputStream gin = new GZIPInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = gin.read(buf)) > 0) {
    out.write(buf, 0, len);
gin.close();
...