PipedReader | API reference | Android Developers (original) (raw)
open class PipedReader : Reader
Piped character-input streams.
Summary
Public constructors |
---|
PipedReader() Creates a PipedReader so that it is not yet connected. |
PipedReader(pipeSize: Int) Creates a PipedReader so that it is not yet connected and uses the specified pipe size for the pipe's buffer. |
PipedReader(src: PipedWriter!) Creates a PipedReader so that it is connected to the piped writer src. |
PipedReader(src: PipedWriter!, pipeSize: Int) Creates a PipedReader so that it is connected to the piped writer src and uses the specified pipe size for the pipe's buffer. |
Public methods | |
---|---|
open Unit | close() Closes this piped stream and releases any system resources associated with the stream. |
open Unit | connect(src: PipedWriter!) Causes this piped reader to be connected to the piped writer src. |
open Int | read() Reads the next character of data from this piped stream. |
open Int | read(cbuf: CharArray!, off: Int, len: Int) Reads up to len characters of data from this piped stream into an array of characters. |
open Boolean | ready() Tell whether this stream is ready to be read. |
Inherited functions |
---|
From class Reader Unit mark(readAheadLimit: Int) Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation. Boolean markSupported() Tells whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method. Reader! nullReader() Returns a new Reader that reads no characters. The returned stream is initially open. The stream is closed by calling the close() method. Subsequent calls to close() have no effect. While the stream is open, the read(), read(char[]), read(char[], int, int), read(Charbuffer), ready(), skip(long), and transferTo() methods all behave as if end of stream has been reached. After the stream has been closed, these methods all throw IOException. The markSupported() method returns false. The mark() and reset() methods throw an IOException. The object used to synchronize operations on the returned Reader is not specified. Int read(cbuf: CharArray!) Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. Int read(target: CharBuffer!) Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed. Unit reset() Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark(). Long skip(n: Long) Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. Long transferTo(out: Writer!) Reads all characters from this reader and writes the characters to the given writer in the order that they are read. On return, this reader will be at end of the stream. This method does not close either reader or writer. This method may block indefinitely reading from the reader, or writing to the writer. The behavior for the case where the reader and/or writer is asynchronously closed, or the thread interrupted during the transfer, is highly reader and writer specific, and therefore not specified. If an I/O error occurs reading from the reader or writing to the writer, then it may do so after some characters have been read or written. Consequently the reader may not be at end of the stream and one, or both, streams may be in an inconsistent state. It is strongly recommended that both streams be promptly closed if an I/O error occurs. |
Inherited properties |
---|
From class Reader Any! lock The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method. |
Public constructors
PipedReader
PipedReader()
Creates a PipedReader
so that it is not yet connected. It must be connected to a PipedWriter
before being used.
PipedReader
PipedReader(pipeSize: Int)
Creates a PipedReader
so that it is not yet [connected](#connect%28java.io.PipedWriter%29)
and uses the specified pipe size for the pipe's buffer. It must be connected to a PipedWriter
before being used.
Parameters | |
---|---|
pipeSize | Int: the size of the pipe's buffer. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException | if pipeSize <= 0. |
PipedReader
PipedReader(src: PipedWriter!)
Creates a PipedReader
so that it is connected to the piped writer src
. Data written to src
will then be available as input from this stream.
Parameters | |
---|---|
src | PipedWriter!: the stream to connect to. |
Exceptions | |
---|---|
java.io.IOException | if an I/O error occurs. |
PipedReader
PipedReader(
src: PipedWriter!,
pipeSize: Int)
Creates a PipedReader
so that it is connected to the piped writer src
and uses the specified pipe size for the pipe's buffer. Data written to src
will then be available as input from this stream.
Parameters | |
---|---|
src | PipedWriter!: the stream to connect to. |
pipeSize | Int: the size of the pipe's buffer. |
Exceptions | |
---|---|
java.io.IOException | if an I/O error occurs. |
java.lang.IllegalArgumentException | if pipeSize <= 0. |
Public methods
close
open fun close(): Unit
Closes this piped stream and releases any system resources associated with the stream.
Exceptions | |
---|---|
java.lang.Exception | if this resource cannot be closed |
java.io.IOException | if an I/O error occurs |
java.io.IOException | if an I/O error occurs. |
connect
open fun connect(src: PipedWriter!): Unit
Causes this piped reader to be connected to the piped writer src
. If this object is already connected to some other piped writer, an IOException
is thrown.
If src
is an unconnected piped writer and snk
is an unconnected piped reader, they may be connected by either the call:
snk.connect(src)
or the call:
src.connect(snk)
The two calls have the same effect.
Parameters | |
---|---|
src | PipedWriter!: The piped writer to connect to. |
Exceptions | |
---|---|
java.io.IOException | if an I/O error occurs. |
read
open fun read(): Int
Reads the next character of data from this piped stream. If no character is available because the end of the stream has been reached, the value -1
is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
Return | |
---|---|
Int | the next character of data, or -1 if the end of the stream is reached. |
Exceptions | |
---|---|
java.io.IOException | if the pipe is broken, unconnected, closed, or an I/O error occurs. |
read
open fun read(
cbuf: CharArray!,
off: Int,
len: Int
): Int
Reads up to len
characters of data from this piped stream into an array of characters. Less than len
characters will be read if the end of the data stream is reached or if len
exceeds the pipe's buffer size. This method blocks until at least one character of input is available.
Parameters | |
---|---|
cbuf | CharArray!: the buffer into which the data is read. |
off | Int: the start offset of the data. |
len | Int: the maximum number of characters read. |
Return | |
---|---|
Int | the total number of characters read into the buffer, or -1 if there is no more data because the end of the stream has been reached. |
Exceptions | |
---|---|
java.io.IOException | if the pipe is broken, unconnected, closed, or an I/O error occurs. |
java.lang.IndexOutOfBoundsException | If off is negative, or len is negative, or len is greater than cbuf.length - off |
ready
open fun ready(): Boolean
Tell whether this stream is ready to be read. A piped character stream is ready if the circular buffer is not empty.
Return | |
---|---|
Boolean | True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. |
Exceptions | |
---|---|
java.io.IOException | if the pipe is broken, unconnected, or closed. |