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
InputStream
implementation that can read from String, StringBuffer,
StringBuilder or CharBuffer.
- Since:
- 2.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBuffer
private static final int
private final CharBuffer
private final CharsetEncoder
private int
private int
private static final int
-
Constructor Summary
ConstructorsConstructorDescriptionCharSequenceInputStream
(CharSequence cs, String charset) Constructor, callsCharSequenceInputStream(CharSequence, String, int)
with a buffer size of 2048.CharSequenceInputStream
(CharSequence cs, String charset, int bufferSize) Constructor, callsCharSequenceInputStream(CharSequence, Charset, int)
.CharSequenceInputStream
(CharSequence cs, Charset charset) Constructor, callsCharSequenceInputStream(CharSequence, Charset, int)
with a buffer size of 2048.CharSequenceInputStream
(CharSequence cs, Charset charset, int bufferSize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionint
Return an estimate of the number of bytes remaining in the byte stream.void
close()
private void
Fills the byte output buffer from the input char buffer.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] array, int off, int len) void
reset()
long
skip
(long n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
NO_MARK
private static final int NO_MARK- See Also:
-
encoder
-
cbuf
-
bbuf
-
mark_cbuf
private int mark_cbuf -
mark_bbuf
private int mark_bbuf
-
-
Constructor Details
-
CharSequenceInputStream
Constructor.- Parameters:
cs
- the input character sequencecharset
- the character set name to usebufferSize
- the buffer size to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character
-
CharSequenceInputStream
Constructor, callsCharSequenceInputStream(CharSequence, Charset, int)
.- Parameters:
cs
- the input character sequencecharset
- the character set name to usebufferSize
- the buffer size to use.- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character
-
CharSequenceInputStream
Constructor, callsCharSequenceInputStream(CharSequence, Charset, int)
with a buffer size of 2048.- Parameters:
cs
- the input character sequencecharset
- the character set name to use- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character
-
CharSequenceInputStream
Constructor, callsCharSequenceInputStream(CharSequence, String, int)
with a buffer size of 2048.- Parameters:
cs
- the input character sequencecharset
- the character set name to use- Throws:
IllegalArgumentException
- if the buffer is not large enough to hold a complete character
-
-
Method Details
-
fillBuffer
Fills the byte output buffer from the input char buffer.- Throws:
CharacterCodingException
- an error encoding data
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
Return an estimate of 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
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
- Parameters:
readlimit
- max read limit (ignored)
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-