26import java.nio.ByteBuffer;
38 private volatile long nativeInstance;
39 long getNativeInstance() {
return nativeInstance; }
48 nativeInstance = ctorImpl(url, timeoutMS);
49 }
catch (
final Throwable t) {
50 System.err.println(
"ByteInStream_URL.ctor: native ctor failed: "+t.getMessage());
54 private native
long ctorImpl(
final String url,
final long timeoutMS);
62 synchronized( this ) {
63 handle = nativeInstance;
70 private static native
void dtorImpl(
final long nativeInstance);
82 clearImpl( state.
mask );
84 private native
void clearImpl(
int s);
88 return new IOState( rdStateImpl() );
90 private native
int rdStateImpl();
94 setStateImpl( state.
mask );
96 private native
void setStateImpl(
int s);
99 public native
boolean good();
102 public native
boolean eof();
108 public native
boolean bad();
117 public native
int read(
final byte[] out,
final int offset,
final int length);
120 public int read(
final ByteBuffer out) {
122 throw new IllegalArgumentException(
"out buffer not direct");
125 out.limit(out.position() + res);
128 private native
int read2Impl(Object out,
int out_offset);
131 public native
int peek(
byte[] out,
final int offset,
final int length,
final long peek_offset);
134 public native String
id();
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 a URL connection provisioned data feed.
int read(final ByteBuffer out)
Read from the source.
native long discard_next(long N)
Discard the next N bytes of the data.
native boolean eof()
Checks if end-of-file has been reached.
native boolean fail()
Checks if an error has occurred.
native int read(final byte[] out, final int offset, final int length)
Read from the source.
native boolean is_open()
Checks if the stream has an associated file.
void setState(final IOState state)
Sets state flags, by keeping its previous bits.
native boolean timeout()
Checks if a timeout (non-recoverable) has occurred.
native long tellg()
Returns the input position indicator, similar to std::basic_istream.
void close()
Close the stream if supported by the underlying mechanism and dispose the native instance.
native void closeStream()
Close the stream if supported by the underlying mechanism.
void clear(final IOState state)
Clears state flags by assignment to the given value.
native boolean good()
Checks if no error nor eof() has occurred i.e.
native boolean available(final long n)
Return whether n bytes are available in the input stream, if has_content_size() or using an asynchron...
native boolean has_content_size()
Returns true if implementation is aware of content_size(), otherwise false.
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.
native long content_size()
Returns the content_size if known.
native String id()
return the id of this data source
IOState rdState()
Returns the current state flags.
ByteInStream_URL(final String url, final long timeoutMS)
Construct a ringbuffer backed Http byte input stream.
native boolean bad()
Checks if a non-recoverable error has occurred.
Mimic std::ios_base::iostate for state functionality, see iostate_func.
Abstract byte input stream object.