An abstraction of data origin/sink. A stream can support up to three types of operations: reading, writing and repositioning. The user may query these capabilities before using a stream, but can also opt to proceed without pre-checking if willing to handle the error.
An internal pointer is pointing to the position within the stream where the next operation will start from. If the stream doesn't support repositioning, this pointer will only move forward.
Type | Name | Signature |
---|---|---|
method | canMark | public bool canMark() |
method | canRead | public bool canRead() |
method | canWrite | public bool canWrite() |
method | close | public void close() |
method | flush | public void flush() |
method | mark | public void mark() |
method | read | public byte read() |
method | read | public int read(byte[], int, int) |
method | reset | public void reset() |
method | skip | public int skip(int) |
method | write | public void write(byte) |
method | write | public void write(byte[], int, int) |
public bool canMark()
Whether this stream supports position-manipulating operations. This method governs mark, reset.
Returns
public bool canRead()
Whether this stream supports reading. This method governs read, skip.
Returns
public bool canWrite()
Whether this stream supports writing. This method governs write and other write methods.
Returns
public void close()
Close the stream. Once the stream is closed it cannot be re-opened.
public void flush()
Flush the stream. This will materialize all the data copy which may so far have only occurred inside in-memory data buffer, which is usually an implementation detail of the stream. It's best practice for the user to call this method between writing calls, as well as at the conclusion of data copy logic, to ensure all the data have effectively flown into the sink.
public void mark()
Mark the current position of stream. Calling reset() will move the stream pointer to the marked position.
If canMark() return false, this method will throw IOException.
public byte read()
Read one byte from the stream.
This will move forward the stream pointer by one. If canRead() return false, this method will throw IOException.
Returns
public int read(byte[] buffer, int offset, int count)
Try to read desired number of bytes from the stream into the given buffer, starting from the offset and not exceeding the buffer's capacity. This will move forward the stream pointer by the number of bytes actually read. If the stream hits the end, or the buffer runs short of room, before reading the specified count, only those bytes will be read, making the returned value less than the count argument.
This method moves forward the stream pointer by the count equal to returned value. If canRead() return false, this method will throw IOException.
Parameters
Returns
public void reset()
Move the stream pointer to the position marked by mark().
If canMark() return false, this method will throw IOException.
public int skip(int count)
Instead of reading, try to skip desired number of bytes from the stream. This will move forward the stream pointer by the number of bytes actually read. If the stream hits the end before reading the specified count, only those bytes will be skipped, making the returned value less than the count argument.
This method moves forward the stream pointer by the count equal to returned value. If canRead() return false, this method will throw IOException.
Parameters
Returns
public void write(byte data)
Write one byte to the stream.
This will move forward the stream pointer by one. If canWrite() return false, this method will throw IOException.
Parameters
public void write(byte[] buffer, int offset, int count)
Try to write desired number of bytes into the stream from the given buffer, starting from the offset and not exceeding the buffer's capacity. This will move forward the stream pointer by the number of bytes actually read. If the buffer hits the end before reading the specified count, only those bytes will be written, making the returned value less than the count argument.
This method moves forward the stream pointer by the count equal to returned value. If canWrite() return false, this method will throw IOException.
Parameters