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

Ringbuffer-Based byte input stream with an externally provisioned data feed. More...

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

Public Member Functions

 ByteInStream_Feed (final String id_name, final long timeoutMS)
 Construct a ringbuffer backed externally provisioned byte input stream. More...
 
native 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...
 
void finalize ()
 
native boolean is_open ()
 Checks if the stream has an associated file. More...
 
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...
 
native boolean good ()
 Checks if no error nor eof() has occurred i.e. More...
 
native boolean eof ()
 Checks if end-of-file has been reached. More...
 
native boolean fail ()
 Checks if an error has occurred. More...
 
native boolean bad ()
 Checks if a non-recoverable error has occurred. More...
 
native boolean timeout ()
 Checks if a timeout (non-recoverable) has occurred. More...
 
native boolean available (final long n)
 Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source. More...
 
native int read (final byte[] out, final int offset, final int length)
 Read from the source. More...
 
int read (final ByteBuffer out)
 Read from the source. More...
 
native 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...
 
native String id ()
 return the id of this data source More...
 
native long discard_next (long N)
 Discard the next N bytes of the data. More...
 
native long tellg ()
 Returns the input position indicator, similar to std::basic_istream. More...
 
native boolean has_content_size ()
 Returns true if implementation is aware of content_size(), otherwise false. More...
 
native long content_size ()
 Returns the content_size if known. More...
 
native void interruptReader ()
 Interrupt a potentially blocked reader. More...
 
boolean write (final byte[] in, final int offset, final int length, final long timeoutMS)
 Write given bytes to the async ringbuffer using explicit given timeout. More...
 
boolean write (final byte[] in, final int offset, final int length)
 Write given bytes to the async ringbuffer. More...
 
boolean write (final ByteBuffer in)
 Write given bytes to the async ringbuffer. More...
 
native void set_content_size (final long size)
 Set known content size, informal only. More...
 
native void set_eof (final int result)
 Set end-of-data (EOS), i.e. More...
 
native String toString ()
 
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 ()
 
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

Ringbuffer-Based byte input stream with an externally provisioned data feed.

Instance uses the native C++ object jau::io::ByteInStream_Feed.

Definition at line 33 of file ByteInStream_Feed.java.

Constructor & Destructor Documentation

◆ ByteInStream_Feed()

org.jau.io.ByteInStream_Feed.ByteInStream_Feed ( final String  id_name,
final long  timeoutMS 
)

Construct a ringbuffer backed externally provisioned byte input stream.

Parameters
id_namearbitrary identifier for this instance
timeoutMSmaximum duration in milliseconds to wait @ check_available() and write(), zero waits infinitely

Definition at line 42 of file ByteInStream_Feed.java.

Member Function Documentation

◆ available()

