ChunkedOutputStream (Commons IO 2.5)
Date: 2016-12-01

org.apache.commons.io.output

## Class ChunkedOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - org.apache.commons.io.output.ChunkedOutputStream

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

      public class ChunkedOutputStream
      extends java.io.FilterOutputStream

  OutputStream which breaks larger output blocks into chunks. Native code may need to copy the input array; if the write buffer is very large this can cause OOME.
  Since:
    2.5

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private int` | `chunkSize` The maximum chunk size to us when writing data arrays
    `private static int` | `DEFAULT_CHUNK_SIZE` The default chunk size to use, i.e.

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

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ChunkedOutputStream(java.io.OutputStream stream)` Creates a new stream that uses a chunk size of `DEFAULT_CHUNK_SIZE`.
    `ChunkedOutputStream(java.io.OutputStream stream, int chunkSize)` Creates a new stream that uses the specified chunk size.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `write(byte[] data, int srcOffset, int length)` Writes the data buffer in chunks to the underlying stream

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

      `close, flush, write, write`

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

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

- - ### Field Detail

    - #### DEFAULT_CHUNK_SIZE

          private static final int DEFAULT_CHUNK_SIZE

      The default chunk size to use, i.e. 4096 bytes.
      See Also:
        Constant Field Values

    - #### chunkSize

          private final int chunkSize

      The maximum chunk size to us when writing data arrays

  - ### Constructor Detail

    - #### ChunkedOutputStream

          public ChunkedOutputStream(java.io.OutputStream stream,
                             int chunkSize)

      Creates a new stream that uses the specified chunk size.
      Parameters:
        `stream` - the stream to wrap
        `chunkSize` - the chunk size to use; must be a positive number.
      Throws:
        `java.lang.IllegalArgumentException` - if the chunk size is <= 0

    - #### ChunkedOutputStream

          public ChunkedOutputStream(java.io.OutputStream stream)

      Creates a new stream that uses a chunk size of `DEFAULT_CHUNK_SIZE`.
      Parameters:
        `stream` - the stream to wrap

  - ### Method Detail

    - #### write

          public void write(byte[] data,
                   int srcOffset,
                   int length)
                     throws java.io.IOException

      Writes the data buffer in chunks to the underlying stream
      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Parameters:
        `data` - the data to write
        `srcOffset` - the offset
        `length` - the length of data to write
      Throws:
        `java.io.IOException` - if an I/O error occurs.

Copyright (c) 2002-2016 Apache Software Foundation