Package org.jline.utils
Class PumpReader
java.lang.Object
java.io.Reader
org.jline.utils.PumpReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private static final int
private static final int
private final CharBuffer
private final CharBuffer
private final PumpReader.Writer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
private int
copyFromBuffer
(char[] cbuf, int off, int len) createInputStream
(Charset charset) private void
encodeBytes
(CharsetEncoder encoder, ByteBuffer output) (package private) void
flush()
int
read()
int
read
(char[] cbuf, int off, int len) int
read
(CharBuffer target) (package private) int
readBytes
(CharsetEncoder encoder, byte[] b, int off, int len) (package private) void
readBytes
(CharsetEncoder encoder, ByteBuffer output) boolean
ready()
private static boolean
rewind
(CharBuffer buffer, CharBuffer other) private boolean
Attempts to find additional input by rewinding thereadBuffer
.private void
Attempts to find additional buffer space by rewinding thewriteBuffer
.private boolean
wait
(CharBuffer buffer) Waits untilbuffer.hasRemaining() == true
, or it is false and the reader isclosed
.private void
Blocks until there is new space available for buffering or the reader is closed.private boolean
Blocks until input is available or the reader is closed.private boolean
Blocks until more input is available, even ifreadBuffer
already contains some chars; or until the reader is closed.(package private) void
write
(char c) (package private) void
write
(char[] cbuf, int off, int len) (package private) void
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, reset, skip, transferTo
-
Field Details
-
EOF
private static final int EOF- See Also:
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE- See Also:
-
readBuffer
-
writeBuffer
-
writer
-
closed
private boolean closed
-
-
Constructor Details
-
PumpReader
public PumpReader() -
PumpReader
public PumpReader(int bufferSize)
-
-
Method Details
-
getWriter
-
createInputStream
-
waitForMoreInput
Blocks until more input is available, even ifreadBuffer
already contains some chars; or until the reader is closed.- Returns:
- true if more input is available, false if no additional input is available and the reader is closed
- Throws:
InterruptedIOException
- IfObject.wait()
is interrupted
-
wait
Waits untilbuffer.hasRemaining() == true
, or it is false and the reader isclosed
.- Returns:
- true if
buffer.hasRemaining() == true
; false otherwise when reader is closed - Throws:
InterruptedIOException
-
waitForInput
Blocks until input is available or the reader is closed.- Returns:
- true if input is available, false if no input is available and the reader is closed
- Throws:
InterruptedIOException
- IfObject.wait()
is interrupted
-
waitForBufferSpace
Blocks until there is new space available for buffering or the reader is closed.- Throws:
InterruptedIOException
- IfObject.wait()
is interruptedClosedException
- If the reader was closed
-
rewind
-
rewindReadBuffer
private boolean rewindReadBuffer()Attempts to find additional input by rewinding thereadBuffer
. Updates thewriteBuffer
to make read bytes available for buffering.- Returns:
- If more input is available
-
rewindWriteBuffer
private void rewindWriteBuffer()Attempts to find additional buffer space by rewinding thewriteBuffer
. Updates thereadBuffer
to make written bytes available to the reader. -
ready
public boolean ready() -
available
public int available() -
read
- Overrides:
read
in classReader
- Throws:
IOException
-
copyFromBuffer
private int copyFromBuffer(char[] cbuf, int off, int len) -
read
- Specified by:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in interfaceReadable
- Overrides:
read
in classReader
- Throws:
IOException
-
encodeBytes
- Throws:
IOException
-
readBytes
- Throws:
IOException
-
readBytes
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
flush
void flush() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-