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:
BufferedFileChannelInputStream.Builder,CharSequenceInputStream.Builder,ChunkedOutputStream.Builder,DeferredFileOutputStream.Builder,FileWriterWithEncoding.Builder,LockableFileWriter.Builder,MemoryMappedFileInputStream.Builder,ProxyInputStream.AbstractBuilder,ProxyOutputStream.Builder,QueueInputStream.Builder,RandomAccessFileInputStream.Builder,RandomAccessFileOutputStream.Builder,ReadAheadInputStream.Builder,ReaderInputStream.Builder,ReversedLinesFileReader.Builder,Tailer.Builder,UncheckedBufferedReader.Builder,UncheckedFilterInputStream.Builder,UncheckedFilterOutputStream.Builder,UncheckedFilterReader.Builder,UncheckedFilterWriter.Builder,UnsynchronizedBufferedInputStream.Builder,UnsynchronizedByteArrayInputStream.Builder,UnsynchronizedByteArrayOutputStream.Builder,UnsynchronizedFilterInputStream.Builder,ValidatingObjectInputStream.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 ofT.- Since:
- 2.12.0
-
-
Field Summary
Fields Modifier and Type Field Description private intbufferSizeThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).private java.util.function.IntUnaryOperatorbufferSizeCheckerThe checking behavior for a buffer size request.private intbufferSizeDefaultThe buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).private intbufferSizeMaxThe maximum buffer size.private java.nio.charset.CharsetcharsetThe Charset, defaults toCharset.defaultCharset().private java.nio.charset.CharsetcharsetDefaultThe Charset, defaults toCharset.defaultCharset().private static intDEFAULT_MAX_VALUEprivate static java.nio.file.OpenOption[]DEFAULT_OPEN_OPTIONSprivate java.util.function.IntUnaryOperatordefaultSizeCheckerThe default checking behavior for a buffer size request.private java.nio.file.OpenOption[]openOptions
-
Constructor Summary
Constructors Constructor Description AbstractStreamBuilder()Constructs a new instance for subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intcheckBufferSize(int size)Applies the buffer size request.intgetBufferSize()Gets the buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).intgetBufferSizeDefault()Gets the buffer size default, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).java.lang.CharSequencegetCharSequence()Gets a CharSequence from the origin with a Charset.java.nio.charset.CharsetgetCharset()Gets the Charset, defaults toCharset.defaultCharset().java.nio.charset.CharsetgetCharsetDefault()Gets the Charset default, defaults toCharset.defaultCharset().java.io.FilegetFile()Gets a File from the origin.java.io.InputStreamgetInputStream()Gets an InputStream from the origin with OpenOption[].java.nio.file.OpenOption[]getOpenOptions()Gets the OpenOption array.java.io.OutputStreamgetOutputStream()Gets an OutputStream from the origin with OpenOption[].java.nio.file.PathgetPath()Gets a Path from the origin.java.io.RandomAccessFilegetRandomAccessFile()Gets a RandomAccessFile from the origin.java.io.ReadergetReader()Gets a Reader from the origin with a Charset.java.io.WritergetWriter()Gets a Writer from the origin with an OpenOption[].BsetBufferSize(int bufferSize)Sets the buffer size.BsetBufferSize(java.lang.Integer bufferSize)Sets the buffer size.BsetBufferSizeChecker(java.util.function.IntUnaryOperator bufferSizeChecker)Sets the buffer size checker function.protected BsetBufferSizeDefault(int bufferSizeDefault)Sets the buffer size for subclasses to initialize.BsetBufferSizeMax(int bufferSizeMax)The maximum buffer size checked by the buffer size checker.BsetCharset(java.lang.String charset)Sets the Charset.BsetCharset(java.nio.charset.Charset charset)Sets the Charset.protected BsetCharsetDefault(java.nio.charset.Charset defaultCharset)Sets the Charset default for subclasses to initialize.BsetOpenOptions(java.nio.file.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, newRandomAccessFileOrigin, newRandomAccessFileOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriter
-
Methods inherited from class org.apache.commons.io.build.AbstractSupplier
asThis
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.io.function.IOSupplier
asSupplier, get, getUnchecked
-
-
-
-
Field Detail
-
DEFAULT_MAX_VALUE
private static final int DEFAULT_MAX_VALUE
- See Also:
- Constant Field Values
-
DEFAULT_OPEN_OPTIONS
private static final java.nio.file.OpenOption[] DEFAULT_OPEN_OPTIONS
-
bufferSize
private int bufferSize
The buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).
-
bufferSizeDefault
private int bufferSizeDefault
The buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).
-
bufferSizeMax
private int bufferSizeMax
The maximum buffer size.
-
charset
private java.nio.charset.Charset charset
The Charset, defaults toCharset.defaultCharset().
-
charsetDefault
private java.nio.charset.Charset charsetDefault
The Charset, defaults toCharset.defaultCharset().
-
openOptions
private java.nio.file.OpenOption[] openOptions
-
defaultSizeChecker
private final java.util.function.IntUnaryOperator defaultSizeChecker
The default checking behavior for a buffer size request. Throws aIllegalArgumentExceptionby default.
-
bufferSizeChecker
private java.util.function.IntUnaryOperator bufferSizeChecker
The checking behavior for a buffer size request.
-
-
Method Detail
-
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
public int getBufferSize()
Gets the buffer size, defaults toIOUtils.DEFAULT_BUFFER_SIZE(8192).- Returns:
- the buffer size, defaults to
IOUtils.DEFAULT_BUFFER_SIZE(8192).
-
getBufferSizeDefault
public 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
public java.lang.CharSequence getCharSequence() throws java.io.IOExceptionGets a CharSequence from the origin with a Charset.- Returns:
- An input stream
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to a CharSequence.java.io.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
AbstractOrigin.getCharSequence(Charset)
-
getCharset
public java.nio.charset.Charset getCharset()
Gets the Charset, defaults toCharset.defaultCharset().- Returns:
- the Charset, defaults to
Charset.defaultCharset().
-
getCharsetDefault
public java.nio.charset.Charset getCharsetDefault()
Gets the Charset default, defaults toCharset.defaultCharset().- Returns:
- the Charset default, defaults to
Charset.defaultCharset().
-
getFile
public java.io.File getFile()
Gets a File from the origin.- Returns:
- A File
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to aFile.- Since:
- 2.18.0
- See Also:
AbstractOrigin.getPath()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionGets an InputStream from the origin with OpenOption[].- Returns:
- An input stream
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to anInputStream.java.io.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
AbstractOrigin.getInputStream(OpenOption...),getOpenOptions()
-
getOpenOptions
public java.nio.file.OpenOption[] getOpenOptions()
Gets the OpenOption array.- Returns:
- the OpenOption array.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOExceptionGets an OutputStream from the origin with OpenOption[].- Returns:
- An OutputStream
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to anOutputStream.java.io.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
AbstractOrigin.getOutputStream(OpenOption...),getOpenOptions()
-
getPath
public java.nio.file.Path getPath()
Gets a Path from the origin.- Returns:
- A Path
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to aPath.- Since:
- 2.13.0
- See Also:
AbstractOrigin.getPath()
-
getRandomAccessFile
public java.io.RandomAccessFile getRandomAccessFile() throws java.io.IOExceptionGets a RandomAccessFile from the origin.- Returns:
- A RandomAccessFile
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to aRandomAccessFile.java.io.IOException- if an I/O error occurs.- Since:
- 2.18.0
-
getReader
public java.io.Reader getReader() throws java.io.IOExceptionGets a Reader from the origin with a Charset.- Returns:
- A Reader
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to aReader.java.io.IOException- if an I/O error occurs.- Since:
- 2.16.0
- See Also:
AbstractOrigin.getReader(Charset),getCharset()
-
getWriter
public java.io.Writer getWriter() throws java.io.IOExceptionGets a Writer from the origin with an OpenOption[].- Returns:
- An writer.
- Throws:
java.lang.IllegalStateException- if theoriginisnull.java.lang.UnsupportedOperationException- if the origin cannot be converted to aWriter.java.io.IOException- if an I/O error occurs.- Since:
- 2.13.0
- See Also:
AbstractOrigin.getOutputStream(OpenOption...),getOpenOptions()
-
setBufferSize
public B setBufferSize(int bufferSize)
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:
thisinstance.
-
setBufferSize
public B setBufferSize(java.lang.Integer bufferSize)
Sets the buffer size.Subclasses may ignore this setting.
- Parameters:
bufferSize- the buffer size, null resets to the default.- Returns:
thisinstance.
-
setBufferSizeChecker
public B setBufferSizeChecker(java.util.function.IntUnaryOperator bufferSizeChecker)
Sets the buffer size checker function. Throws aIllegalArgumentExceptionby default.- Parameters:
bufferSizeChecker- the buffer size checker function. null resets to the default behavior.- Returns:
thisinstance.- Since:
- 2.14.0
-
setBufferSizeDefault
protected B setBufferSizeDefault(int bufferSizeDefault)
Sets the buffer size for subclasses to initialize.Subclasses may ignore this setting.
- Parameters:
bufferSizeDefault- the buffer size, null resets to the default.- Returns:
thisinstance.
-
setBufferSizeMax
public B setBufferSizeMax(int bufferSizeMax)
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:
thisinstance.- Since:
- 2.14.0
-
setCharset
public B setCharset(java.nio.charset.Charset charset)
Sets the Charset.Subclasses may ignore this setting.
- Parameters:
charset- the Charset, null resets to the default.- Returns:
thisinstance.
-
setCharset
public B setCharset(java.lang.String charset)
Sets the Charset.Subclasses may ignore this setting.
- Parameters:
charset- the Charset name, null resets to the default.- Returns:
thisinstance.
-
setCharsetDefault
protected B setCharsetDefault(java.nio.charset.Charset defaultCharset)
Sets the Charset default for subclasses to initialize.Subclasses may ignore this setting.
- Parameters:
defaultCharset- the Charset name, null resets to the default.- Returns:
thisinstance.
-
setOpenOptions
public B setOpenOptions(java.nio.file.OpenOption... openOptions)
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:
thisinstance.- Since:
- 2.13.0
- See Also:
AbstractOriginSupplier.setInputStream(InputStream),AbstractOriginSupplier.setOutputStream(OutputStream),AbstractOriginSupplier.setWriter(Writer)
-
throwIae
private int throwIae(int size, int max)
-
-