Class ByteBufferDataInputStream
java.lang.Object
net.okapia.osid.torrefacto.transport.ByteBufferDataInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable, DataInputStream
A
DataInputStream backed by a Java
ByteBuffer. The stream consumes the buffer it is given, advancing
the buffer's position as bytes are read or skipped; the caller hands
off ownership and should not use the buffer afterward.
This class is not thread-safe.-
Constructor Summary
ConstructorsConstructorDescriptionByteBufferDataInputStream(ByteBuffer buffer) Constructs a newByteBufferDataInputStream. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests if the end of this stream has been reached.longGets the number ofbytesavailable for retrieval.voidclose()Closes this stream and frees up any allocated resources.longread(byte[] buf, long n) Reads a specified number ofbytesfrom this stream.longskip(long n) Skips a specified number ofbytesin the stream.
-
Constructor Details
-
ByteBufferDataInputStream
Constructs a newByteBufferDataInputStream. The buffer must already be flipped and ready for reading; the stream takes ownership of it.- Parameters:
buffer- a flipped byte buffer- Throws:
NullArgumentException-bufferisnull
-
-
Method Details
-
atEndOfStream
Tests if the end of this stream has been reached. This may not be a permanent condition as more data may be available at a later time as in the case of tailing a file.- Specified by:
atEndOfStreamin interfaceDataInputStream- Returns:
trueif the end of this stream has been reached,falseotherwise- Throws:
IllegalStateException- this stream has been closed
-
available
Gets the number ofbytesavailable for retrieval. The number returned by this method may be less than or equal to the total number ofbytesin this stream.- Specified by:
availablein interfaceDataInputStream- Returns:
- the number of
bytesavailable for retrieval - Throws:
IllegalStateException- this stream has been closed
-
skip
Skips a specified number ofbytesin the stream. A non-positive count skips nothing and returns zero.- Specified by:
skipin interfaceDataInputStream- Parameters:
n- the number ofbytesto skip- Returns:
- the actual number of
bytesskipped - Throws:
IllegalStateException- this stream has been closed oratEndOfStream()istrue
-
read
Reads a specified number ofbytesfrom this stream. A non-positive count reads nothing and returns zero.- Specified by:
readin interfaceDataInputStream- Parameters:
buf- the buffer in which the data is readn- the number ofbytesto read- Returns:
- the actual number of
bytesread - Throws:
IllegalStateException- this stream has been closed oratEndOfStream()istrueInvalidArgumentException- the size ofbufis less thannNullArgumentException-bufisnullOperationFailedException- unable to complete request
-
close
Closes this stream and frees up any allocated resources. Methods in this object may not be invoked after this method is called.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDataInputStream- Throws:
IllegalStateException- this stream has been closed
-