Package com.ning.compress.gzip

Examples of com.ning.compress.gzip.OptimizedGZIPInputStream


            case NONE:
                break;
            case LZF:
                return new LZFInputStream(in);
            case GZIP:
                return new OptimizedGZIPInputStream(in);
            default: // sanity check
                throw new IllegalArgumentException("Unrecognized compression type: "+comp);
            }
        }
        return in;
View Full Code Here


    {
        if (expSize <= 0) {
            return gzipUncompress(compData);
        }
        byte[] buffer = new byte[expSize];
        OptimizedGZIPInputStream in = new OptimizedGZIPInputStream(new ByteArrayInputStream(compData));
        int offset = 0;
        int left = buffer.length;
        int count;

        while (left > 0 && (count = in.read(buffer, offset, left)) > 0) {
            offset += count;
            left -= count;
        }
        // should have gotten exactly expected amount
        try {
            if (offset < expSize) {
                throw new IOException("Corrupt GZIP/Deflate data: expected "+expSize+" bytes, got "+offset);
            }
            // and no more
            if (in.read() != -1) {
                throw new IOException("Corrupt GZIP/Deflate data: expected "+expSize+" bytes, got at least one more");
            }
        } finally {
            try { in.close(); } catch (IOException e) { }
        }
        return buffer;
    }
View Full Code Here

    }

    public static byte[] gzipUncompress(byte[] compData)
        throws IOException
    {
        OptimizedGZIPInputStream in = new OptimizedGZIPInputStream(new ByteArrayInputStream(compData));
        ByteArrayOutputStream bytes = new ByteArrayOutputStream(16 + (compData.length << 1));
        byte[] buffer = new byte[500];
        int count;

        while ((count = in.read(buffer)) > 0) {
            bytes.write(buffer, 0, count);
        }
        in.close();
        bytes.close();
        return bytes.toByteArray();
    }
View Full Code Here

TOP

Related Classes of com.ning.compress.gzip.OptimizedGZIPInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.