Class ChannelInput
- java.lang.Object
-
- org.apache.commons.crypto.stream.input.ChannelInput
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Input
public class ChannelInput extends java.lang.Object implements Input
The ChannelInput class takes aReadableByteChannel
object and wraps it asInput
object acceptable byCryptoInputStream
.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
buf
private java.nio.channels.ReadableByteChannel
channel
private static int
SKIP_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description ChannelInput(java.nio.channels.ReadableByteChannel channel)
Constructs theChannelInput
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Overrides theInput.available()
.void
close()
Overrides theInput.seek(long)
.private java.nio.ByteBuffer
getSkipBuf()
Gets the skip buffer.int
read(long position, byte[] buffer, int offset, int length)
Overrides theInput.read(long, byte[], int, int)
.int
read(java.nio.ByteBuffer dst)
Overrides theInput.read(ByteBuffer)
.void
seek(long position)
Overrides theInput.seek(long)
.long
skip(long n)
Overrides theInput.skip(long)
.
-
-
-
Field Detail
-
SKIP_BUFFER_SIZE
private static final int SKIP_BUFFER_SIZE
- See Also:
- Constant Field Values
-
buf
private java.nio.ByteBuffer buf
-
channel
private final java.nio.channels.ReadableByteChannel channel
-
-
Constructor Detail
-
ChannelInput
public ChannelInput(java.nio.channels.ReadableByteChannel channel)
Constructs theChannelInput
.- Parameters:
channel
- the ReadableByteChannel object.
-
-
Method Detail
-
available
public int available() throws java.io.IOException
Overrides theInput.available()
. Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
-
close
public void close() throws java.io.IOException
Overrides theInput.seek(long)
. Closes this input and releases any system resources associated with the under layer input.
-
getSkipBuf
private java.nio.ByteBuffer getSkipBuf()
Gets the skip buffer.- Returns:
- the buffer.
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
Overrides theInput.read(ByteBuffer)
. Reads a sequence of bytes from input into the given buffer.
-
read
public int read(long position, byte[] buffer, int offset, int length) throws java.io.IOException
Overrides theInput.read(long, byte[], int, int)
. Reads up tolen
bytes of data from the input stream into an array of bytes. An attempt is made to read as many aslen
bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.- Specified by:
read
in interfaceInput
- Parameters:
position
- the given position within a stream.buffer
- the buffer into which the data is read.offset
- the start offset in array buffer.length
- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached. - Throws:
java.io.IOException
- if an I/O error occurs.
-
seek
public void seek(long position) throws java.io.IOException
Overrides theInput.seek(long)
. Seeks to the given offset from the start of the stream. The next read() will be from that location.
-
skip
public long skip(long n) throws java.io.IOException
Overrides theInput.skip(long)
. Skips over and discardsn
bytes of data from this input stream.
-
-