BaseNCodecOutputStream (Apache Commons Codec 1.22.1 API)
Description: declaration: package: org.apache.commons.codec.binary, class: BaseNCodecOutputStream

Package org.apache.commons.codec.binary

# Class BaseNCodecOutputStream<C extends BaseNCodec,T extends BaseNCodecOutputStream<C,T,B>,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>>

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.apache.commons.codec.binary.BaseNCodecOutputStream<C,T,B>

Type Parameters:
  `C` - A BaseNCodec subclass.
  `T` - A BaseNCodecInputStream subclass.
  `B` - A subclass.

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`

Direct Known Subclasses:
  `Base16OutputStream`, `Base32OutputStream`, `Base58OutputStream`, `Base64OutputStream`

public class BaseNCodecOutputStream<C extends BaseNCodec,T extends BaseNCodecOutputStream<C,T,B>,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>> extends FilterOutputStream
Abstract superclass for Base-N output streams.

To write the EOF marker without closing the stream, call `eof()` or use an Apache Commons IO CloseShieldOutputStream.

Since:
  1.5
See Also:
  - `Base16OutputStream`
  - `Base32OutputStream`
  - `Base64OutputStream`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `BaseNCodecOutputStream.AbstractBuilder<T,C extends BaseNCodec,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>>`
  Builds output stream instances in `BaseNCodec` format.

- ## Field Summary

  ### Fields inherited from class java.io.FilterOutputStream

  `out`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  ``
  `BaseNCodecOutputStream(OutputStream outputStream, C basedCodec, boolean doEncode)`
  Constructs a new instance.
  `protected`
  `BaseNCodecOutputStream(BaseNCodecOutputStream.AbstractBuilder<T,C,B> builder)`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes this output stream and releases any system resources associated with the stream.
  `void`
  `eof()`
  Writes EOF.
  `void`
  `flush()`
  Flushes this output stream and forces any buffered output bytes to be written out to the stream.
  `boolean`
  `isStrictDecoding()`
  Returns true if decoding behavior is strict.
  `void`
  `write(byte[] array, int offset, int len)`
  Writes `len` bytes from the specified `b` array starting at `offset` to this output stream.
  `void`
  `write(int i)`
  Writes the specified `byte` to this output stream.

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

  `write`

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

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

- ## Constructor Details

  - ### BaseNCodecOutputStream

    protected BaseNCodecOutputStream(BaseNCodecOutputStream.AbstractBuilder<T,C,B> builder)
    Constructs a new instance.
    Parameters:
      `builder` - A builder.
    Since:
      1.20.0

  - ### BaseNCodecOutputStream

    public BaseNCodecOutputStream(OutputStream outputStream, C basedCodec, boolean doEncode)
    Constructs a new instance. TODO should this be protected?
    Parameters:
      `outputStream` - The underlying output or null.
      `basedCodec` - A BaseNCodec.
      `doEncode` - true to encode, false to decode, TODO should be an enum?.

- ## Method Details

  - ### close

    public void close() throws IOException
    Closes this output stream and releases any system resources associated with the stream.

    To write the EOF marker without closing the stream, call `eof()` or use an Apache Commons IO CloseShieldOutputStream.

    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `FilterOutputStream`
    Throws:
      `IOException` - if an I/O error occurs.

  - ### eof

    public void eof()
    Writes EOF.
    Since:
      1.11

  - ### flush

    public void flush() throws IOException
    Flushes this output stream and forces any buffered output bytes to be written out to the stream.
    Specified by:
      `flush` in interface `Flushable`
    Overrides:
      `flush` in class `FilterOutputStream`
    Throws:
      `IOException` - if an I/O error occurs.

  - ### isStrictDecoding

    public boolean isStrictDecoding()
    Returns true if decoding behavior is strict. Decoding will raise an `IllegalArgumentException` if trailing bits are not part of a valid encoding.

    The default is false for lenient encoding. Decoding will compose trailing bits into 8-bit bytes and discard the remainder.

    Returns:
      true if using strict decoding.
    Since:
      1.15

  - ### write

    public void write(byte[] array, int offset, int len) throws IOException
    Writes `len` bytes from the specified `b` array starting at `offset` to this output stream.
    Overrides:
      `write` in class `FilterOutputStream`
    Parameters:
      `array` - source byte array.
      `offset` - where to start reading the bytes.
      `len` - maximum number of bytes to write.
    Throws:
      `IOException` - if an I/O error occurs.
      `NullPointerException` - if the byte array parameter is null.
      `IndexOutOfBoundsException` - if offset, len or buffer size are invalid.

  - ### write

    public void write(int i) throws IOException
    Writes the specified `byte` to this output stream.
    Overrides:
      `write` in class `FilterOutputStream`
    Parameters:
      `i` - source byte.
    Throws:
      `IOException` - if an I/O error occurs.