Class CompressFilterOutputStream<T extends OutputStream>

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.apache.commons.compress.CompressFilterOutputStream<T>
Type Parameters:
T - The underlying OutputStream type.
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
ArchiveOutputStream, CompressorOutputStream

public abstract class CompressFilterOutputStream<T extends OutputStream> extends FilterOutputStream
Abstracts classes that compress or archive an output stream.
Since:
1.28.0
  • Constructor Details

    • CompressFilterOutputStream

      Constructs a new instance without a backing OutputStream.

      You must initialize this.out after construction.

    • CompressFilterOutputStream

      Creates an output stream filter built on top of the specified underlying OutputStream.
      Parameters:
      out - the underlying output stream to be assigned to the field this.out for later use, or null if this instance is to be created without an underlying stream.
  • Method Details

    • checkOpen

      protected void checkOpen() throws IOException
      Check to make sure that this stream has not been closed.
      Throws:
      IOException - if the stream is already closed.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterOutputStream
      Throws:
      IOException
    • finish

      public void finish() throws IOException
      Finishes the addition of entries to this stream, without closing it. Additional data can be written, if the format supports it.
      Throws:
      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
    • out

      protected T out()
      Gets the underlying output stream.
      Returns:
      the underlying output stream.
    • write

      public long write(File file) throws 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:
      IOException - if an I/O error occurs when reading or writing.
    • write

      public long write(Path path) throws 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:
      IOException - if an I/O error occurs when reading or writing.
    • writeUsAscii

      public byte[] writeUsAscii(String data) throws IOException
      Writes and filters the ASCII bytes from the specified String to this output stream.
      Parameters:
      data - the data.
      Returns:
      the ASCII bytes.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeUsAsciiRaw

      public byte[] writeUsAsciiRaw(String data) throws IOException
      Writes the raw ASCII bytes from the specified String to this output stream.
      Parameters:
      data - the data.
      Returns:
      the ASCII bytes.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeUtf8

      public byte[] writeUtf8(String data) throws 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:
      IOException - if an I/O error occurs.
      See Also: