Package org.jline.utils
Class PumpReader
- java.lang.Object
-
- java.io.Reader
-
- org.jline.utils.PumpReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class PumpReader extends java.io.Reader
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPumpReader.InputStreamprivate static classPumpReader.Writer
-
Field Summary
Fields Modifier and Type Field Description private booleanclosedprivate static intDEFAULT_BUFFER_SIZEprivate static intEOFprivate java.nio.CharBufferreadBufferprivate java.nio.CharBufferwriteBufferprivate PumpReader.Writerwriter
-
Constructor Summary
Constructors Constructor Description PumpReader()PumpReader(int bufferSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()private intcopyFromBuffer(char[] cbuf, int off, int len)java.io.InputStreamcreateInputStream(java.nio.charset.Charset charset)private voidencodeBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)(package private) voidflush()java.io.WritergetWriter()intread()intread(char[] cbuf, int off, int len)intread(java.nio.CharBuffer target)(package private) intreadBytes(java.nio.charset.CharsetEncoder encoder, byte[] b, int off, int len)(package private) voidreadBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)booleanready()private static booleanrewind(java.nio.CharBuffer buffer, java.nio.CharBuffer other)private booleanrewindReadBuffer()Attempts to find additional input by rewinding thereadBuffer.private voidrewindWriteBuffer()Attempts to find additional buffer space by rewinding thewriteBuffer.private booleanwait(java.nio.CharBuffer buffer)Waits untilbuffer.hasRemaining() == true, or it is false and the reader isclosed.private voidwaitForBufferSpace()Blocks until there is new space available for buffering or the reader is closed.private booleanwaitForInput()Blocks until input is available or the reader is closed.private booleanwaitForMoreInput()Blocks until more input is available, even ifreadBufferalready contains some chars; or until the reader is closed.(package private) voidwrite(char c)(package private) voidwrite(char[] cbuf, int off, int len)(package private) voidwrite(java.lang.String str, int off, int len)
-
-
-
Field Detail
-
EOF
private static final int EOF
- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
readBuffer
private final java.nio.CharBuffer readBuffer
-
writeBuffer
private final java.nio.CharBuffer writeBuffer
-
writer
private final PumpReader.Writer writer
-
closed
private boolean closed
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
-
createInputStream
public java.io.InputStream createInputStream(java.nio.charset.Charset charset)
-
waitForMoreInput
private boolean waitForMoreInput() throws java.io.InterruptedIOExceptionBlocks until more input is available, even ifreadBufferalready 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:
java.io.InterruptedIOException- IfObject.wait()is interrupted
-
wait
private boolean wait(java.nio.CharBuffer buffer) throws java.io.InterruptedIOExceptionWaits untilbuffer.hasRemaining() == true, or it is false and the reader isclosed.- Returns:
- true if
buffer.hasRemaining() == true; false otherwise when reader is closed - Throws:
java.io.InterruptedIOException
-
waitForInput
private boolean waitForInput() throws java.io.InterruptedIOExceptionBlocks 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:
java.io.InterruptedIOException- IfObject.wait()is interrupted
-
waitForBufferSpace
private void waitForBufferSpace() throws java.io.InterruptedIOException, ClosedExceptionBlocks until there is new space available for buffering or the reader is closed.- Throws:
java.io.InterruptedIOException- IfObject.wait()is interruptedClosedException- If the reader was closed
-
rewind
private static boolean rewind(java.nio.CharBuffer buffer, java.nio.CharBuffer other)
-
rewindReadBuffer
private boolean rewindReadBuffer()
Attempts to find additional input by rewinding thereadBuffer. Updates thewriteBufferto 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 thereadBufferto make written bytes available to the reader.
-
ready
public boolean ready()
- Overrides:
readyin classjava.io.Reader
-
available
public int available()
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
copyFromBuffer
private int copyFromBuffer(char[] cbuf, int off, int len)
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(java.nio.CharBuffer target) throws java.io.IOException- Specified by:
readin interfacejava.lang.Readable- Overrides:
readin classjava.io.Reader- Throws:
java.io.IOException
-
encodeBytes
private void encodeBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
int readBytes(java.nio.charset.CharsetEncoder encoder, byte[] b, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
readBytes
void readBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output) throws java.io.IOException- Throws:
java.io.IOException
-
write
void write(char c) throws java.io.IOException- Throws:
java.io.IOException
-
write
void write(char[] cbuf, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
write
void write(java.lang.String str, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
flush
void flush()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
-