java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, ByteBufferPositionedReadable, ByteBufferReadable, CanSetDropBehind, CanSetReadahead, CanUnbuffer, HasEnhancedByteBufferAccess, HasFileDescriptor, PositionedReadable, Seekable, IOStatisticsSource, StreamCapabilities@Private @Evolving public class CryptoInputStream extends java.io.FilterInputStream implements Seekable, PositionedReadable, ByteBufferReadable, HasFileDescriptor, CanSetDropBehind, CanSetReadahead, HasEnhancedByteBufferAccess, java.nio.channels.ReadableByteChannel, CanUnbuffer, StreamCapabilities, ByteBufferPositionedReadable, IOStatisticsSource
counter = base + pos/(algorithm blocksize); padding = pos%(algorithm blocksize);
The underlying stream offset is maintained as state.
StreamCapabilities.StreamCapabilityABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO| Constructor | Description |
|---|---|
CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
byte[] key,
byte[] iv) |
|
CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv) |
|
CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset) |
| Modifier and Type | Method | Description |
|---|---|---|
int |
available() |
|
void |
close() |
|
java.io.FileDescriptor |
getFileDescriptor() |
|
IOStatistics |
getIOStatistics() |
Return a statistics instance.
|
long |
getPos() |
Get underlying stream position.
|
java.io.InputStream |
getWrappedStream() |
|
boolean |
hasCapability(java.lang.String capability) |
Query the stream for a specific capability.
|
boolean |
isOpen() |
|
void |
mark(int readLimit) |
|
boolean |
markSupported() |
|
int |
read() |
|
int |
read(byte[] b,
int off,
int len) |
Decryption is buffer based.
|
int |
read(long position,
byte[] buffer,
int offset,
int length) |
Positioned read.
|
int |
read(long position,
java.nio.ByteBuffer buf) |
Positioned read using
ByteBuffers. |
int |
read(java.nio.ByteBuffer buf) |
ByteBuffer read.
|
java.nio.ByteBuffer |
read(ByteBufferPool bufferPool,
int maxLength,
java.util.EnumSet<ReadOption> opts) |
Get a ByteBuffer containing file data.
|
void |
readFully(long position,
byte[] buffer) |
Read number of bytes equal to the length of the buffer, from a given
position within a file.
|
void |
readFully(long position,
byte[] buffer,
int offset,
int length) |
Positioned read fully.
|
void |
readFully(long position,
java.nio.ByteBuffer buf) |
Positioned readFully using
ByteBuffers. |
void |
releaseBuffer(java.nio.ByteBuffer buffer) |
Release a ByteBuffer which was created by the enhanced ByteBuffer read
function.
|
void |
reset() |
|
void |
seek(long pos) |
Seek to a position.
|
boolean |
seekToNewSource(long targetPos) |
Seeks a different copy of the data.
|
void |
setDropBehind(java.lang.Boolean dropCache) |
Configure whether the stream should drop the cache.
|
void |
setReadahead(java.lang.Long readahead) |
Set the readahead on this stream.
|
long |
skip(long n) |
Skip n bytes
|
void |
unbuffer() |
Reduce the buffering.
|
nullInputStream, readAllBytes, readNBytes, readNBytes, transferToclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmaxReadSizeForVectorReads, minSeekForVectorReads, readVectoredpublic CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv)
throws java.io.IOException
java.io.IOExceptionpublic CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
int bufferSize,
byte[] key,
byte[] iv,
long streamOffset)
throws java.io.IOException
java.io.IOExceptionpublic CryptoInputStream(java.io.InputStream in,
CryptoCodec codec,
byte[] key,
byte[] iv)
throws java.io.IOException
java.io.IOExceptionpublic java.io.InputStream getWrappedStream()
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
outBuffer, then read it out of this buffer.
If there is no data in outBuffer, then read more from the
underlying stream and do the decryption.read in class java.io.FilterInputStreamb - the buffer into which the decrypted data is read.off - the buffer offset.len - the maximum number of decrypted data bytes to read.java.io.IOException - raised on errors performing I/O.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in interface java.io.Closeableclose in class java.io.FilterInputStreamjava.io.IOExceptionpublic int read(long position,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
read in interface PositionedReadableposition - position within filebuffer - destination bufferoffset - offset in the bufferlength - number of bytes to readjava.io.IOException - IO problems.public int read(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
ByteBuffers. This method is thread-safe.read in interface ByteBufferPositionedReadableposition - position within filebuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - if there is some error performing the readpublic void readFully(long position,
java.nio.ByteBuffer buf)
throws java.io.IOException
ByteBuffers. This method is thread-safe.readFully in interface ByteBufferPositionedReadableposition - position within filebuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - if there is some error performing the readjava.io.EOFException - the end of the data was reached before
the read operation completedByteBufferPositionedReadable.read(long, ByteBuffer)public void readFully(long position,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
readFully in interface PositionedReadableposition - position within filebuffer - destination bufferoffset - offset in the bufferlength - number of bytes to readjava.io.IOException - IO problems.java.io.EOFException - the end of the data was reached before
the read operation completedpublic void readFully(long position,
byte[] buffer)
throws java.io.IOException
PositionedReadablereadFully in interface PositionedReadableposition - position within filebuffer - destination bufferjava.io.IOException - IO problems.java.io.EOFException - the end of the data was reached before
the read operation completedpublic void seek(long pos)
throws java.io.IOException
public long skip(long n)
throws java.io.IOException
skip in class java.io.FilterInputStreamjava.io.IOExceptionpublic long getPos()
throws java.io.IOException
public int read(java.nio.ByteBuffer buf)
throws java.io.IOException
read in interface ByteBufferReadableread in interface java.nio.channels.ReadableByteChannelbuf - the ByteBuffer to receive the results of the read operation.java.io.IOException - if there is some error performing the readpublic int available()
throws java.io.IOException
available in class java.io.FilterInputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.FilterInputStreampublic void mark(int readLimit)
mark in class java.io.FilterInputStreampublic void reset()
throws java.io.IOException
reset in class java.io.FilterInputStreamjava.io.IOExceptionpublic boolean seekToNewSource(long targetPos)
throws java.io.IOException
SeekableseekToNewSource in interface SeekabletargetPos - target position.java.io.IOException - raised on errors performing I/O.public java.nio.ByteBuffer read(ByteBufferPool bufferPool, int maxLength, java.util.EnumSet<ReadOption> opts) throws java.io.IOException, java.lang.UnsupportedOperationException
HasEnhancedByteBufferAccessread in interface HasEnhancedByteBufferAccessbufferPool - If this is non-null, it will be used to create a fallback
ByteBuffer when the stream itself cannot create one.maxLength - The maximum length of buffer to return. We may return a buffer
which is shorter than this.opts - Options to use when reading.java.io.IOException - if there was an error reading.java.lang.UnsupportedOperationException - if factory was null,
and we needed an external byte buffer.public void releaseBuffer(java.nio.ByteBuffer buffer)
HasEnhancedByteBufferAccessreleaseBuffer in interface HasEnhancedByteBufferAccessbuffer - The ByteBuffer to release.public void setReadahead(java.lang.Long readahead)
throws java.io.IOException,
java.lang.UnsupportedOperationException
CanSetReadaheadsetReadahead in interface CanSetReadaheadreadahead - The readahead to use. null means to use the default.java.io.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting readahead.java.lang.UnsupportedOperationExceptionpublic void setDropBehind(java.lang.Boolean dropCache)
throws java.io.IOException,
java.lang.UnsupportedOperationException
CanSetDropBehindsetDropBehind in interface CanSetDropBehinddropCache - Whether to drop the cache. null means to use the
default value.java.io.IOException - If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting the drop-behind.java.lang.UnsupportedOperationExceptionpublic java.io.FileDescriptor getFileDescriptor()
throws java.io.IOException
getFileDescriptor in interface HasFileDescriptorjava.io.IOException - raised on errors performing I/O.public int read()
throws java.io.IOException
read in class java.io.FilterInputStreamjava.io.IOExceptionpublic boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic void unbuffer()
CanUnbufferunbuffer in interface CanUnbufferpublic boolean hasCapability(java.lang.String capability)
StreamCapabilitieshasCapability in interface StreamCapabilitiescapability - string to query the stream support for.public IOStatistics getIOStatistics()
IOStatisticsSource
It is not a requirement that the same instance is returned every time.
IOStatisticsSource.
If the object implementing this is Closeable, this method may return null if invoked on a closed object, even if it returns a valid instance when called earlier.
getIOStatistics in interface IOStatisticsSourceCopyright © 2008–2025 Apache Software Foundation. All rights reserved.