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 class
PumpReader.InputStream
private static class
PumpReader.Writer
-
Field Summary
Fields Modifier and Type Field Description private boolean
closed
private static int
DEFAULT_BUFFER_SIZE
private static int
EOF
private java.nio.CharBuffer
readBuffer
private java.nio.CharBuffer
writeBuffer
private PumpReader.Writer
writer
-
Constructor Summary
Constructors Constructor Description PumpReader()
PumpReader(int bufferSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
private int
copyFromBuffer(char[] cbuf, int off, int len)
java.io.InputStream
createInputStream(java.nio.charset.Charset charset)
private void
encodeBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)
(package private) void
flush()
java.io.Writer
getWriter()
int
read()
int
read(char[] cbuf, int off, int len)
int
read(java.nio.CharBuffer target)
(package private) int
readBytes(java.nio.charset.CharsetEncoder encoder, byte[] b, int off, int len)
(package private) void
readBytes(java.nio.charset.CharsetEncoder encoder, java.nio.ByteBuffer output)
boolean
ready()
private static boolean
rewind(java.nio.CharBuffer buffer, java.nio.CharBuffer other)
private boolean
rewindReadBuffer()
Attempts to find additional input by rewinding thereadBuffer
.private void
rewindWriteBuffer()
Attempts to find additional buffer space by rewinding thewriteBuffer
.private boolean
wait(java.nio.CharBuffer buffer)
private void
waitForBufferSpace()
Blocks until there is new space available for buffering or the reader is closed.private boolean
waitForInput()
Blocks until more input is available or the reader is closed.(package private) void
write(char c)
(package private) void
write(char[] cbuf, int off, int len)
(package private) void
write(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)
-
wait
private boolean wait(java.nio.CharBuffer buffer) throws java.io.InterruptedIOException
- Throws:
java.io.InterruptedIOException
-
waitForInput
private boolean waitForInput() throws java.io.InterruptedIOException
Blocks until more input is available or the reader is closed.- Returns:
- true if more input is available, false if the reader is closed
- Throws:
java.io.InterruptedIOException
- IfObject.wait()
is interrupted
-
waitForBufferSpace
private void waitForBufferSpace() throws java.io.InterruptedIOException, ClosedException
Blocks 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 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()
- 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
-
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:
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
-
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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Reader
- Throws:
java.io.IOException
-
-