CompressionOutputStream (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.io.compress, class: CompressionOutputStream

Package org.apache.hadoop.io.compress

# Class CompressionOutputStream

java.lang.Object
java.io.OutputStream
org.apache.hadoop.io.compress.CompressionOutputStream

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`, `org.apache.hadoop.fs.statistics.IOStatisticsSource`

Direct Known Subclasses:
  `CompressorStream`

@Public @Evolving public abstract class CompressionOutputStream extends OutputStream implements org.apache.hadoop.fs.statistics.IOStatisticsSource
A compression output stream.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final OutputStream`
  `out`
  The output stream to be compressed.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `CompressionOutputStream(OutputStream out)`
  Create a compression output stream that writes the compressed bytes to the given stream.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `abstract void`
  `finish()`
  Finishes writing compressed data to the output stream without closing the underlying stream.
  `void`
  `flush()`
  `IOStatistics`
  `getIOStatistics()`
  Return any IOStatistics provided by the underlying stream.
  `abstract void`
  `resetState()`
  Reset the compression to the initial state.
  `abstract void`
  `write(byte[] b, int off, int len)`
  Write compressed bytes to the stream.

  ### Methods inherited from class java.io.OutputStream

  `nullOutputStream, write, write`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### out

    protected final OutputStream out
    The output stream to be compressed.

- ## Constructor Details

  - ### CompressionOutputStream

    protected CompressionOutputStream(OutputStream out)
    Create a compression output stream that writes the compressed bytes to the given stream.
    Parameters:
      `out` - out.

- ## Method Details

  - ### close

    public void close() throws IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `OutputStream`
    Throws:
      `IOException`

  - ### flush

    public void flush() throws IOException
    Specified by:
      `flush` in interface `Flushable`
    Overrides:
      `flush` in class `OutputStream`
    Throws:
      `IOException`

  - ### write

    public abstract void write(byte[] b, int off, int len) throws IOException
    Write compressed bytes to the stream. Made abstract to prevent leakage to underlying stream.
    Overrides:
      `write` in class `OutputStream`
    Throws:
      `IOException`

  - ### finish

    public abstract void finish() throws IOException
    Finishes writing compressed data to the output stream without closing the underlying stream.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### resetState

    public abstract void resetState() throws IOException
    Reset the compression to the initial state. Does not reset the underlying stream.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### getIOStatistics

    public IOStatistics getIOStatistics()
    Return any IOStatistics provided by the underlying stream.
    Specified by:
      `getIOStatistics` in interface `org.apache.hadoop.fs.statistics.IOStatisticsSource`
    Returns:
      IO stats from the inner stream.