public final class ReadStream extends java.io.InputStream implements LockableStream
Dynamic streams, like tcp and http will properly flush writes before reading input. And random access streams, like RandomAccessFile, can use the same API as normal streams.
Most applications will use the Path routines to create their own streams. Specialized applications, like servers, need the capability of recycling streams.
Modifier and Type | Class and Description |
---|---|
class |
ReadStream.StreamReader |
Modifier and Type | Field and Description |
---|---|
static int |
READ_TIMEOUT |
static int |
ZERO_COPY_SIZE |
Constructor and Description |
---|
ReadStream()
Creates an uninitialized stream.
|
ReadStream(StreamImpl source)
Creates a stream and initializes with a specified source.
|
ReadStream(StreamImpl source,
WriteStream sibling)
Creates a stream and initializes with a specified source.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Compatibility with InputStream.
|
boolean |
canRead()
Returns true if the stream allows reading.
|
void |
clearPosition()
Clears the position for statistics cases like a socket stream.
|
void |
clearRead()
Clears the read buffer.
|
void |
clearReadTime()
Returns the last read-time.
|
void |
close()
Close the stream.
|
int |
fillBuffer()
Fills the buffer from the underlying stream.
|
boolean |
fillIfLive(long timeout)
Fills the buffer with a timed read, testing for the end of file.
|
int |
fillWithTimeout(long timeout)
Fills the buffer with a non-blocking read.
|
java.lang.Object |
getAttribute(java.lang.String name)
Returns a named attribute.
|
java.util.Iterator<java.lang.String> |
getAttributeNames()
Lists all named attributes.
|
int |
getAvailable()
Returns an estimate of the available bytes.
|
byte[] |
getBuffer() |
int |
getBufferAvailable()
Returns true if data in the buffer is available.
|
java.lang.String |
getEncoding()
Returns the mime-encoding currently read.
|
int |
getLength() |
int |
getOffset() |
Path |
getPath()
Returns the Path which opened this stream.
|
long |
getPosition()
Returns the read position.
|
java.io.Reader |
getReader()
Returns a Reader reading to this stream.
|
long |
getReadTime()
Returns the last read-time.
|
WriteStream |
getSibling() |
StreamImpl |
getSource()
Returns the underlying source for the stream.
|
java.lang.String |
getURL()
Returns the user path which opened this stream.
|
java.lang.String |
getUserPath()
Returns the user path which opened this stream.
|
void |
init(StreamImpl source,
WriteStream sibling)
Initializes the stream with a given source.
|
boolean |
lock(boolean shared,
boolean block)
Lock the shared advisory lock.
|
void |
pushFilter(StreamFilter filter)
Pushes a filter on the top of the stream stack.
|
int |
read()
Returns the next byte or -1 if at the end of file.
|
int |
read(byte[] buf,
int offset,
int length)
Reads into a byte array.
|
int |
read(char[] buf,
int offset,
int length)
Reads into a character buffer from the stream.
|
int |
read(CharBuffer buf,
int length)
Reads characters from the stream, appending to the character buffer.
|
int |
readAll(byte[] buf,
int offset,
int length)
Reads into a byte array.
|
int |
readAll(char[] buf,
int offset,
int length)
Reads into a character buffer from the stream.
|
int |
readAll(CharBuffer buf,
int length)
Reads characters from the stream, appending to the character buffer.
|
int |
readChar()
Reads a character from the stream, returning -1 on end of file.
|
int |
readInt()
Reads a 4-byte network encoded integer
|
java.lang.String |
readLine()
Reads a line, returning a string.
|
int |
readLine(char[] buf,
int length)
Reads a line into the character buffer.
|
int |
readLine(char[] buf,
int length,
boolean isChop)
Reads a line into the character buffer.
|
boolean |
readLine(CharBuffer cb)
Reads a line into the character buffer.
|
boolean |
readLine(CharBuffer cb,
boolean isChop)
Reads a line into the character buffer.
|
java.lang.String |
readLineNoChop()
Reads a line, returning a string.
|
java.lang.String |
readln()
Reads a line from the stream, returning a string.
|
boolean |
readln(CharBuffer cb)
Fills the buffer with the next line from the input stream.
|
long |
readLong()
Reads an 8-byte network encoded long
|
boolean |
readNonBlock()
Fills the buffer with a non-blocking read.
|
int |
readUTF8ByByteLength(char[] buffer,
int offset,
int byteLength)
Reads a utf-8 string
|
void |
removeAttribute(java.lang.String name)
Removes a named attribute.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets a named attribute.
|
void |
setDisableClose(boolean disableClose)
Disables close.
|
void |
setDisableCloseSource(boolean disableClose)
Disables closing of the underlying source.
|
void |
setEnableReadTime(boolean isEnable)
Enables setting the read time on every reads.
|
void |
setEncoding(java.lang.String encoding)
Sets the current read encoding.
|
void |
setLength(int length) |
void |
setOffset(int offset) |
void |
setPath(Path path)
Sets a path name associated with the stream.
|
boolean |
setPosition(long pos)
Sets the current read position.
|
void |
setReuseBuffer(boolean reuse) |
void |
setSibling(WriteStream sibling) |
void |
setSource(StreamImpl source) |
long |
skip(long n)
Skips the next
n bytes. |
java.lang.String |
toString()
Returns a printable representation of the read stream.
|
boolean |
unlock()
Unlock the advisory lock.
|
void |
unread()
Unreads the last byte.
|
boolean |
waitForRead()
Waits for data to be available.
|
void |
writeToStream(java.io.OutputStream os)
Copies this stream to the output stream.
|
void |
writeToStream(java.io.OutputStream os,
int len)
Writes
len |
void |
writeToWriter(java.io.Writer out)
Copies this stream to the output stream.
|
public static int ZERO_COPY_SIZE
public static final int READ_TIMEOUT
public ReadStream()
init
to initialize.public ReadStream(StreamImpl source)
source
- Underlying source for the stream.public ReadStream(StreamImpl source, WriteStream sibling)
source
- Underlying source for the stream.sibling
- Sibling write stream.public void init(StreamImpl source, WriteStream sibling)
source
- Underlying source for the stream.sibling
- Sibling write streampublic void setSibling(WriteStream sibling)
public WriteStream getSibling()
public StreamImpl getSource()
public void setSource(StreamImpl source)
public void setReuseBuffer(boolean reuse)
public void pushFilter(StreamFilter filter)
filter
- the filter to be added.public byte[] getBuffer()
public int getOffset()
public void setOffset(int offset)
public int getLength()
public void setLength(int length)
public long getPosition()
public long getReadTime()
public void clearReadTime()
public void setEnableReadTime(boolean isEnable)
public boolean setPosition(long pos) throws java.io.IOException
java.io.IOException
public void clearPosition()
public boolean canRead()
public void clearRead()
public int getAvailable() throws java.io.IOException
java.io.IOException
public int getBufferAvailable() throws java.io.IOException
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public final int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public final void unread()
public final boolean waitForRead() throws java.io.IOException
java.io.IOException
public long skip(long n) throws java.io.IOException
n
bytes.skip
in class java.io.InputStream
n
- bytes to skip.java.io.IOException
public final int read(byte[] buf, int offset, int length) throws java.io.IOException
read
may return less than
the maximum bytes even if more bytes are available to read.read
in class java.io.InputStream
buf
- byte arrayoffset
- offset into the byte array to start readinglength
- maximum byte allowed to read.java.io.IOException
public int readAll(byte[] buf, int offset, int length) throws java.io.IOException
readAll
will always read
length
bytes, blocking if necessary, until the end of
file is reached.buf
- byte arrayoffset
- offset into the byte array to start readinglength
- maximum byte allowed to read.java.io.IOException
public void setEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
encoding
- name of the read encodingjava.io.UnsupportedEncodingException
public java.lang.String getEncoding()
public final int readChar() throws java.io.IOException
java.io.IOException
public final int read(char[] buf, int offset, int length) throws java.io.IOException
buf
- character buffer to filloffset
- starting offset into the character bufferlength
- maximum number of characters to readjava.io.IOException
public int readAll(char[] buf, int offset, int length) throws java.io.IOException
length
characters will always be read until the end of file is reached.buf
- character buffer to filloffset
- starting offset into the character bufferlength
- maximum number of characters to readjava.io.IOException
public int read(CharBuffer buf, int length) throws java.io.IOException
buf
- character buffer to filllength
- maximum number of characters to readjava.io.IOException
public int readAll(CharBuffer buf, int length) throws java.io.IOException
length
characters will always be read until the end of
file.buf
- character buffer to filllength
- maximum number of characters to readjava.io.IOException
public final java.lang.String readln() throws java.io.IOException
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
java.io.IOException
public java.lang.String readLineNoChop() throws java.io.IOException
java.io.IOException
public final boolean readln(CharBuffer cb) throws java.io.IOException
java.io.IOException
public final boolean readLine(CharBuffer cb) throws java.io.IOException
buf
- character buffer to filljava.io.IOException
public final boolean readLine(CharBuffer cb, boolean isChop) throws java.io.IOException
buf
- character buffer to filljava.io.IOException
public final int readLine(char[] buf, int length) throws java.io.IOException
buf
- character buffer to fill.length
- number of characters to fill.java.io.IOException
public final int readLine(char[] buf, int length, boolean isChop) throws java.io.IOException
buf
- character buffer to fill.length
- number of characters to fill.java.io.IOException
public int readInt() throws java.io.IOException
java.io.IOException
public long readLong() throws java.io.IOException
java.io.IOException
public int readUTF8ByByteLength(char[] buffer, int offset, int byteLength) throws java.io.IOException
java.io.IOException
public void writeToStream(java.io.OutputStream os) throws java.io.IOException
os
- destination stream.java.io.IOException
public void writeToStream(java.io.OutputStream os, int len) throws java.io.IOException
len bytes to the output stream from this stream.
os
- destination stream.len
- bytes to write.java.io.IOException
public void writeToWriter(java.io.Writer out) throws java.io.IOException
out
- destination writerjava.io.IOException
public int fillBuffer() throws java.io.IOException
java.io.IOException
public boolean readNonBlock() throws java.io.IOException
java.io.IOException
public int fillWithTimeout(long timeout) throws java.io.IOException
timeout
- the timeout in milliseconds for the next datajava.io.IOException
public boolean fillIfLive(long timeout) throws java.io.IOException
timeout
- the timeout in milliseconds for the next datajava.io.IOException
public void setDisableClose(boolean disableClose)
public void setDisableCloseSource(boolean disableClose)
public final void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
public java.lang.Object getAttribute(java.lang.String name) throws java.io.IOException
java.io.IOException
public java.util.Iterator<java.lang.String> getAttributeNames() throws java.io.IOException
java.io.IOException
public void setAttribute(java.lang.String name, java.lang.Object value) throws java.io.IOException
java.io.IOException
public void removeAttribute(java.lang.String name) throws java.io.IOException
java.io.IOException
public Path getPath()
public java.lang.String getUserPath()
Parsing routines typically use this for error reporting.
public java.lang.String getURL()
Parsing routines typically use this for error reporting.
public void setPath(Path path)
public java.io.Reader getReader()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean lock(boolean shared, boolean block)
LockableStream
lock
in interface LockableStream
public boolean unlock()
LockableStream
unlock
in interface LockableStream