Package com.github.luben.zstd
Class ZstdOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.github.luben.zstd.ZstdOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class ZstdOutputStream extends java.io.FilterOutputStream
OutputStream filter that compresses the data using Zstd compression
-
-
Field Summary
Fields Modifier and Type Field Description private ZstdOutputStreamNoFinalizer
inner
-
Constructor Summary
Constructors Constructor Description ZstdOutputStream(java.io.OutputStream outStream)
create a new compressing OutputStreamZstdOutputStream(java.io.OutputStream outStream, int level)
create a new compressing OutputStreamZstdOutputStream(java.io.OutputStream outStream, int level, boolean closeFrameOnFlush)
Deprecated.Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the settersZstdOutputStream(java.io.OutputStream outStream, int level, boolean closeFrameOnFlush, boolean useChecksums)
Deprecated.Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the settersZstdOutputStream(java.io.OutputStream outStream, BufferPool bufferPool)
create a new compressing OutputStreamZstdOutputStream(java.io.OutputStream outStream, BufferPool bufferPool, int level)
create a new compressing OutputStream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
protected void
finalize()
void
flush()
Flushes the outputstatic long
recommendedCOutSize()
ZstdOutputStream
setChecksum(boolean useChecksums)
Enable checksums for the compressed stream.ZstdOutputStream
setCloseFrameOnFlush(boolean closeOnFlush)
Enable closing the frame on flush.ZstdOutputStream
setDict(byte[] dict)
ZstdOutputStream
setDict(ZstdDictCompress dict)
void
setFinalize(boolean finalize)
Deprecated.If you don't rely on finalizers, use `ZstdOutputStreamNoFinalizer` instead.ZstdOutputStream
setLevel(int level)
Set the compression level.ZstdOutputStream
setLong(int windowLog)
Set the Long Distance Matching.ZstdOutputStream
setWorkers(int n)
Enable use of worker threads for parallel compression.void
write(byte[] src, int offset, int len)
void
write(int i)
-
-
-
Field Detail
-
inner
private ZstdOutputStreamNoFinalizer inner
-
-
Constructor Detail
-
ZstdOutputStream
@Deprecated public ZstdOutputStream(java.io.OutputStream outStream, int level, boolean closeFrameOnFlush, boolean useChecksums) throws java.io.IOException
Deprecated.Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the setters- Throws:
java.io.IOException
-
ZstdOutputStream
@Deprecated public ZstdOutputStream(java.io.OutputStream outStream, int level, boolean closeFrameOnFlush) throws java.io.IOException
Deprecated.Use ZstdOutputStream() or ZstdOutputStream(level) and set the other params with the setters- Throws:
java.io.IOException
-
ZstdOutputStream
public ZstdOutputStream(java.io.OutputStream outStream, int level) throws java.io.IOException
create a new compressing OutputStream- Parameters:
outStream
- the stream to wraplevel
- the compression level- Throws:
java.io.IOException
-
ZstdOutputStream
public ZstdOutputStream(java.io.OutputStream outStream) throws java.io.IOException
create a new compressing OutputStream- Parameters:
outStream
- the stream to wrap- Throws:
java.io.IOException
-
ZstdOutputStream
public ZstdOutputStream(java.io.OutputStream outStream, BufferPool bufferPool, int level) throws java.io.IOException
create a new compressing OutputStream- Parameters:
outStream
- the stream to wrapbufferPool
- the pool to fetch and return buffers- Throws:
java.io.IOException
-
ZstdOutputStream
public ZstdOutputStream(java.io.OutputStream outStream, BufferPool bufferPool) throws java.io.IOException
create a new compressing OutputStream- Parameters:
outStream
- the stream to wrapbufferPool
- the pool to fetch and return buffers- Throws:
java.io.IOException
-
-
Method Detail
-
setFinalize
@Deprecated public void setFinalize(boolean finalize)
Deprecated.If you don't rely on finalizers, use `ZstdOutputStreamNoFinalizer` instead.Enable or disable class finalizers If finalizers are disabled the responsibility fir calling the `close` method is on the consumer.- Parameters:
finalize
- default `true` - finalizers are enabled
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
recommendedCOutSize
public static long recommendedCOutSize()
-
setChecksum
public ZstdOutputStream setChecksum(boolean useChecksums) throws java.io.IOException
Enable checksums for the compressed stream. Default: false- Throws:
java.io.IOException
-
setLevel
public ZstdOutputStream setLevel(int level) throws java.io.IOException
Set the compression level. Default:Zstd.defaultCompressionLevel()
- Throws:
java.io.IOException
-
setLong
public ZstdOutputStream setLong(int windowLog) throws java.io.IOException
Set the Long Distance Matching. Values for windowLog outside the range 10-27 will disable and reset LDM- Throws:
java.io.IOException
-
setWorkers
public ZstdOutputStream 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 ZstdOutputStream 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 ZstdOutputStream setDict(byte[] dict) throws java.io.IOException
- Throws:
java.io.IOException
-
setDict
public ZstdOutputStream 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:
write
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
write
public void write(int i) throws java.io.IOException
- Overrides:
write
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Flushes the output- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
-