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.ReaderA reader implementation with an associated writer for buffered character transfer.The PumpReader class provides a Reader implementation with an associated Writer that allows characters to be written to the writer and then read from the reader. This creates a character pipe or pump that can be used to transfer character data between different components.
This class is particularly useful for:
- Creating character streams for testing without actual I/O
- Buffering characters between producer and consumer threads
- Implementing character-based pipes with flow control
- Simulating input for terminal emulation
The PumpReader maintains internal buffers for reading and writing, with both buffers backed by the same array. It provides methods for reading characters with optional timeouts and for checking the availability of characters without blocking.
This class is used in JLine for various purposes, including implementing non-blocking readers and for testing terminal input handling without actual terminal devices.
-
-
Constructor Summary
Constructors Constructor Description PumpReader()PumpReader(int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()java.io.InputStreamcreateInputStream(java.nio.charset.Charset charset)java.io.WritergetWriter()intread()intread(char[] cbuf, int off, int len)intread(java.nio.CharBuffer target)booleanready()
-
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
-
createInputStream
public java.io.InputStream createInputStream(java.nio.charset.Charset charset)
-
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
-
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
-
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
-
-