26import java.nio.ByteBuffer;
34 private volatile long nativeInstance;
35 long getNativeInstance() {
return nativeInstance; }
44 nativeInstance = ctorImpl(id_name, timeoutMS);
45 }
catch (
final Throwable t) {
46 System.err.println(
"ByteInStream_Feed.ctor: native ctor failed: "+t.getMessage());
50 private native
long ctorImpl(
final String id_name,
final long timeoutMS);
58 synchronized( this ) {
59 handle = nativeInstance;
66 private static native
void dtorImpl(
final long nativeInstance);
78 clearImpl( state.
mask );
80 private native
void clearImpl(
int s);
84 return new IOState( rdStateImpl() );
86 private native
int rdStateImpl();
90 setStateImpl( state.
mask );
92 private native
void setStateImpl(
int s);
95 public native
boolean good();
98 public native
boolean eof();
104 public native
boolean bad();
113 public native
int read(
final byte[] out,
final int offset,
final int length);
116 public int read(
final ByteBuffer out) {
118 throw new IllegalArgumentException(
"out buffer not direct");
121 out.limit(out.position() + res);
124 private native
int read2Impl(Object out,
int out_offset);
127 public native
int peek(
byte[] out,
final int offset,
final int length,
final long peek_offset);
130 public native String
id();
167 public boolean write(
final byte[] in,
final int offset,
final int length,
final long timeoutMS) {
168 return write0Impl(in, offset, length, timeoutMS);
170 private native
boolean write0Impl(
final byte[] in,
final int offset,
final int length,
final long timeoutMS);
184 public boolean write(
final byte[] in,
final int offset,
final int length) {
185 return write1Impl(in, offset, length);
187 private native
boolean write1Impl(
final byte[] in,
final int offset,
final int length);
200 public boolean write(
final ByteBuffer in) {
202 throw new IllegalArgumentException(
"out buffer not direct");
205 in.limit(in.position());
211 private native
boolean write2Impl(ByteBuffer out,
int out_offset,
int out_limit);
Utility methods allowing easy java.nio.Buffer manipulations.
static boolean isDirect(final Object buf)
Helper routine to tell whether a buffer is direct or not.
static long getDirectBufferByteOffset(final Object buf)
Helper routine to get the Buffer byte offset by taking into account the Buffer position and the under...
Ringbuffer-Based byte input stream with an externally provisioned data feed.
native void interruptReader()
Interrupt a potentially blocked reader.
native boolean eof()
Checks if end-of-file has been reached.
native long content_size()
Returns the content_size if known.
void setState(final IOState state)
Sets state flags, by keeping its previous bits.
native boolean has_content_size()
Returns true if implementation is aware of content_size(), otherwise false.
native boolean bad()
Checks if a non-recoverable error has occurred.
native void set_eof(final int result)
Set end-of-data (EOS), i.e.
native boolean is_open()
Checks if the stream has an associated file.
native boolean good()
Checks if no error nor eof() has occurred i.e.
boolean write(final ByteBuffer in)
Write given bytes to the async ringbuffer.
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.
boolean write(final byte[] in, final int offset, final int length)
Write given bytes to the async ringbuffer.
void clear(final IOState state)
Clears state flags by assignment to the given value.
int read(final ByteBuffer out)
Read from the source.
void close()
Close the stream if supported by the underlying mechanism and dispose the native instance.
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.
IOState rdState()
Returns the current state flags.
native int read(final byte[] out, final int offset, final int length)
Read from the source.
native long discard_next(long N)
Discard the next N bytes of the data.
native boolean fail()
Checks if an error has occurred.
native void set_content_size(final long size)
Set known content size, informal only.
native void closeStream()
Close the stream if supported by the underlying mechanism.
native long tellg()
Returns the input position indicator, similar to std::basic_istream.
native String id()
return the id of this data source
native boolean timeout()
Checks if a timeout (non-recoverable) has occurred.
ByteInStream_Feed(final String id_name, final long timeoutMS)
Construct a ringbuffer backed externally provisioned byte input stream.
native boolean available(final long n)
Return whether n bytes are available in the input stream, if has_content_size() or using an asynchron...
Mimic std::ios_base::iostate for state functionality, see iostate_func.
Abstract byte input stream object.