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;
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations