Package org.apache.commons.io.output
Class ChunkedWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
org.apache.commons.io.output.ChunkedWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Writer 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
FieldsModifier and TypeFieldDescriptionprivate final int
The maximum chunk size to us when writing data arraysprivate static final int
The default chunk size to use, i.e.Fields inherited from class java.io.FilterWriter
out
-
Constructor Summary
ConstructorsConstructorDescriptionChunkedWriter
(Writer writer) Creates a new writer that uses a chunk size ofDEFAULT_CHUNK_SIZE
ChunkedWriter
(Writer writer, int chunkSize) Creates a new writer that uses the specified chunk size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
write
(char[] data, int srcOffset, int length) writes the data buffer in chunks to the underlying writerMethods inherited from class java.io.FilterWriter
close, flush, write, write
-
Field Details
-
DEFAULT_CHUNK_SIZE
private static final int DEFAULT_CHUNK_SIZEThe default chunk size to use, i.e. 8192 bytes.- See Also:
-
chunkSize
private final int chunkSizeThe maximum chunk size to us when writing data arrays
-
-
Constructor Details
-
ChunkedWriter
Creates a new writer that uses a chunk size ofDEFAULT_CHUNK_SIZE
- Parameters:
writer
- the writer to wrap
-
ChunkedWriter
Creates a new writer that uses the specified chunk size.- Parameters:
writer
- the writer to wrapchunkSize
- the chunk size to use; must be a positive number.- Throws:
IllegalArgumentException
- if the chunk size is <= 0
-
-
Method Details
-
write
writes the data buffer in chunks to the underlying writer- Overrides:
write
in classFilterWriter
- Parameters:
data
- The datasrcOffset
- the offsetlength
- the number of bytes to write- Throws:
IOException
- upon error
-