DemuxOutputStream (Apache Ant API)
Description: declaration: package: org.apache.tools.ant, class: DemuxOutputStream

# Class DemuxOutputStream

java.lang.Object
java.io.OutputStream
org.apache.tools.ant.DemuxOutputStream

All Implemented Interfaces:
  `Closeable, Flushable, AutoCloseable`

public class DemuxOutputStream extends OutputStream
Logs content written by a thread and forwards the buffers onto the project object which will forward the content to the appropriate task.

Since:
  1.4

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DemuxOutputStream(Project project, boolean isErrorStream)`
  Creates a new instance of this class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Equivalent to flushing the stream.
  `void`
  `flush()`
  Writes all remaining data in the buffer associated with the current thread to the project.
  `protected void`
  `processBuffer(ByteArrayOutputStream buffer)`
  Converts the buffer to a string and sends it to the project.
  `protected void`
  `processFlush(ByteArrayOutputStream buffer)`
  Converts the buffer to a string and sends it to the project.
  `void`
  `write(byte[] b, int off, int len)`
  Write a block of characters to the output stream
  `void`
  `write(int cc)`
  Writes the data to the buffer and flushes the buffer if a line separator is detected or if the buffer has reached its maximum size.

  ### Methods inherited from class OutputStream

  `nullOutputStream, write`

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### DemuxOutputStream

    public DemuxOutputStream(Project project, boolean isErrorStream)
    Creates a new instance of this class.
    Parameters:
      `project` - The project instance for which output is being demultiplexed. Must not be `null`.
      `isErrorStream` - `true` if this is the error string, otherwise a normal output stream. This is passed to the project so it knows which stream it is receiving.

- ## Method Details

  - ### write

    public void write(int cc) throws IOException
    Writes the data to the buffer and flushes the buffer if a line separator is detected or if the buffer has reached its maximum size.
    Specified by:
      `write` in class `OutputStream`
    Parameters:
      `cc` - data to log (byte).
    Throws:
      `IOException` - if the data cannot be written to the stream

  - ### processBuffer

    protected void processBuffer(ByteArrayOutputStream buffer)
    Converts the buffer to a string and sends it to the project.
    Parameters:
      `buffer` - the ByteArrayOutputStream used to collect the output until a line separator is seen.
    See Also:
      - `Project.demuxOutput(String,boolean)`

  - ### processFlush

    protected void processFlush(ByteArrayOutputStream buffer)
    Converts the buffer to a string and sends it to the project.
    Parameters:
      `buffer` - the ByteArrayOutputStream used to collect the output until a line separator is seen.
    See Also:
      - `Project.demuxOutput(String,boolean)`

  - ### close

    public void close() throws IOException
    Equivalent to flushing the stream.
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `OutputStream`
    Throws:
      `IOException` - if there is a problem closing the stream.
    See Also:
      - `flush()`

  - ### flush

    public void flush() throws IOException
    Writes all remaining data in the buffer associated with the current thread to the project.
    Specified by:
      `flush` in interface `Flushable`
    Overrides:
      `flush` in class `OutputStream`
    Throws:
      `IOException` - if there is a problem flushing the stream.

  - ### write

    public void write(byte[] b, int off, int len) throws IOException
    Write a block of characters to the output stream
    Overrides:
      `write` in class `OutputStream`
    Parameters:
      `b` - the array containing the data
      `off` - the offset into the array where data starts
      `len` - the length of block
    Throws:
      `IOException` - if the data cannot be written into the stream.