public IntelDeflaterFactory(File tmpDir) { intelDeflaterSupported = new IntelDeflater().load(tmpDir); }
/** * Compresses the input data and fills specified buffer with compressed * data. Returns actual number of bytes of compressed data. A return value * of 0 indicates that {@link #needsInput() needsInput} should be called * in order to determine if more input data is required. * * @param b the buffer for the compressed data * @param off the start offset of the data * @param len the maximum number of bytes of compressed data * @return the actual number of bytes of compressed data written to the * output buffer */ public int deflate(byte[] b, int off, int len ) { return deflateNative(b, len); }
/** * Closes the compressor and discards any unprocessed input. * This method should be called when the compressor is no longer * being used, but will also be called automatically by the * finalize() method. Once this method is called, the behavior * of the IntelDeflater object is undefined. */ @Override public void end() { endNative(); }
public boolean load() { return load(null); }
/** * Returns an IntelDeflater if supported on the platform, otherwise returns a Java Deflater * * @param compressionLevel the compression level (0-9) * @param gzipCompatible if true the use GZIP compatible compression * @return a Deflater object */ public Deflater makeDeflater(final int compressionLevel, final boolean gzipCompatible) { if (intelDeflaterSupported) { if ((compressionLevel == 1 && gzipCompatible) || compressionLevel != 1) { return new IntelDeflater(compressionLevel, gzipCompatible); } } logger.warn("IntelDeflater is not supported, using Java.util.zip.Deflater"); return new Deflater(compressionLevel, gzipCompatible); }
@Override public void reset() { resetNative(nowrap); inputBuffer = null; inputBufferLength = 0; endOfStream = false; finished = false; }
public boolean load(File tmpDir) { isSupported = IntelGKLUtils.load(tmpDir); if (isSupported) { initNative(); } return isSupported; }
/** * Closes the compressor when garbage is collected. */ protected void finalize() { end(); } }
/** * Sets input data for compression. This should be called whenever * needsInput() returns true indicating that more input data is required. * @param b the input data bytes * @param off the start offset of the data * @param len the length of the data * @see IntelDeflater */ @Override public void setInput(byte[] b, int off, int len) throws NullPointerException { if(lz_stream == 0) reset(); if(b == null) { throw new NullPointerException("Input is null"); } if(len <= 0) { throw new NullPointerException("Input buffer length is zero."); } inputBuffer = b; inputBufferLength = len; }
public void reset() { logger.debug("Reset deflater"); resetNative(nowrap); inputBuffer = null; inputBufferLength = 0; endOfStream = false; finished = false; }
/** * Loads the native library, if it is supported on this platform. <p> * Returns false if AVX is not supported. <br> * Returns false if the native library cannot be loaded for any reason. <br> * Initializes the native library after the first load. <br> * * @param tempDir directory where the native library is extracted or null to use the system temp directory * @return true if the native library is supported and loaded, false otherwise */ @Override public synchronized boolean load(File tempDir) { if (!NativeLibraryLoader.load(tempDir, NATIVE_LIBRARY_NAME)) { return false; } if (!initialized) { initNative(); initialized = true; } return true; }
public Deflater makeDeflater(final int compressionLevel, final boolean nowrap) { boolean intelDeflaterSupported = new IntelDeflater().load(tmpDir); if (intelDeflaterSupported) { if ((compressionLevel == 1 && nowrap) || compressionLevel != 1) { usingIntelDeflater = true; return new IntelDeflater(compressionLevel, nowrap); } } logger.warn("IntelDeflater is not supported, using Java.util.zip.Deflater"); usingIntelDeflater = false; return new Deflater(compressionLevel, nowrap); }
/** * Closes the compressor and discards any unprocessed input. * This method should be called when the compressor is no longer * being used, but will also be called automatically by the * finalize() method. Once this method is called, the behavior * of the IntelDeflater object is undefined. */ @Override public void end() { if(lz_stream != 0) { endNative(); lz_stream = 0; } } }
/** * Compresses the input data and fills specified buffer with compressed * data. Returns actual number of bytes of compressed data. A return value * of 0 indicates that {@link #needsInput() needsInput} should be called * in order to determine if more input data is required. * * @param b the buffer for the compressed data * @param off the start offset of the data * @param len the maximum number of bytes of compressed data * @return the actual number of bytes of compressed data written to the * output buffer */ @Override public int deflate(byte[] b, int off, int len ) { return deflateNative(b, len); }
@Test public void testIntelDeflaterIsAvailable() { checkIntelSupported("IntelDeflater"); Assert.assertTrue(new IntelDeflater().load(null), "Intel shared library was not loaded. This could be due to a configuration error, or your system might not support it."); }