Class CompressFilterOutputStream<T extends java.io.OutputStream>

  • Type Parameters:
    T - The underlying OutputStream type.
    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
    • Field Summary

      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      CompressFilterOutputStream()
      Constructs a new instance without a backing OutputStream.
      CompressFilterOutputStream​(T out)
      Creates an output stream filter built on top of the specified underlying OutputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkOpen()
      Check to make sure that this stream has not been closed.
      void close()  
      void finish()
      Finishes the addition of entries to this stream, without closing it.
      boolean isClosed()
      Tests whether this instance was successfully closed.
      protected boolean isFinished()
      Tests whether this instance was successfully finished.
      protected T out()
      Gets the underlying output stream.
      long write​(java.io.File file)
      Writes all bytes from a file this output stream.
      long write​(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.
      • Methods inherited from class java.io.FilterOutputStream

        flush, write, write, write
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CompressFilterOutputStream

        public CompressFilterOutputStream()
        Constructs a new instance without a backing OutputStream.

        You must initialize this.out after construction.

      • CompressFilterOutputStream

        public CompressFilterOutputStream​(T out)
        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 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.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
      • out

        protected T out()
        Gets the underlying output stream.
        Returns:
        the underlying output stream.
      • 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[])