public final class ReaderInputStream extends InputStream
An InputStream
that converts characters from a Reader
into bytes using an
arbitrary Charset.
This is an alternative to copying the data to an OutputStream
via a Writer
,
which is necessarily blocking. By implementing an InputStream
it allows consumers to
"pull" as much data as they can handle, which is more convenient when dealing with flow
controlled, async APIs.
Constructor and Description |
---|
ReaderInputStream(Reader reader,
Charset charset)
Creates a new input stream that will encode the characters from
reader into bytes using
the given character set encoder. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
available, mark, markSupported, read, reset, skip
public ReaderInputStream(Reader reader, Charset charset)
reader
into bytes using
the given character set encoder.reader
- input sourcecharset
- character set used for encoding chars to bytesIllegalArgumentException
- if bufferSize is non-positivepublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
Copyright © 2018 Guangshan Technology, Inc.. All rights reserved.