/** * Return the fastest available {@link LZ4Factory} instance which does not * rely on JNI bindings. It first tries to load the * {@link #unsafeInstance() unsafe instance}, and then the * {@link #safeInstance() safe Java instance} if the JVM doesn't have a * working {@link sun.misc.Unsafe}. */ public static LZ4Factory fastestJavaInstance() { if (Utils.isUnalignedAccessAllowed()) { try { return unsafeInstance(); } catch (Throwable t) { return safeInstance(); } } else { return safeInstance(); } }
/** * Return the fastest available {@link LZ4Factory} instance which does not * rely on JNI bindings. It first tries to load the * {@link #unsafeInstance() unsafe instance}, and then the * {@link #safeInstance() safe Java instance} if the JVM doesn't have a * working {@link sun.misc.Unsafe}. */ public static LZ4Factory fastestJavaInstance() { if (Utils.isUnalignedAccessAllowed()) { try { return unsafeInstance(); } catch (Throwable t) { return safeInstance(); } } else { return safeInstance(); } }
public static void encode(File file, File outputFile) { try { byte[] data= Files.readAllBytes(file.toPath()); LZ4Factory factory= LZ4Factory.safeInstance(); LZ4Compressor compressor= factory.highCompressor(9); FileOutputStream fos= new FileOutputStream(outputFile); byte[] result= compressor.compress(data); writeIntLE(data.length, fos); fos.write(result); fos.close(); } catch (Exception e) { throw new RuntimeException(e); } } }
LZ4FastDecompressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().fastDecompressor();
LZ4SafeDecompressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().safeDecompressor();
LZ4Compressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().fastCompressor();
LZ4Compressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().highCompressor(compressionLevel);
LZ4Compressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().fastCompressor();
LZ4FastDecompressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().fastDecompressor();
LZ4SafeDecompressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().safeDecompressor();
LZ4Compressor safeInstance = SAFE_INSTANCE; if (safeInstance == null) { safeInstance = SAFE_INSTANCE = LZ4Factory.safeInstance().highCompressor(compressionLevel);
}); LZ4Compressor safeCompressor = LZ4Factory.safeInstance().fastCompressor(); benchmarkFunction("LZ4 (Safe)", set.length, () -> { return benchMarkLZ4(safeCompressor, set);