Package com.github.luben.zstd
Class ZstdOutputStreamNoFinalizer
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.github.luben.zstd.ZstdOutputStreamNoFinalizer
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class ZstdOutputStreamNoFinalizer extends java.io.FilterOutputStreamOutputStream filter that compresses the data using Zstd compression.
-
-
Field Summary
Fields Modifier and Type Field Description private BufferPoolbufferPoolprivate booleancloseFrameOnFlushprivate byte[]dstprivate java.nio.ByteBufferdstByteBufferprivate longdstPosprivate static intdstSizeprivate booleanframeClosedprivate booleanisClosedprivate longsrcPosprivate longstream
-
Constructor Summary
Constructors Constructor Description ZstdOutputStreamNoFinalizer(java.io.OutputStream outStream)create a new compressing OutputStreamZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, int level)create a new compressing OutputStreamZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, BufferPool bufferPool)create a new compressing OutputStreamZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, BufferPool bufferPool, int level)create a new compressing OutputStream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private voidclose(boolean closeParentStream)voidcloseWithoutClosingParentStream()private intcompressStream(long ctx, byte[] dst, int dst_size, byte[] src, int src_size)private static longcreateCStream()private intendStream(long ctx, byte[] dst, int dst_size)voidflush()Flushes the outputprivate intflushStream(long ctx, byte[] dst, int dst_size)private static intfreeCStream(long ctx)static longrecommendedCOutSize()private intresetCStream(long ctx)ZstdOutputStreamNoFinalizersetChecksum(boolean useChecksums)Enable checksums for the compressed stream.ZstdOutputStreamNoFinalizersetCloseFrameOnFlush(boolean closeOnFlush)Enable closing the frame on flush.ZstdOutputStreamNoFinalizersetDict(byte[] dict)ZstdOutputStreamNoFinalizersetDict(ZstdDictCompress dict)ZstdOutputStreamNoFinalizersetLevel(int level)Set the compression level.ZstdOutputStreamNoFinalizersetLong(int windowLog)Enable Long Distance Matching and set the Window size Log.ZstdOutputStreamNoFinalizersetWorkers(int n)Enable use of worker threads for parallel compression.voidwrite(byte[] src, int offset, int len)voidwrite(int i)
-
-
-
Field Detail
-
stream
private final long stream
-
srcPos
private long srcPos
-
dstPos
private long dstPos
-
bufferPool
private final BufferPool bufferPool
-
dstByteBuffer
private final java.nio.ByteBuffer dstByteBuffer
-
dst
private final byte[] dst
-
isClosed
private boolean isClosed
-
dstSize
private static final int dstSize
-
closeFrameOnFlush
private boolean closeFrameOnFlush
-
frameClosed
private boolean frameClosed
-
-
Constructor Detail
-
ZstdOutputStreamNoFinalizer
public ZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, int level) throws java.io.IOExceptioncreate a new compressing OutputStream- Parameters:
outStream- the stream to wraplevel- the compression level- Throws:
java.io.IOException
-
ZstdOutputStreamNoFinalizer
public ZstdOutputStreamNoFinalizer(java.io.OutputStream outStream) throws java.io.IOExceptioncreate a new compressing OutputStream- Parameters:
outStream- the stream to wrap- Throws:
java.io.IOException
-
ZstdOutputStreamNoFinalizer
public ZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, BufferPool bufferPool, int level) throws java.io.IOExceptioncreate a new compressing OutputStream- Parameters:
outStream- the stream to wrapbufferPool- the pool to fetch and return buffers- Throws:
java.io.IOException
-
ZstdOutputStreamNoFinalizer
public ZstdOutputStreamNoFinalizer(java.io.OutputStream outStream, BufferPool bufferPool) throws java.io.IOExceptioncreate a new compressing OutputStream- Parameters:
outStream- the stream to wrapbufferPool- the pool to fetch and return buffers- Throws:
java.io.IOException
-
-
Method Detail
-
recommendedCOutSize
public static long recommendedCOutSize()
-
createCStream
private static long createCStream()
-
freeCStream
private static int freeCStream(long ctx)
-
resetCStream
private int resetCStream(long ctx)
-
compressStream
private int compressStream(long ctx, byte[] dst, int dst_size, byte[] src, int src_size)
-
flushStream
private int flushStream(long ctx, byte[] dst, int dst_size)
-
endStream
private int endStream(long ctx, byte[] dst, int dst_size)
-
setChecksum
public ZstdOutputStreamNoFinalizer setChecksum(boolean useChecksums) throws java.io.IOException
Enable checksums for the compressed stream. Default: false- Throws:
java.io.IOException
-
setLevel
public ZstdOutputStreamNoFinalizer setLevel(int level) throws java.io.IOException
Set the compression level. Default:Zstd.defaultCompressionLevel()- Throws:
java.io.IOException
-
setLong
public ZstdOutputStreamNoFinalizer setLong(int windowLog) throws java.io.IOException
Enable Long Distance Matching and set the Window size Log. Values for windowLog outside the range 10-27 will disable and reset LDM- Throws:
java.io.IOException
-
setWorkers
public ZstdOutputStreamNoFinalizer setWorkers(int n) throws java.io.IOException
Enable use of worker threads for parallel compression. Default: no worker threads.- Throws:
java.io.IOException
-
setCloseFrameOnFlush
public ZstdOutputStreamNoFinalizer setCloseFrameOnFlush(boolean closeOnFlush)
Enable closing the frame on flush. This will guarantee that it can be ready fully if the process crashes before closing the stream. On the downside it will negatively affect the compression ratio. Default: false.
-
setDict
public ZstdOutputStreamNoFinalizer setDict(byte[] dict) throws java.io.IOException
- Throws:
java.io.IOException
-
setDict
public ZstdOutputStreamNoFinalizer setDict(ZstdDictCompress dict) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(byte[] src, int offset, int len) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(int i) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionFlushes the output- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
closeWithoutClosingParentStream
public void closeWithoutClosingParentStream() throws java.io.IOException- Throws:
java.io.IOException
-
close
private void close(boolean closeParentStream) throws java.io.IOException- Throws:
java.io.IOException
-
-