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
A 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 int
available()
void
close()
java.io.InputStream
createInputStream(java.nio.charset.Charset charset)
java.io.Writer
getWriter()
int
read()
int
read(char[] cbuf, int off, int len)
int
read(java.nio.CharBuffer target)
boolean
ready()
-
-
-
Method Detail
-
getWriter
public java.io.Writer getWriter()
-
createInputStream
public java.io.InputStream createInputStream(java.nio.charset.Charset charset)
-
ready
public boolean ready()
- Overrides:
ready
in classjava.io.Reader
-
available
public int available()
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException
- Specified by:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read(java.nio.CharBuffer target) throws java.io.IOException
- Specified by:
read
in interfacejava.lang.Readable
- Overrides:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Reader
- Throws:
java.io.IOException
-
-