org.apache.axiom.attachments.utils

## Class BAAOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.axiom.attachments.utils.BAAOutputStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, ReadFromSupport

      public class BAAOutputStream
      extends OutputStream
      implements ReadFromSupport

  BAAOutputStream is like a ByteArrayOutputStream. A ByteArrayOutputStream stores the backing data in a byte[]. BAAOutputStream stores the backing data in a Array of byte[]. Using several non-contiguous chunks reduces memory copy and resizing.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BAAOutputStream()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ArrayList` | `buffers()`
    `int` | `length()`
    `long` | `readFrom(InputStream is, long maxRead)` Read data from the given input stream and write it to this output stream.
    `long` | `receive(InputStream is, long maxRead)`
    `void` | `write(byte[] b)`
    `void` | `write(byte[] b, int off, int len)`
    `void` | `write(int b)`

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

      `close, flush`

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

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

- - ### Constructor Detail

    - #### BAAOutputStream

          public BAAOutputStream()

  - ### Method Detail

    - #### write

          public void write(byte[] b,
                            int off,
                            int len)
                     throws IOException

      Overrides:
        `write` in class `OutputStream`
      Throws:
        `IOException`

    - #### write

          public void write(byte[] b)
                     throws IOException

      Overrides:
        `write` in class `OutputStream`
      Throws:
        `IOException`

    - #### write

          public void write(int b)
                     throws IOException

      Specified by:
        `write` in class `OutputStream`
      Throws:
        `IOException`

    - #### buffers

          public ArrayList buffers()

    - #### length

          public int length()

    - #### receive

          public long receive(InputStream is,
                              long maxRead)
                       throws IOException

      Parameters:
        `is` - InputStream containing data
        `maxRead` - the maximum number of bytes to receive
      Returns:
        bytesReceived
      Throws:
        `IOException`

    - #### readFrom

          public long readFrom(InputStream is,
                               long maxRead)
                        throws StreamCopyException

      Description copied from interface: `ReadFromSupport`
      Read data from the given input stream and write it to this output stream. The method transfers data until one of the following conditions is met:
      - The end of the input stream is reached.
      - The value of the `length` argument is different from `-1` and the number of bytes transferred is equal to `length`.
      Specified by:
        `readFrom` in interface `ReadFromSupport`
      Parameters:
        `is` - An input stream to read data from. This method will not close the stream.
        `maxRead` - the number of bytes to transfer, or `-1` if the method should transfer data until the end of the input stream is reached
      Returns:
        the number of bytes transferred
      Throws:
        `StreamCopyException`

Copyright © The Apache Software Foundation. All Rights Reserved.