jaulib v1.1.2-115-g39e35fd
Jau Support Library (C++, Java, ..)
Public Member Functions | List of all members
org.jau.io.ByteInStream Interface Reference

Abstract byte input stream object. More...

Inheritance diagram for org.jau.io.ByteInStream:
Collaboration diagram for org.jau.io.ByteInStream:

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...
 

Detailed Description

Abstract byte input stream object.

Its specializations utilize a native C++ implementation derived from jau::io::ByteInStream.

ByteInStream Properties

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().

See also
ByteInStream Properties

Definition at line 53 of file ByteInStream.java.

Member Function Documentation

◆ available()

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.

Parameters
nbyte count to wait for
Returns
true if n bytes are available, otherwise false
See also
has_content_size()
read()
ByteInStream Properties

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

Here is the caller graph for this function:

◆ close()

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.

◆ closeStream()

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.

◆ content_size()

long org.jau.io.ByteInStream.content_size ( )

Returns the content_size if known.

See also
has_content_size()

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

Here is the caller graph for this function:

◆ discard_next()

long org.jau.io.ByteInStream.discard_next ( long  N)

Discard the next N bytes of the data.

Parameters
Nthe number of bytes to discard
Returns
number of bytes actually discarded

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

◆ has_content_size()

boolean org.jau.io.ByteInStream.has_content_size ( )

Returns true if implementation is aware of content_size(), otherwise false.

See also
content_size()

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

Here is the caller graph for this function:

◆ id()

String org.jau.io.ByteInStream.id ( )

return the id of this data source

Returns
std::string representing the id of this data source

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

◆ is_open()

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.

◆ peek()

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.

Parameters
outthe byte array to write the output to
offsetoffset to byte array to read into
lengthnumber of in bytes to read into starting at offset
peek_offsetthe offset into the stream to read at
Returns
length in bytes that was actually read and put into out

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

◆ read() [1/2]

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.

Parameters
outthe byte array to write the result to
offsetoffset to byte array to read into
lengththe length of the byte array out
Returns
length in bytes that was actually read and put into out
See also
available()
ByteInStream Properties

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

Here is the caller graph for this function:

◆ read() [2/2]

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.

Parameters
outthe direct ByteBuffer to write the result starting at its position up to its capacity. Limit will be set to position + read-bytes.
Returns
length in bytes that was actually read and put into out, equal to its limit - position, i.e. remaining.
See also
available()
ByteInStream Properties

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

◆ tellg()

long org.jau.io.ByteInStream.tellg ( )

Returns the input position indicator, similar to std::basic_istream.

Returns
number of bytes read so far.

Implemented in org.jau.io.ByteInStream_Feed, org.jau.io.ByteInStream_File, and org.jau.io.ByteInStream_URL.

◆ toString()

String org.jau.io.ByteInStream.toString ( )

The documentation for this interface was generated from the following file: