List of usage examples for org.apache.hadoop.io.compress.snappy SnappyCompressor isNativeCodeLoaded
public static boolean isNativeCodeLoaded()
From source file:org.apache.ignite.internal.processors.hadoop.HadoopSnappyTest.java
License:Apache License
/** * Internal check routine.//from w w w .j a va 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; } }