/** * Creates a new LZF decoder with specified decoding instance. * * @param safeInstance * If {@code true} decoder will use {@link ChunkDecoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise decoder will try to use highly optimized {@link ChunkDecoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). */ public LzfDecoder(boolean safeInstance) { decoder = safeInstance ? ChunkDecoderFactory.safeInstance() : ChunkDecoderFactory.optimalInstance(); recycler = BufferRecycler.instance(); }
/** * Creates a new LZF encoder with specified settings. * * @param safeInstance * If {@code true} encoder will use {@link ChunkEncoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise encoder will try to use highly optimized {@link ChunkEncoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). * @param totalLength * Expected total length of content to compress; only matters for outgoing messages that is smaller * than maximum chunk size (64k), to optimize encoding hash tables. */ public LzfEncoder(boolean safeInstance, int totalLength) { super(false); if (totalLength < MIN_BLOCK_TO_COMPRESS || totalLength > MAX_CHUNK_LEN) { throw new IllegalArgumentException("totalLength: " + totalLength + " (expected: " + MIN_BLOCK_TO_COMPRESS + '-' + MAX_CHUNK_LEN + ')'); } encoder = safeInstance ? ChunkEncoderFactory.safeNonAllocatingInstance(totalLength) : ChunkEncoderFactory.optimalNonAllocatingInstance(totalLength); recycler = BufferRecycler.instance(); }
/** * Creates a new LZF decoder with specified decoding instance. * * @param safeInstance * If {@code true} decoder will use {@link ChunkDecoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise decoder will try to use highly optimized {@link ChunkDecoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). */ public LzfDecoder(boolean safeInstance) { decoder = safeInstance ? ChunkDecoderFactory.safeInstance() : ChunkDecoderFactory.optimalInstance(); recycler = BufferRecycler.instance(); }
/** * Creates a new LZF encoder with specified settings. * * @param safeInstance * If {@code true} encoder will use {@link ChunkEncoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise encoder will try to use highly optimized {@link ChunkEncoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). * @param totalLength * Expected total length of content to compress; only matters for outgoing messages that is smaller * than maximum chunk size (64k), to optimize encoding hash tables. */ public LzfEncoder(boolean safeInstance, int totalLength) { super(false); if (totalLength < MIN_BLOCK_TO_COMPRESS || totalLength > MAX_CHUNK_LEN) { throw new IllegalArgumentException("totalLength: " + totalLength + " (expected: " + MIN_BLOCK_TO_COMPRESS + '-' + MAX_CHUNK_LEN + ')'); } encoder = safeInstance ? ChunkEncoderFactory.safeNonAllocatingInstance(totalLength) : ChunkEncoderFactory.optimalNonAllocatingInstance(totalLength); recycler = BufferRecycler.instance(); }
/** * Creates a new LZF decoder with specified decoding instance. * * @param safeInstance * If {@code true} decoder will use {@link ChunkDecoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise decoder will try to use highly optimized {@link ChunkDecoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). */ public LzfDecoder(boolean safeInstance) { decoder = safeInstance ? ChunkDecoderFactory.safeInstance() : ChunkDecoderFactory.optimalInstance(); recycler = BufferRecycler.instance(); }
/** * Creates a new LZF encoder with specified settings. * * @param safeInstance * If {@code true} encoder will use {@link ChunkEncoder} that only uses standard JDK access methods, * and should work on all Java platforms and JVMs. * Otherwise encoder will try to use highly optimized {@link ChunkEncoder} implementation that uses * Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well). * @param totalLength * Expected total length of content to compress; only matters for outgoing messages that is smaller * than maximum chunk size (64k), to optimize encoding hash tables. */ public LzfEncoder(boolean safeInstance, int totalLength) { super(false); if (totalLength < MIN_BLOCK_TO_COMPRESS || totalLength > MAX_CHUNK_LEN) { throw new IllegalArgumentException("totalLength: " + totalLength + " (expected: " + MIN_BLOCK_TO_COMPRESS + '-' + MAX_CHUNK_LEN + ')'); } encoder = safeInstance ? ChunkEncoderFactory.safeNonAllocatingInstance(totalLength) : ChunkEncoderFactory.optimalNonAllocatingInstance(totalLength); recycler = BufferRecycler.instance(); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in) throws IOException { this(decoder, in, BufferRecycler.instance(), false); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in, boolean fullReads) throws IOException { this(decoder, in, BufferRecycler.instance(), fullReads); }
/** * Alternate constructor used when we want to avoid allocation encoding * buffer, in cases where caller wants full control over allocations. */ protected ChunkEncoder(int totalLength, boolean bogus) { this(totalLength, BufferRecycler.instance(), bogus); }
/** * Uses a ThreadLocal soft-referenced BufferRecycler instance. * * @param totalLength Total encoded length; used for calculating size * of hash table to use */ protected ChunkEncoder(int totalLength) { this(totalLength, BufferRecycler.instance()); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in) throws IOException { this(decoder, in, BufferRecycler.instance(), false); }
/** * Uses a ThreadLocal soft-referenced BufferRecycler instance. * * @param totalLength Total encoded length; used for calculating size * of hash table to use */ protected ChunkEncoder(int totalLength) { this(totalLength, BufferRecycler.instance()); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in, boolean fullReads) throws IOException { this(decoder, in, BufferRecycler.instance(), fullReads); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in) throws IOException { this(decoder, in, BufferRecycler.instance(), false); }
/** * Alternate constructor used when we want to avoid allocation encoding * buffer, in cases where caller wants full control over allocations. */ protected ChunkEncoder(int totalLength, boolean bogus) { this(totalLength, BufferRecycler.instance(), bogus); }
public LZFInputStream(final ChunkDecoder decoder, final InputStream in, boolean fullReads) throws IOException { this(decoder, in, BufferRecycler.instance(), fullReads); }
public LZFCompressingInputStream(InputStream in) { this(null, in, BufferRecycler.instance()); }
public LZFCompressingInputStream(final ChunkEncoder encoder, InputStream in, BufferRecycler bufferRecycler) { // may be passed by caller, or could be null _encoder = encoder; _inputStream = in; if (bufferRecycler==null) { bufferRecycler = (encoder!=null) ? _encoder._recycler : BufferRecycler.instance(); } _recycler = bufferRecycler; _inputBuffer = bufferRecycler.allocInputBuffer(LZFChunk.MAX_CHUNK_LEN); // let's not yet allocate encoding buffer; don't know optimal size }
/** * @param in Underlying input stream to use * @param fullReads Whether {@link #read(byte[])} should try to read exactly * as many bytes as requested (true); or just however many happen to be * available (false) */ public LZFInputStream(final InputStream in, boolean fullReads) throws IOException { this(ChunkDecoderFactory.optimalInstance(), in, BufferRecycler.instance(), fullReads); }
public LZFCompressedStreamInput(StreamInput in, ChunkDecoder decoder) throws IOException { super(in); this.recycler = BufferRecycler.instance(); this.decoder = decoder; this.uncompressed = recycler.allocDecodeBuffer(LZFChunk.MAX_CHUNK_LEN); this.inputBuffer = recycler.allocInputBuffer(LZFChunk.MAX_CHUNK_LEN); }