native boolean org.jau.io.ByteInStream_Feed.available ( final 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

Implements org.jau.io.ByteInStream.

◆ bad()

native boolean org.jau.io.ByteInStream_Feed.bad ( )

Checks if a non-recoverable error has occurred.

Implements org.jau.io.IOStateFunc.

◆ clear()

void org.jau.io.ByteInStream_Feed.clear ( final IOState  state)

Clears state flags by assignment to the given value.

Implements org.jau.io.IOStateFunc.

Definition at line 77 of file ByteInStream_Feed.java.

◆ close()

void org.jau.io.ByteInStream_Feed.close ( )

Close the stream if supported by the underlying mechanism and dispose the native instance.

Instance is unusable after having this method called.

Close the stream if supported by the underlying mechanism and dispose the native instance.Instance is unusable after having this method called.

Implements org.jau.io.ByteInStream.

Definition at line 56 of file ByteInStream_Feed.java.

Here is the caller graph for this function:

◆ closeStream()

native void org.jau.io.ByteInStream_Feed.closeStream ( )

Close the stream if supported by the underlying mechanism.

Native instance will not be disposed.

Close the stream if supported by the underlying mechanism.Native instance will not be disposed.

Implements org.jau.io.ByteInStream.

◆ content_size()

native long org.jau.io.ByteInStream_Feed.content_size ( )

Returns the content_size if known.

See also
has_content_size()

Implements org.jau.io.ByteInStream.

◆ discard_next()

native long org.jau.io.ByteInStream_Feed.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

Implements org.jau.io.ByteInStream.

◆ eof()

native boolean org.jau.io.ByteInStream_Feed.eof ( )

Checks if end-of-file has been reached.

Implements org.jau.io.IOStateFunc.

◆ fail()

native boolean org.jau.io.ByteInStream_Feed.fail ( )

Checks if an error has occurred.

Implements org.jau.io.IOStateFunc.

◆ finalize()

void org.jau.io.ByteInStream_Feed.finalize ( )

Definition at line 69 of file ByteInStream_Feed.java.

Here is the call graph for this function:

◆ good()

native boolean org.jau.io.ByteInStream_Feed.good ( )

Checks if no error nor eof() has occurred i.e.

I/O operations are available.

Implements org.jau.io.IOStateFunc.

◆ has_content_size()

native boolean org.jau.io.ByteInStream_Feed.has_content_size ( )

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

See also
content_size()

Implements org.jau.io.ByteInStream.

◆ id()

native String org.jau.io.ByteInStream_Feed.id ( )

return the id of this data source

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

Implements org.jau.io.ByteInStream.

◆ interruptReader()

native void org.jau.io.ByteInStream_Feed.interruptReader ( )

Interrupt a potentially blocked reader.

Call this method if intended to abort streaming and to interrupt the reader thread's potentially blocked check_available() call, i.e. done at set_eof()

See also
set_eof()

◆ is_open()

native boolean org.jau.io.ByteInStream_Feed.is_open ( )

Checks if the stream has an associated file.

Implements org.jau.io.ByteInStream.

◆ peek()

native int org.jau.io.ByteInStream_Feed.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

Implements org.jau.io.ByteInStream.

◆ rdState()

IOState org.jau.io.ByteInStream_Feed.rdState ( )

Returns the current state flags.

Method is marked virtual to allow implementations with asynchronous resources to determine or update the current iostate.

Method is used throughout all query members and setstate(), hence they all will use the updated state from a potential override implementation.

Implements org.jau.io.IOStateFunc.

Definition at line 83 of file ByteInStream_Feed.java.

◆ read() [1/2]

native int org.jau.io.ByteInStream_Feed.read ( final 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

Implements org.jau.io.ByteInStream.

◆ read() [2/2]

int org.jau.io.ByteInStream_Feed.read ( final 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

Implements org.jau.io.ByteInStream.

Definition at line 116 of file ByteInStream_Feed.java.

Here is the call graph for this function:

◆ set_content_size()

native void org.jau.io.ByteInStream_Feed.set_content_size ( final long  size)

Set known content size, informal only.

Parameters
content_lengththe content size in bytes

◆ set_eof()

native void org.jau.io.ByteInStream_Feed.set_eof ( final int  result)

Set end-of-data (EOS), i.e.

when feeder completed provisioning bytes.

Implementation issues interruptReader() to unblock a potentially blocked reader thread.

Parameters
resultshould be either -1 for FAILED or 1 for SUCCESS.
See also
interruptReader()

◆ setState()

void org.jau.io.ByteInStream_Feed.setState ( final IOState  state)

Sets state flags, by keeping its previous bits.

Implements org.jau.io.IOStateFunc.

Definition at line 89 of file ByteInStream_Feed.java.

◆ tellg()

native long org.jau.io.ByteInStream_Feed.tellg ( )

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

Returns
number of bytes read so far.

Implements org.jau.io.ByteInStream.

◆ timeout()

native boolean org.jau.io.ByteInStream_Feed.timeout ( )

Checks if a timeout (non-recoverable) has occurred.

Implements org.jau.io.IOStateFunc.

◆ toString()

native String org.jau.io.ByteInStream_Feed.toString ( )

◆ write() [1/3]

boolean org.jau.io.ByteInStream_Feed.write ( final byte[]  in,
final int  offset,
final int  length 
)

Write given bytes to the async ringbuffer.

Wait up to timeout duration set in constructor until ringbuffer space is available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
inthe byte array to transfer to the async ringbuffer
offsetoffset to in byte array to write
lengthnumber of in bytes to write starting at offset
Returns
true if successful, otherwise false on timeout or stopped feeder and subsequent calls to good() will return false.

Definition at line 184 of file ByteInStream_Feed.java.

◆ write() [2/3]

boolean org.jau.io.ByteInStream_Feed.write ( final byte[]  in,
final int  offset,
final int  length,
final long  timeoutMS 
)

Write given bytes to the async ringbuffer using explicit given timeout.

Wait up to explicit given timeout duration until ringbuffer space is available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
nbyte count to wait for
inthe byte array to transfer to the async ringbuffer
lengththe length of the byte array in
timeoutexplicit given timeout for async ringbuffer put operation
Returns
true if successful, otherwise false on timeout or stopped feeder and subsequent calls to good() will return false.

Definition at line 167 of file ByteInStream_Feed.java.

◆ write() [3/3]

boolean org.jau.io.ByteInStream_Feed.write ( final ByteBuffer  in)

Write given bytes to the async ringbuffer.

Wait up to timeout duration set in constructor until ringbuffer space is available, where fractions_i64::zero waits infinitely.

This method is blocking.

Parameters
inthe direct ByteBuffer to transfer to the async ringbuffer starting at its position up to its limit. Limit will be reset to position.
Returns
true if successful, otherwise false on timeout or stopped feeder and subsequent calls to good() will return false.

Definition at line 200 of file ByteInStream_Feed.java.

Here is the call graph for this function:

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