APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.org.jline.utils

public Class InputStreamReader

extends Reader
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStreamWriter, .Reader, .UnsupportedEncodingException, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetDecoder, .CoderResult, .CodingErrorAction, .MalformedInputException, .UnmappableCharacterException

A class for turning a byte stream into a character stream. Data read from the source input stream is converted into characters by either a default or a provided character converter. The default encoding is taken from the "file.encoding" system property. InputStreamReader contains a buffer of bytes read from the source stream and converts these into characters as needed. The buffer size is 8K.
See Also
OutputStreamWriter

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv ByteBuffer
pack-priv CharsetDecoder
private boolean
private InputStream
pack-priv char
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
InputStreamReader(InputStream
the input stream from which to read characters.
in
)

Constructs a new InputStreamReader on the InputStream in.

public
InputStreamReader(InputStream
the InputStream from which to read characters.
in
,
final String
identifies the character converter to use.
enc
)

Constructs a new InputStreamReader on the InputStream in.

public
InputStreamReader(InputStream
the source InputStream from which to read characters.
in
,
CharsetDecoder
the CharsetDecoder used by the character conversion.
dec
)

Constructs a new InputStreamReader on the InputStream in and CharsetDecoder dec.

public
InputStreamReader(InputStream
the source InputStream from which to read characters.
in
,
Charset
the Charset that defines the character converter
charset
)

Constructs a new InputStreamReader on the InputStream in and Charset charset.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes this reader.

public String

Returns:

the name of the character converter or null if this reader is closed.
getEncoding
()

Returns the name of the encoding used to convert bytes into characters.

private boolean
public int

Returns:

the character read or -1 if the end of the reader has been reached.
read
()

Overrides java.io.Reader.read.

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.

public int

Returns:

the number of characters read or -1 if the end of the reader has been reached.
read
(char[]
the array to store the characters read.
buf
,
int
the initial position in buf to store the characters read from this reader.
offset
,
int
the maximum number of characters to read.
length
)

Implements abstract java.io.Reader.read.

Reads at most length characters from this reader and stores them at position offset in the character array buf.

public boolean

Returns:

true if the receiver will not block when read() is called, false if unknown or blocking will occur.
ready
()

Overrides java.io.Reader.ready.

Indicates whether this reader is ready to be read without blocking.

Inherited from java.io.Reader:
markmarkSupportednullReaderofreadreadreadAllAsStringreadAllLinesresetskiptransferTo

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
bytesback to summary
pack-priv ByteBuffer bytes
decoderback to summary
pack-priv CharsetDecoder decoder
endOfInputback to summary
private boolean endOfInput
inback to summary
private InputStream in
pendingback to summary
pack-priv char pending

Constructor Detail

InputStreamReaderback to summary
public InputStreamReader(InputStream in)

Constructs a new InputStreamReader on the InputStream in. This constructor sets the character converter to the encoding specified in the "file.encoding" property and falls back to ISO 8859_1 (ISO-Latin-1) if the property doesn't exist.

Parameters
in:InputStream

the input stream from which to read characters.

InputStreamReaderback to summary
public InputStreamReader(InputStream in, final String enc) throws UnsupportedEncodingException

Constructs a new InputStreamReader on the InputStream in. The character converter that is used to decode bytes into characters is identified by name by enc. If the encoding cannot be found, an UnsupportedEncodingException error is thrown.

Parameters
in:InputStream

the InputStream from which to read characters.

enc:String

identifies the character converter to use.

Exceptions
UnsupportedEncodingException:
if the encoding specified by enc cannot be found.
NullPointerException:
if enc is null.
InputStreamReaderback to summary
public InputStreamReader(InputStream in, CharsetDecoder dec)

Constructs a new InputStreamReader on the InputStream in and CharsetDecoder dec.

Parameters
in:InputStream

the source InputStream from which to read characters.

dec:CharsetDecoder

the CharsetDecoder used by the character conversion.

InputStreamReaderback to summary
public InputStreamReader(InputStream in, Charset charset)

Constructs a new InputStreamReader on the InputStream in and Charset charset.

Parameters
in:InputStream

the source InputStream from which to read characters.

charset:Charset

the Charset that defines the character converter

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes this reader. This implementation closes the source InputStream and releases all local storage.

Annotations
@Override
Exceptions
IOException:
if an error occurs attempting to close this reader.
getEncodingback to summary
public String getEncoding()

Returns the name of the encoding used to convert bytes into characters. The value null is returned if this reader has been closed.

Returns:String

the name of the character converter or null if this reader is closed.

isOpenback to summary
private boolean isOpen()
readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached. The byte value is either obtained from converting bytes in this reader's buffer or by first filling the buffer from the source InputStream and then reading from the buffer.

Returns:int

the character read or -1 if the end of the reader has been reached.

Annotations
@Override
Exceptions
IOException:
if this reader is closed or some other I/O error occurs.
readback to summary
public int read(char[] buf, int offset, int length) throws IOException

Implements abstract java.io.Reader.read.

Reads at most length characters from this reader and stores them at position offset in the character array buf. Returns the number of characters actually read or -1 if the end of the reader has been reached. The bytes are either obtained from converting bytes in this reader's buffer or by first filling the buffer from the source InputStream and then reading from the buffer.

Parameters
buf:char[]

the array to store the characters read.

offset:int

the initial position in buf to store the characters read from this reader.

length:int

the maximum number of characters to read.

Returns:int

the number of characters read or -1 if the end of the reader has been reached.

Annotations
@Override
Exceptions
IOException:
if this reader is closed or some other I/O error occurs.
IndexOutOfBoundsException:
if offset < 0 or length < 0, or if offset + length is greater than the length of buf.
readyback to summary
public boolean ready() throws IOException

Overrides java.io.Reader.ready.

Indicates whether this reader is ready to be read without blocking. If the result is true, the next read() will not block. If the result is false then this reader may or may not block when read() is called. This implementation returns true if there are bytes available in the buffer or the source stream has bytes available.

Returns:boolean

true if the receiver will not block when read() is called, false if unknown or blocking will occur.

Annotations
@Override
Exceptions
IOException:
if this reader is closed or some other I/O error occurs.