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

public Class PumpReader

extends Reader
Class Inheritance
Imports
java.io.IOException, .InterruptedIOException, .Reader, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, .CoderResult, .CodingErrorAction

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private static final int
private static final int
private final CharBuffer
private final CharBuffer
private final PumpReader.Writer
Inherited from java.io.Reader:
lock

Constructor Summary

AccessConstructor and Description
public
public
PumpReader(int bufferSize)

Method Summary

Modifier and TypeMethod and Description
public synchronized int
public synchronized void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

private int
copyFromBuffer(char[] cbuf, int off, int len)

public InputStream
private void
pack-priv synchronized void
public Writer
public synchronized int
read()

Overrides java.io.Reader.read.

Reads a single character.

public synchronized int
read(char[] cbuf, int off, int len)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

public synchronized int
read(CharBuffer target)

Overrides java.io.Reader.read.

Implements java.lang.Readable.read.

Attempts to read characters into the specified character buffer.

pack-priv synchronized int
readBytes(CharsetEncoder encoder, byte[] b, int off, int len)

pack-priv synchronized void
public synchronized boolean
ready()

Overrides java.io.Reader.ready.

Tells whether this stream is ready to be read.

private static boolean
rewind(CharBuffer buffer, CharBuffer other)

private boolean

Returns:

If more input is available
rewindReadBuffer
()

Attempts to find additional input by rewinding the readBuffer.

private void
rewindWriteBuffer()

Attempts to find additional buffer space by rewinding the writeBuffer.

private boolean

Returns:

true if buffer.hasRemaining() == true; false otherwise when reader is closed
wait
(CharBuffer buffer)

Waits until buffer.hasRemaining() == true, or it is false and the reader is closed.

private void
waitForBufferSpace()

Blocks until there is new space available for buffering or the reader is closed.

private boolean

Returns:

true if input is available, false if no input is available and the reader is closed
waitForInput
()

Blocks until input is available or the reader is closed.

private boolean

Returns:

true if more input is available, false if no additional input is available and the reader is closed
waitForMoreInput
()

Blocks until more input is available, even if readBuffer already contains some chars; or until the reader is closed.

pack-priv synchronized void
write(char c)

pack-priv synchronized void
write(char[] cbuf, int off, int len)

pack-priv synchronized void
write(String str, int off, int len)

Inherited from java.io.Reader:
markmarkSupportednullReaderofreadreadAllAsStringreadAllLinesresetskiptransferTo

Field Detail

closedback to summary
private boolean closed
DEFAULT_BUFFER_SIZEback to summary
private static final int DEFAULT_BUFFER_SIZE
EOFback to summary
private static final int EOF
readBufferback to summary
private final CharBuffer readBuffer
writeBufferback to summary
private final CharBuffer writeBuffer
writerback to summary
private final PumpReader.Writer writer

Constructor Detail

PumpReaderback to summary
public PumpReader()
PumpReaderback to summary
public PumpReader(int bufferSize)

Method Detail

availableback to summary
public synchronized int available()
closeback to summary
public synchronized void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
copyFromBufferback to summary
private int copyFromBuffer(char[] cbuf, int off, int len)
createInputStreamback to summary
public InputStream createInputStream(Charset charset)
encodeBytesback to summary
private void encodeBytes(CharsetEncoder encoder, ByteBuffer output) throws IOException
flushback to summary
pack-priv synchronized void flush()
getWriterback to summary
public Writer getWriter()
readback to summary
public synchronized int read() throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public synchronized int read(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public synchronized int read(CharBuffer target) throws IOException

Overrides java.io.Reader.read.

Implements java.lang.Readable.read.

Doc from java.io.Reader.read.

Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed. If the length of the specified character buffer is zero, then no characters will be read and zero will be returned.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
readBytesback to summary
pack-priv synchronized int readBytes(CharsetEncoder encoder, byte[] b, int off, int len) throws IOException
readBytesback to summary
pack-priv synchronized void readBytes(CharsetEncoder encoder, ByteBuffer output) throws IOException
readyback to summary
public synchronized boolean ready()

Overrides java.io.Reader.ready.

Doc from java.io.Reader.ready.

Tells whether this stream is ready to be read.

Annotations
@Override
rewindback to summary
private static boolean rewind(CharBuffer buffer, CharBuffer other)
rewindReadBufferback to summary
private boolean rewindReadBuffer()

Attempts to find additional input by rewinding the readBuffer. Updates the writeBuffer to make read bytes available for buffering.

Returns:boolean

If more input is available

rewindWriteBufferback to summary
private void rewindWriteBuffer()

Attempts to find additional buffer space by rewinding the writeBuffer. Updates the readBuffer to make written bytes available to the reader.

waitback to summary
private boolean wait(CharBuffer buffer) throws InterruptedIOException

Waits until buffer.hasRemaining() == true, or it is false and the reader is closed.

Returns:boolean

true if buffer.hasRemaining() == true; false otherwise when reader is closed

waitForBufferSpaceback to summary
private void waitForBufferSpace() throws InterruptedIOException, ClosedException

Blocks until there is new space available for buffering or the reader is closed.

Exceptions
InterruptedIOException:
If wait() is interrupted
ClosedException:
If the reader was closed
waitForInputback to summary
private boolean waitForInput() throws InterruptedIOException

Blocks until input is available or the reader is closed.

Returns:boolean

true if input is available, false if no input is available and the reader is closed

Exceptions
InterruptedIOException:
If wait() is interrupted
waitForMoreInputback to summary
private boolean waitForMoreInput() throws InterruptedIOException

Blocks until more input is available, even if readBuffer already contains some chars; or until the reader is closed.

Returns:boolean

true if more input is available, false if no additional input is available and the reader is closed

Exceptions
InterruptedIOException:
If wait() is interrupted
writeback to summary
pack-priv synchronized void write(char c) throws IOException
writeback to summary
pack-priv synchronized void write(char[] cbuf, int off, int len) throws IOException
writeback to summary
pack-priv synchronized void write(String str, int off, int len) throws IOException
jdk.internal.org.jline.utils back to summary

private Class PumpReader.InputStream

extends InputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final CharsetEncoder
private final PumpReader

Constructor Summary

AccessConstructor and Description
private
InputStream(PumpReader reader, Charset charset)

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private int
copyFromBuffer(byte[] b, int off, int len)

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

private boolean
Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

bufferback to summary
private final ByteBuffer buffer
encoderback to summary
private final CharsetEncoder encoder
readerback to summary
private final PumpReader reader

Constructor Detail

InputStreamback to summary
private InputStream(PumpReader reader, Charset charset)

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
copyFromBufferback to summary
private int copyFromBuffer(byte[] b, int off, int len)
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readUsingBufferback to summary
private boolean readUsingBuffer() throws IOException
jdk.internal.org.jline.utils back to summary

private Class PumpReader.Writer

extends Writer
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final PumpReader
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

public void
write(int c)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(char[] cbuf, int off, int len)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

public void
write(String str, int off, int len)

Overrides java.io.Writer.write.

Writes a portion of a string.

Inherited from java.io.Writer:
appendappendappendnullWriterwritewrite

Field Detail

readerback to summary
private final PumpReader reader

Constructor Detail

Writerback to summary
private Writer(PumpReader reader)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs