Class 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.

    To build an instance, see ChunkedOutputStream.Builder

    Since:
    2.5
    See Also:
    ChunkedOutputStream.Builder
    • Field Detail

      • chunkSize

        private final int chunkSize
        The maximum chunk size to us when writing data arrays.
    • Constructor Detail

      • ChunkedOutputStream

        private ChunkedOutputStream​(ChunkedOutputStream.Builder builder)
                             throws java.io.IOException
        Constructs a new stream that uses the specified chunk size.
        Parameters:
        builder - holds contruction data.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • ChunkedOutputStream

        @Deprecated
        public ChunkedOutputStream​(java.io.OutputStream stream,
                                   int chunkSize)
        Constructs 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.
    • Method Detail

      • getChunkSize

        int getChunkSize()
      • 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.lang.NullPointerException - if the data is null.
        java.lang.IndexOutOfBoundsException - if srcOffset or length are negative, or if srcOffset + length is greater than data.length.
        java.io.IOException - if an I/O error occurs.