Package org.apache.commons.io.input
Class CharSequenceInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.CharSequenceInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Implements an
InputStream
to read bytes from String, StringBuffer, StringBuilder or CharBuffer,
encoded using the specified Charset. The Charset defaults to Charset.defaultCharset().
Note: Supports mark(int)
and reset()
.
To build an instance, use CharSequenceInputStream.Builder
.
- Since:
- 2.2
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBuffer
private int
private final CharBuffer
private int
private final CharsetEncoder
private static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CharSequenceInputStream
(CharSequence cs, int bufferSize, CharsetEncoder charsetEncoder) CharSequenceInputStream
(CharSequence cs, String charset) Deprecated.CharSequenceInputStream
(CharSequence cs, String charset, int bufferSize) Deprecated.CharSequenceInputStream
(CharSequence cs, Charset charset) Deprecated.CharSequenceInputStream
(CharSequence cs, Charset charset, int bufferSize) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionint
Gets a lower bound on the number of bytes remaining in the byte stream.builder()
Constructs a newCharSequenceInputStream.Builder
.void
close()
private void
Fills the byte output buffer from the input char buffer.(package private) CharsetEncoder
Gets the CharsetEncoder.void
mark
(int readLimit) boolean
private static CharsetEncoder
newEncoder
(Charset charset) int
read()
int
read
(byte[] b) int
read
(byte[] array, int off, int len) void
reset()
long
skip
(long n)
-
Field Details
-
NO_MARK
private static final int NO_MARK- See Also:
-
bBuf
-
bBufMark
private int bBufMark -
cBuf
-
cBufMark
private int cBufMark -
charsetEncoder
-
-
Constructor Details
-
CharSequenceInputStream
Deprecated.Constructs a new instance with a buffer size ofIOUtils.DEFAULT_BUFFER_SIZE
.- Parameters:
cs
- the input character sequence.charset
- the character set name to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character.
-
CharSequenceInputStream
Deprecated.Constructs a new instance.- Parameters:
cs
- the input character sequence.charset
- the character set name to use, null maps to the default Charset.bufferSize
- the buffer size to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character.
-
CharSequenceInputStream
-
CharSequenceInputStream
Deprecated.Constructs a new instance with a buffer size ofIOUtils.DEFAULT_BUFFER_SIZE
.- Parameters:
cs
- the input character sequence.charset
- the character set name to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character.
-
CharSequenceInputStream
Deprecated.Constructs a new instance.- Parameters:
cs
- the input character sequence.charset
- the character set name to use, null maps to the default Charset.bufferSize
- the buffer size to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character.
-
-
Method Details
-
builder
Constructs a newCharSequenceInputStream.Builder
.- Returns:
- a new
CharSequenceInputStream.Builder
. - Since:
- 2.12.0
-
newEncoder
-
available
Gets a lower bound on the number of bytes remaining in the byte stream.- Overrides:
available
in classInputStream
- Returns:
- the count of bytes that can be read without blocking (or returning EOF).
- Throws:
IOException
- if an error occurs (probably not possible).
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
fillBuffer
Fills the byte output buffer from the input char buffer.- Throws:
CharacterCodingException
- an error encoding data.
-
getCharsetEncoder
CharsetEncoder getCharsetEncoder()Gets the CharsetEncoder.- Returns:
- the CharsetEncoder.
-
mark
public void mark(int readLimit) - Overrides:
mark
in classInputStream
- Parameters:
readLimit
- max read limit (ignored).
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
builder()
,CharSequenceInputStream.Builder
, andCharSequenceInputStream.Builder.get()