Package org.apache.commons.compress
Class CompressFilterOutputStream<T extends java.io.OutputStream>
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.commons.compress.CompressFilterOutputStream<T>
-
- Type Parameters:
T- The underlyingOutputStreamtype.
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
ArchiveOutputStream,CompressorOutputStream
public abstract class CompressFilterOutputStream<T extends java.io.OutputStream> extends java.io.FilterOutputStream
Abstracts classes that compress or archive an output stream.- Since:
- 1.28.0
-
-
Constructor Summary
Constructors Constructor Description CompressFilterOutputStream()Constructs a new instance without a backingOutputStream.CompressFilterOutputStream(T out)Creates an output stream filter built on top of the specified underlyingOutputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckOpen()Check to make sure that this stream has not been closed.voidclose()voidfinish()Finishes the addition of entries to this stream, without closing it.booleanisClosed()Tests whether this instance was successfully closed.protected booleanisFinished()Tests whether this instance was successfully finished.protected Tout()Gets the underlying output stream.longwrite(java.io.File file)Writes all bytes from a file this output stream.longwrite(java.nio.file.Path path)Writes all bytes from a file to this output stream.byte[]writeUsAscii(java.lang.String data)Writes and filters the ASCII bytes from the specified String to this output stream.byte[]writeUsAsciiRaw(java.lang.String data)Writes the raw ASCII bytes from the specified String to this output stream.byte[]writeUtf8(java.lang.String data)Writes and filters the UTF-8 bytes from the specified String to this output stream.
-
-
-
Constructor Detail
-
CompressFilterOutputStream
public CompressFilterOutputStream()
Constructs a new instance without a backingOutputStream.You must initialize
this.outafter construction.
-
CompressFilterOutputStream
public CompressFilterOutputStream(T out)
Creates an output stream filter built on top of the specified underlyingOutputStream.- Parameters:
out- the underlying output stream to be assigned to the fieldthis.outfor later use, ornullif this instance is to be created without an underlying stream.
-
-
Method Detail
-
checkOpen
protected void checkOpen() throws java.io.IOException
Check to make sure that this stream has not been closed.- Throws:
java.io.IOException- if the stream is already closed.
-
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
-
finish
public void finish() throws java.io.IOException
Finishes the addition of entries to this stream, without closing it. Additional data can be written, if the format supports it.- Throws:
java.io.IOException- Maybe thrown by subclasses if the user forgets to close the entry.
-
isClosed
public boolean isClosed()
Tests whether this instance was successfully closed.- Returns:
- whether this instance was successfully closed.
- Since:
- 1.27.0
-
isFinished
protected boolean isFinished()
Tests whether this instance was successfully finished.- Returns:
- whether this instance was successfully finished.
- Since:
- 1.27.0
-
write
public long write(java.io.File file) throws java.io.IOException
Writes all bytes from a file this output stream.- Parameters:
file- the path to the source file.- Returns:
- the number of bytes read or written.
- Throws:
java.io.IOException- if an I/O error occurs when reading or writing.
-
write
public long write(java.nio.file.Path path) throws java.io.IOException
Writes all bytes from a file to this output stream.- Parameters:
path- the path to the source file.- Returns:
- the number of bytes read or written.
- Throws:
java.io.IOException- if an I/O error occurs when reading or writing.
-
writeUsAscii
public byte[] writeUsAscii(java.lang.String data) throws java.io.IOException
Writes and filters the ASCII bytes from the specified String to this output stream.- Parameters:
data- the data.- Returns:
- the ASCII bytes.
- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
OutputStream.write(byte[])
-
writeUsAsciiRaw
public byte[] writeUsAsciiRaw(java.lang.String data) throws java.io.IOException
Writes the raw ASCII bytes from the specified String to this output stream.- Parameters:
data- the data.- Returns:
- the ASCII bytes.
- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
OutputStream.write(byte[])
-
writeUtf8
public byte[] writeUtf8(java.lang.String data) throws java.io.IOException
Writes and filters the UTF-8 bytes from the specified String to this output stream.- Parameters:
data- the data.- Returns:
- the ASCII bytes.
- Throws:
java.io.IOException- if an I/O error occurs.- See Also:
OutputStream.write(byte[])
-
-