26import java.nio.ByteBuffer;
40 private volatile long nativeInstance;
41 long getNativeInstance() {
return nativeInstance; }
53 nativeInstance = ctorImpl1(path);
54 }
catch (
final Throwable t) {
55 System.err.println(
"ByteInStream_File.ctor: native ctor failed: "+t.getMessage());
59 private static native
long ctorImpl1(
final String path);
72 nativeInstance = ctorImpl2(dirfd, path);
73 }
catch (
final Throwable t) {
74 System.err.println(
"ByteInStream_File.ctor: native ctor failed: "+t.getMessage());
78 private static native
long ctorImpl2(
final int dirfd,
final String path);
90 nativeInstance = ctorImpl3(
fd);
91 }
catch (
final Throwable t) {
92 System.err.println(
"ByteInStream_File.ctor: native ctor failed: "+t.getMessage());
96 private static native
long ctorImpl3(
final int fd);
104 synchronized( this ) {
105 handle = nativeInstance;
112 private static native
void dtorImpl(
final long nativeInstance);
124 clearImpl( state.
mask );
126 private native
void clearImpl(
int s);
133 public native
int fd();
137 return new IOState( rdStateImpl() );
139 private native
int rdStateImpl();
143 setStateImpl( state.
mask );
145 private native
void setStateImpl(
int s);
151 public native
boolean eof();
157 public native
boolean bad();
166 public native
int read(
final byte[] out,
final int offset,
final int length);
169 public int read(
final ByteBuffer out) {
171 throw new IllegalArgumentException(
"out buffer not direct");
174 out.limit(out.position() + res);
177 private native
int read2Impl(Object out,
int out_offset);
180 public native
int peek(
byte[] out,
final int offset,
final int length,
final long peek_offset);
183 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...
File based byte input stream, including named file descriptor.
native int read(final byte[] out, final int offset, final int length)
Read from the source.
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 String id()
return the id of this data source
native boolean good()
Checks if no error nor eof() has occurred i.e.
void setState(final IOState state)
Sets state flags, by keeping its previous bits.
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 boolean bad()
Checks if a non-recoverable error has occurred.
void clear(final IOState state)
Clears state flags by assignment to the given value.
int read(final ByteBuffer out)
Read from the source.
native boolean timeout()
Checks if a timeout (non-recoverable) has occurred.
ByteInStream_File(final int dirfd, final String path)
Construct a stream based byte input stream from filesystem path and parent directory file descriptor.
void close()
Close the stream if supported by the underlying mechanism and dispose the native instance.
native boolean fail()
Checks if an error has occurred.
native long content_size()
Returns the content_size if known.
native int fd()
Returns the file descriptor if is_open(), otherwise -1 for no file descriptor.
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.
ByteInStream_File(final String path)
Construct a Stream-Based byte input stream from filesystem path.
native long tellg()
Returns the input position indicator, similar to std::basic_istream.
native boolean is_open()
Checks if the stream has an associated file.
native boolean has_content_size()
Returns true if implementation is aware of content_size(), otherwise false.
native void closeStream()
Close the stream if supported by the underlying mechanism.
ByteInStream_File(final int fd)
Construct a stream based byte input stream by duplicating given file descriptor.
Mimic std::ios_base::iostate for state functionality, see iostate_func.
Abstract byte input stream object.