Search in sources :

Example 6 with SnappyInputStream

use of org.xerial.snappy.SnappyInputStream in project zookeeper by apache.

the class SnapStream method getInputStream.

/**
 * Return the CheckedInputStream based on the extension of the fileName.
 *
 * @param file the file the InputStream read from
 * @return the specific InputStream
 * @throws IOException
 */
public static CheckedInputStream getInputStream(File file) throws IOException {
    FileInputStream fis = new FileInputStream(file);
    InputStream is;
    try {
        switch(getStreamMode(file.getName())) {
            case GZIP:
                is = new GZIPInputStream(fis);
                break;
            case SNAPPY:
                is = new SnappyInputStream(fis);
                break;
            case CHECKED:
            default:
                is = new BufferedInputStream(fis);
        }
        return new CheckedInputStream(is, new Adler32());
    } catch (IOException e) {
        fis.close();
        throw e;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) SnappyInputStream(org.xerial.snappy.SnappyInputStream) BufferedInputStream(java.io.BufferedInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) SnappyInputStream(org.xerial.snappy.SnappyInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CheckedInputStream(java.util.zip.CheckedInputStream) Adler32(java.util.zip.Adler32)

Example 7 with SnappyInputStream

use of org.xerial.snappy.SnappyInputStream in project nimbus by nimbus-org.

the class SerializableExternalizerService method readExternal.

public Object readExternal(InputStream in) throws IOException, ClassNotFoundException {
    if (isBufferedInputStream) {
        in = new BufferedInputStream(in, inputStreamInitialBufferSize);
    }
    if (compressMode != COMPRESS_MODE_NONE && compressThreshold == -1) {
        InputStream is = null;
        Inflater inflater = null;
        switch(compressMode) {
            case COMPRESS_MODE_ZLIB:
                inflater = new Inflater();
                is = bufferSize > 0 ? new InflaterInputStream(in, inflater, bufferSize) : new InflaterInputStream(in);
                break;
            case COMPRESS_MODE_ZIP:
                is = new ZipInputStream(in);
                ((ZipInputStream) is).getNextEntry();
                break;
            case COMPRESS_MODE_GZIP:
                is = bufferSize > 0 ? new GZIPInputStream(in, bufferSize) : new GZIPInputStream(in);
                break;
            case COMPRESS_MODE_SNAPPY:
                is = new SnappyInputStream(in);
                break;
            case COMPRESS_MODE_LZ4:
                is = new LZ4BlockInputStream(in);
                break;
            default:
                throw new IOException("Unknown compress mode : " + compressMode);
        }
        final ObjectInput oi = createObjectInput(is);
        try {
            return readInternal(oi);
        } finally {
            if (inflater != null) {
                inflater.end();
            }
        }
    } else {
        ObjectInput input = createObjectInput(in);
        return readExternal(input);
    }
}
Also used : SnappyInputStream(org.xerial.snappy.SnappyInputStream) SnappyInputStream(org.xerial.snappy.SnappyInputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream)

Example 8 with SnappyInputStream

use of org.xerial.snappy.SnappyInputStream in project pentaho-kettle by pentaho.

the class SnappyCompressionInputStreamTest method createSnappyInputStream.

private SnappyInputStream createSnappyInputStream() throws IOException {
    // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SnappyOutputStream sos = new SnappyOutputStream(baos);
    byte[] testBytes = "Test".getBytes();
    sos.write(testBytes);
    ByteArrayInputStream in = new ByteArrayInputStream(baos.toByteArray());
    sos.close();
    return new SnappyInputStream(in);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SnappyInputStream(org.xerial.snappy.SnappyInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SnappyOutputStream(org.xerial.snappy.SnappyOutputStream)

Example 9 with SnappyInputStream

use of org.xerial.snappy.SnappyInputStream in project pentaho-kettle by pentaho.

the class SnappyCompressionProviderTest method testCreateInputStream.

@Test
public void testCreateInputStream() throws IOException {
    SnappyCompressionProvider provider = (SnappyCompressionProvider) factory.getCompressionProviderByName(PROVIDER_NAME);
    SnappyInputStream in = createSnappyInputStream();
    SnappyCompressionInputStream inStream = new SnappyCompressionInputStream(in, provider);
    assertNotNull(inStream);
    SnappyCompressionInputStream ncis = provider.createInputStream(in);
    assertNotNull(ncis);
}
Also used : SnappyInputStream(org.xerial.snappy.SnappyInputStream) Test(org.junit.Test)

Example 10 with SnappyInputStream

use of org.xerial.snappy.SnappyInputStream in project pentaho-kettle by pentaho.

the class SnappyCompressionProviderTest method createSnappyInputStream.

private SnappyInputStream createSnappyInputStream() throws IOException {
    // Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SnappyOutputStream sos = new SnappyOutputStream(baos);
    byte[] testBytes = "Test".getBytes();
    sos.write(testBytes);
    ByteArrayInputStream in = new ByteArrayInputStream(baos.toByteArray());
    sos.close();
    return new SnappyInputStream(in);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SnappyInputStream(org.xerial.snappy.SnappyInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SnappyOutputStream(org.xerial.snappy.SnappyOutputStream)

Aggregations

SnappyInputStream (org.xerial.snappy.SnappyInputStream)10 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 SnappyOutputStream (org.xerial.snappy.SnappyOutputStream)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)2 OutputStream (java.io.OutputStream)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Adler32 (java.util.zip.Adler32)1 CheckedInputStream (java.util.zip.CheckedInputStream)1 Decoder (lzma.sdk.lzma.Decoder)1 LzmaInputStream (lzma.streams.LzmaInputStream)1 LzmaOutputStream (lzma.streams.LzmaOutputStream)1 CompressorStreamFactory (org.apache.commons.compress.compressors.CompressorStreamFactory)1