jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
Abstract byte input stream object. More...
Public Member Functions | |
boolean | is_open () |
Checks if the stream has an associated file. More... | |
void | closeStream () |
Close the stream if supported by the underlying mechanism. More... | |
void | close () |
Close the stream if supported by the underlying mechanism and dispose the native instance. More... | |
boolean | available (long n) |
Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source. More... | |
int | read (byte out[], final int offset, final int length) |
Read from the source. More... | |
int | read (ByteBuffer out) |
Read from the source. More... | |
int | peek (byte out[], final int offset, final int length, final long peek_offset) |
Read from the source but do not modify the internal offset. More... | |
String | id () |
return the id of this data source More... | |
long | discard_next (long N) |
Discard the next N bytes of the data. More... | |
long | tellg () |
Returns the input position indicator, similar to std::basic_istream. More... | |
boolean | has_content_size () |
Returns true if implementation is aware of content_size(), otherwise false. More... | |
long | content_size () |
Returns the content_size if known. More... | |
String | toString () |
Public Member Functions inherited from org.jau.io.IOStateFunc | |
void | clear (final IOState state) |
Clears state flags by assignment to the given value. More... | |
IOState | rdState () |
Returns the current state flags. More... | |
void | setState (final IOState state) |
Sets state flags, by keeping its previous bits. More... | |
boolean | good () |
Checks if no error nor eof() has occurred i.e. More... | |
boolean | eof () |
Checks if end-of-file has been reached. More... | |
boolean | fail () |
Checks if an error has occurred. More... | |
boolean | bad () |
Checks if a non-recoverable error has occurred. More... | |
boolean | timeout () |
Checks if a timeout (non-recoverable) has occurred. More... | |
Abstract byte input stream object.
Its specializations utilize a native C++ implementation derived from jau::io::ByteInStream
.
The byte input stream can originate from a local source w/o delay, remote URL like http connection or even from another thread feeding the input buffer.
Both latter asynchronous resources may expose blocking properties in available().
Asynchronous resources benefit from knowing their content size, as their available() implementation may avoid blocking and waiting for requested bytes available if the stream is already beyond its scope.
All method implementations are of noexcept
.
One may use fail() to detect whether an error has occurred, while end_of_data() not only covers the end-of-stream (EOS) case but includes fail().
Definition at line 53 of file ByteInStream.java.
boolean org.jau.io.ByteInStream.available | ( | long | n | ) |
Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source.
If !has_content_size() and not being an asynchronous source, !end_of_data() is returned.
Method may be blocking when using an asynchronous source up until the requested bytes are available.
A subsequent call to read() shall return immediately with at least the requested numbers of bytes available, if has_content_size() or using an asynchronous source.
See details of the implementing class.
n | byte count to wait for |
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
void org.jau.io.ByteInStream.close | ( | ) |
Close the stream if supported by the underlying mechanism and dispose the native instance.
Instance is unusable after having this method called.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
void org.jau.io.ByteInStream.closeStream | ( | ) |
Close the stream if supported by the underlying mechanism.
Native instance will not be disposed.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
long org.jau.io.ByteInStream.content_size | ( | ) |
Returns the content_size if known.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
long org.jau.io.ByteInStream.discard_next | ( | long | N | ) |
Discard the next N bytes of the data.
N | the number of bytes to discard |
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
boolean org.jau.io.ByteInStream.has_content_size | ( | ) |
Returns true if implementation is aware of content_size(), otherwise false.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
String org.jau.io.ByteInStream.id | ( | ) |
return the id of this data source
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
boolean org.jau.io.ByteInStream.is_open | ( | ) |
Checks if the stream has an associated file.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
int org.jau.io.ByteInStream.peek | ( | byte | out[], |
final int | offset, | ||
final int | length, | ||
final long | peek_offset | ||
) |
Read from the source but do not modify the internal offset.
Consecutive calls to peek() will return portions of the source starting at the same position.
out | the byte array to write the output to |
offset | offset to byte array to read into |
length | number of in bytes to read into starting at offset |
peek_offset | the offset into the stream to read at |
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
int org.jau.io.ByteInStream.read | ( | byte | out[], |
final int | offset, | ||
final int | length | ||
) |
Read from the source.
Moves the internal offset so that every call to read will return a new portion of the source.
Use available() to try to wait for a certain amount of bytes available.
This method shall only block until min(available, length)
bytes are transfered.
See details of the implementing class.
out | the byte array to write the result to |
offset | offset to byte array to read into |
length | the length of the byte array out |
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
int org.jau.io.ByteInStream.read | ( | ByteBuffer | out | ) |
Read from the source.
Moves the internal offset so that every call to read will return a new portion of the source.
Use available() to try to wait for a certain amount of bytes available.
This method shall only block until min(available, length)
bytes are transfered.
See details of the implementing class.
out | the direct ByteBuffer to write the result starting at its position up to its capacity . Limit will be set to position + read-bytes. |
limit
- position
, i.e. remaining
.Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
long org.jau.io.ByteInStream.tellg | ( | ) |
Returns the input position indicator, similar to std::basic_istream.
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.
String org.jau.io.ByteInStream.toString | ( | ) |
Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.