/** * 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(); }
/** * Convenience method, equivalent to: *<code> * return optimalInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); *</code> */ public static ChunkEncoder optimalInstance(BufferRecycler bufferRecycler) { return optimalInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); }
/** * @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) * @param bufferRecycler Buffer recycler instance, for usages where the * caller manages the recycler instances */ public LZFInputStream(final InputStream in, final BufferRecycler bufferRecycler, boolean fullReads) throws IOException { this(ChunkDecoderFactory.optimalInstance(), in, bufferRecycler, fullReads); }
@Override public long skip(long n) throws IOException { return skipRaw(n); } }
/** * Convenience method, equivalent to: *<code> * return safeInstance(LZFChunk.MAX_CHUNK_LEN); *</code> */ public static ChunkEncoder safeInstance() { return safeInstance(LZFChunk.MAX_CHUNK_LEN); }
@Override public int read() throws IOException { if (!readyBuffer()) { return -1; } return _decodedBytes[_bufferPosition++] & 255; }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
@Override public void write(byte[] buffer, int offset, int length) throws IOException { rawWrite(buffer, offset, length); } }
/** * 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(); }
/** * Convenience method, equivalent to: *<code> * return optimalInstance(LZFChunk.MAX_CHUNK_LEN); *</code> */ public static ChunkEncoder optimalInstance() { return optimalInstance(LZFChunk.MAX_CHUNK_LEN); }
@Override public long skip(long n) throws IOException { return skipRaw(n); } }
/** * Convenience method, equivalent to: *<code> * return safeInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); *</code> */ public static ChunkEncoder safeInstance(BufferRecycler bufferRecycler) { return safeInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); } /**
@Override public int read() throws IOException { if (!readyBuffer()) { return -1; } return _decodedBytes[_bufferPosition++] & 255; }
/** * 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(); }
@Override protected ChunkEncoder initialValue() { return ChunkEncoderFactory.optimalInstance(); } };
/** * Convenience method, equivalent to: *<code> * return optimalInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); *</code> */ public static ChunkEncoder optimalInstance(BufferRecycler bufferRecycler) { return optimalInstance(LZFChunk.MAX_CHUNK_LEN, bufferRecycler); }