Package java.io

Class FilterOutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
BufferedOutputStream, CheckedOutputStream, CipherOutputStream, CipherOutputStream, DataOutputStream, DeflaterOutputStream, DigestOutputStream, InflaterOutputStream, PrintStream

public class FilterOutputStream
extends OutputStream
Wraps an existing OutputStream and performs some transformation on the output data while it is being written. Transformations can be anything from a simple byte-wise filtering output data to an on-the-fly compression or decompression of the underlying stream. Output streams that wrap another output stream and provide some additional functionality on top of it usually inherit from this class.
See Also:
FilterOutputStream
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected OutputStream out
    The target output stream for this filter stream.
  • Constructor Summary

    Constructors
    Constructor Description
    FilterOutputStream​(OutputStream out)
    Constructs a new FilterOutputStream with out as its target stream.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes this stream.
    void flush()
    Ensures that all pending data is sent out to the target stream.
    void write​(byte[] buffer, int offset, int length)
    Writes count bytes from the byte array buffer starting at offset to the target stream.
    void write​(int oneByte)
    Writes one byte to the target stream.

    Methods inherited from class java.io.OutputStream

    write

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • out

      protected OutputStream out
      The target output stream for this filter stream.
  • Constructor Details

    • FilterOutputStream

      public FilterOutputStream​(OutputStream out)
      Constructs a new FilterOutputStream with out as its target stream.
      Parameters:
      out - the target stream that this stream writes to.
  • Method Details

    • close

      public void close() throws IOException
      Closes this stream. This implementation closes the target stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - if an error occurs attempting to close this stream.
    • flush

      public void flush() throws IOException
      Ensures that all pending data is sent out to the target stream. This implementation flushes the target stream.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an error occurs attempting to flush this stream.
    • write

      public void write​(byte[] buffer, int offset, int length) throws IOException
      Writes count bytes from the byte array buffer starting at offset to the target stream.
      Overrides:
      write in class OutputStream
      Parameters:
      buffer - the buffer to write.
      offset - the index of the first byte in buffer to write.
      length - the number of bytes in buffer to write.
      Throws:
      IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.
      IOException - if an I/O error occurs while writing to this stream.
    • write

      public void write​(int oneByte) throws IOException
      Writes one byte to the target stream. Only the low order byte of the integer oneByte is written.
      Specified by:
      write in class OutputStream
      Parameters:
      oneByte - the byte to be written.
      Throws:
      IOException - if an I/O error occurs while writing to this stream.