Package org.apache.commons.io.build
Class AbstractStreamBuilder<T,B extends AbstractStreamBuilder<T,B>>
java.lang.Object
org.apache.commons.io.build.AbstractSupplier<T,B>
org.apache.commons.io.build.AbstractOriginSupplier<T,B>
org.apache.commons.io.build.AbstractStreamBuilder<T,B>
- Type Parameters:
T- the type of instances to build.B- the type of builder subclass.
- All Implemented Interfaces:
IOSupplier<T>
- Direct Known Subclasses:
AutoCloseInputStream.Builder,BOMInputStream.Builder,BoundedInputStream.AbstractBuilder,BufferedFileChannelInputStream.Builder,CharSequenceInputStream.Builder,ChecksumInputStream.Builder,ChunkedOutputStream.Builder,DeferredFileOutputStream.Builder,FileWriterWithEncoding.Builder,LockableFileWriter.Builder,MemoryMappedFileInputStream.Builder,MessageDigestCalculatingInputStream.Builder,MessageDigestInputStream.Builder,QueueInputStream.Builder,RandomAccessFileInputStream.Builder,ReadAheadInputStream.Builder,ReaderInputStream.Builder,ReversedLinesFileReader.Builder,Tailer.Builder,ThrottledInputStream.Builder,UncheckedBufferedReader.Builder,UncheckedFilterInputStream.Builder,UncheckedFilterOutputStream.Builder,UncheckedFilterReader.Builder,UncheckedFilterWriter.Builder,UnsynchronizedBufferedInputStream.Builder,UnsynchronizedByteArrayInputStream.Builder,UnsynchronizedByteArrayOutputStream.Builder,UnsynchronizedFilterInputStream.Builder,WriterOutputStream.Builder,XmlStreamReader.Builder,XmlStreamWriter.Builder
public abstract class AbstractStreamBuilder<T,B extends AbstractStreamBuilder<T,B>>
extends AbstractOriginSupplier<T,B>
Abstracts building a typed instance of
T.- Since:
- 2.12.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).private IntUnaryOperatorThe checking behavior for a buffer size request.private intThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).private intThe maximum buffer size.private CharsetThe Charset, defaults toCharset.defaultCharset().private CharsetThe Charset, defaults toCharset.defaultCharset().private static final intprivate static final OpenOption[]private final IntUnaryOperatorThe default checking behavior for a buffer size request.private OpenOption[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intcheckBufferSize(int size) Applies the buffer size request.protected intGets the buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).protected intGets the buffer size default, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).protected CharSequenceGets a CharSequence from the origin with a Charset.Gets the Charset, defaults toCharset.defaultCharset().protected CharsetGets the Charset default, defaults toCharset.defaultCharset().protected InputStreamGets an InputStream from the origin with OpenOption[].protected OpenOption[]Gets the OpenOption array.protected OutputStreamGets an OutputStream from the origin with OpenOption[].protected PathgetPath()Gets a Path from the origin.protected ReaderGets a Reader from the origin with a Charset.protected WriterGets a Writer from the origin with an OpenOption[].setBufferSize(int bufferSize) Sets the buffer size.setBufferSize(Integer bufferSize) Sets the buffer size.setBufferSizeChecker(IntUnaryOperator bufferSizeChecker) Sets the buffer size checker function.protected BsetBufferSizeDefault(int bufferSizeDefault) Sets the buffer size for subclasses to initialize.setBufferSizeMax(int bufferSizeMax) The maximum buffer size checked by the buffer size checker.setCharset(String charset) Sets the Charset.setCharset(Charset charset) Sets the Charset.protected BsetCharsetDefault(Charset defaultCharset) Sets the Charset default for subclasses to initialize.setOpenOptions(OpenOption... openOptions) Sets the OpenOption[].private intthrowIae(int size, int max) Methods inherited from class org.apache.commons.io.build.AbstractOriginSupplier
checkOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setReader, setURI, setWriterMethods inherited from class org.apache.commons.io.build.AbstractSupplier
asThisMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.io.function.IOSupplier
asSupplier, get
-
Field Details
-
DEFAULT_MAX_VALUE
private static final int DEFAULT_MAX_VALUE- See Also:
-
DEFAULT_OPEN_OPTIONS
-
bufferSize
private int bufferSizeThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192). -
bufferSizeDefault
private int bufferSizeDefaultThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192). -
bufferSizeMax
private int bufferSizeMaxThe maximum buffer size. -
charset
The Charset, defaults toCharset.defaultCharset(). -
charsetDefault
The Charset, defaults toCharset.defaultCharset(). -
openOptions
-
defaultSizeChecker
The default checking behavior for a buffer size request. Throws aIllegalArgumentExceptionby default. -
bufferSizeChecker
The checking behavior for a buffer size request.
-
-
Constructor Details
-
AbstractStreamBuilder
public AbstractStreamBuilder()
-
-
Method Details
-
checkBufferSize
private int checkBufferSize(int size) Applies the buffer size request.- Parameters:
size- the size request.- Returns:
- the size to use, usually the input, or can throw an unchecked exception, like
IllegalArgumentException.
-
getBufferSize
protected int getBufferSize()Gets the buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).- Returns:
- the buffer size, defaults to
IOUtils.DEFAULT_BUFFER_SIZE(8192).
-
getBufferSizeDefault
protected int getBufferSizeDefault()Gets the buffer size default, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).- Returns:
- the buffer size default, defaults to
IOUtils.DEFAULT_BUFFER_SIZE(8192).
-
getCharSequence
Gets a CharSequence from the origin with a Charset.- Returns:
- An input stream
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to a CharSequence.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
-
getCharset
Gets the Charset, defaults toCharset.defaultCharset().- Returns:
- the Charset, defaults to
Charset.defaultCharset().
-
getCharsetDefault
Gets the Charset default, defaults toCharset.defaultCharset().- Returns:
- the Charset default, defaults to
Charset.defaultCharset().
-
getInputStream
Gets an InputStream from the origin with OpenOption[].- Returns:
- An input stream
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to anInputStream.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
-
getOpenOptions
Gets the OpenOption array.- Returns:
- the OpenOption array.
-
getOutputStream
Gets an OutputStream from the origin with OpenOption[].- Returns:
- An OutputStream
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to anOutputStream.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
-
getPath
Gets a Path from the origin.- Returns:
- A Path
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to aPath.- Since:
- 2.13.0
- See Also:
-
getReader
Gets a Reader from the origin with a Charset.- Returns:
- A Reader
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to aReader.IOException- if an I/O error occurs.- Since:
- 2.16.0
- See Also:
-
getWriter
Gets a Writer from the origin with an OpenOption[].- Returns:
- An writer.
- Throws:
IllegalStateException- if theoriginisnull.UnsupportedOperationException- if the origin cannot be converted to aWriter.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
-
setBufferSize
Sets the buffer size. Invalid input (bufferSize <= 0) resets the value to its default.Subclasses may ignore this setting.
- Parameters:
bufferSize- the buffer size.- Returns:
- this.
-
setBufferSize
Sets the buffer size.Subclasses may ignore this setting.
- Parameters:
bufferSize- the buffer size, null resets to the default.- Returns:
- this.
-
setBufferSizeChecker
Sets the buffer size checker function. Throws aIllegalArgumentExceptionby default.- Parameters:
bufferSizeChecker- the buffer size checker function. null resets to the default behavior.- Returns:
- this
- Since:
- 2.14.0
-
setBufferSizeDefault
Sets the buffer size for subclasses to initialize.Subclasses may ignore this setting.
- Parameters:
bufferSizeDefault- the buffer size, null resets to the default.- Returns:
- this.
-
setBufferSizeMax
The maximum buffer size checked by the buffer size checker. Values less or equal to 0, resets to the int max value. By default, if this value is exceeded, this methods throws anIllegalArgumentException.- Parameters:
bufferSizeMax- maximum buffer size checked by the buffer size checker.- Returns:
- this.
- Since:
- 2.14.0
-
setCharset
Sets the Charset.Subclasses may ignore this setting.
- Parameters:
charset- the Charset, null resets to the default.- Returns:
- this.
-
setCharset
Sets the Charset.Subclasses may ignore this setting.
- Parameters:
charset- the Charset name, null resets to the default.- Returns:
- this.
-
setCharsetDefault
Sets the Charset default for subclasses to initialize.Subclasses may ignore this setting.
- Parameters:
defaultCharset- the Charset name, null resets to the default.- Returns:
- this.
-
setOpenOptions
Sets the OpenOption[].Normally used with InputStream, OutputStream, and Writer.
Subclasses may ignore this setting.
- Parameters:
openOptions- the OpenOption[] name, null resets to the default.- Returns:
- this.
- Since:
- 2.13.0
- See Also:
-
throwIae
private int throwIae(int size, int max)
-