List of usage examples for org.apache.hadoop.io.compress SnappyCodec createInputStream
@Override public CompressionInputStream createInputStream(InputStream in) throws IOException
From source file:org.apache.ignite.internal.processors.hadoop.HadoopSnappyTest.java
License:Apache License
/** * Internal check routine.//from www . j av a 2 s.c o m * * @throws Throwable If failed. */ public static void checkSnappy() throws Throwable { try { byte[] expBytes = new byte[BYTE_SIZE]; byte[] actualBytes = new byte[BYTE_SIZE]; for (int i = 0; i < expBytes.length; i++) expBytes[i] = (byte) ThreadLocalRandom.current().nextInt(16); SnappyCodec codec = new SnappyCodec(); codec.setConf(new Configuration()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (CompressionOutputStream cos = codec.createOutputStream(baos)) { cos.write(expBytes); cos.flush(); } try (CompressionInputStream cis = codec .createInputStream(new ByteArrayInputStream(baos.toByteArray()))) { int read = cis.read(actualBytes, 0, actualBytes.length); assert read == actualBytes.length; } assert Arrays.equals(expBytes, actualBytes); } catch (Throwable e) { System.out.println("Snappy check failed:"); System.out .println("### NativeCodeLoader.isNativeCodeLoaded: " + NativeCodeLoader.isNativeCodeLoaded()); System.out .println("### SnappyCompressor.isNativeCodeLoaded: " + SnappyCompressor.isNativeCodeLoaded()); throw e; } }
From source file:org.pentaho.hadoop.shim.common.CommonSnappyShim.java
License:Apache License
/** * Gets an InputStream that uses the snappy codec and wraps the supplied base input stream. * * @param the buffer size for the codec to use (in bytes) * @param in the base input stream to wrap around * @return an InputStream that uses the Snappy codec * @throws Exception if snappy is not available or an error occurs during reflection */// w w w.ja v a 2 s . co m public InputStream getSnappyInputStream(int bufferSize, InputStream in) throws Exception { if (!isHadoopSnappyAvailable()) { throw new Exception("Hadoop-snappy does not seem to be available"); } ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { SnappyCodec c = new SnappyCodec(); Configuration newConf = new Configuration(); newConf.set(IO_COMPRESSION_CODEC_SNAPPY_BUFFERSIZE_KEY, "" + bufferSize); c.setConf(newConf); return c.createInputStream(in); } finally { Thread.currentThread().setContextClassLoader(cl); } }