Package com.twelvemonkeys.imageio.stream
Class BufferedChannelImageInputStream
java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
com.twelvemonkeys.imageio.stream.BufferedChannelImageInputStream
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
,ImageInputStream
A buffered
ImageInputStream
that is backed by a SeekableByteChannel
and provides greatly improved performance
compared to FileCacheImageInputStream
or MemoryCacheImageInputStream
for shorter reads, like single byte or bit reads.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
private int
private int
private ByteBuffer
private SeekableByteChannel
private Closeable
private static final Closeable
(package private) static final int
private final ByteBuffer
private final byte[]
Fields inherited from class javax.imageio.stream.ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Constructs aBufferedChannelImageInputStream
that will read from a givenCache
.Constructs aBufferedChannelImageInputStream
that will read from a givenFile
.BufferedChannelImageInputStream
(FileInputStream inputStream) Constructs aBufferedChannelImageInputStream
that will read from a givenFileInputStream
.Constructs aBufferedChannelImageInputStream
that will read from a givenRandomAccessFile
.Constructs aBufferedChannelImageInputStream
that will read from a givenSeekableByteChannel
.private
BufferedChannelImageInputStream
(SeekableByteChannel channel, boolean closeChannelOnClose) Constructs aBufferedChannelImageInputStream
that will read from a givenPath
. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
void
close()
private boolean
void
flushBefore
(long pos) long
length()
int
read()
int
read
(byte[] bytes, int offset, int length) private int
readBuffered
(byte[] bytes, int offset, int length) private int
readDirect
(byte[] bytes, int offset, int length) int
readInt()
long
readLong()
short
void
seek
(long position) void
setByteOrder
(ByteOrder byteOrder) Methods inherited from class javax.imageio.stream.ImageInputStreamImpl
checkClosed, finalize, flush, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readLine, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, setBitOffset, skipBytes, skipBytes
-
Field Details
-
CLOSEABLE_STUB
-
DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZE- See Also:
-
byteBuffer
-
buffer
private byte[] buffer -
bufferPos
private int bufferPos -
bufferLimit
private int bufferLimit -
integralCache
-
integralCacheArray
private final byte[] integralCacheArray -
channel
-
closeable
-
-
Constructor Details
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStream
that will read from a givenFile
.- Parameters:
file
- aFile
to read from.- Throws:
IllegalArgumentException
- iffile
isnull
.SecurityException
- if a security manager is installed, and it denies read access to the file.IOException
- if an I/O error occurs while opening the file.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStream
that will read from a givenPath
.- Parameters:
file
- aPath
to read from.- Throws:
IllegalArgumentException
- iffile
isnull
.UnsupportedOperationException
- if thefile
is associated with a provider that does not support creating file channels.IOException
- if an I/O error occurs while opening the file.SecurityException
- if a security manager is installed, and it denies read access to the file.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStream
that will read from a givenRandomAccessFile
.- Parameters:
file
- aRandomAccessFile
to read from.- Throws:
IllegalArgumentException
- iffile
isnull
.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStream
that will read from a givenFileInputStream
.Closing this stream will not close the
FileInputStream
.- Parameters:
inputStream
- aFileInputStream
to read from.- Throws:
IllegalArgumentException
- ifinputStream
isnull
.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStream
that will read from a givenSeekableByteChannel
.Closing this stream will not close the
SeekableByteChannel
.- Parameters:
channel
- aSeekableByteChannel
to read from.- Throws:
IllegalArgumentException
- ifchannel
isnull
.
-
BufferedChannelImageInputStream
BufferedChannelImageInputStream(Cache cache) Constructs aBufferedChannelImageInputStream
that will read from a givenCache
.Closing this stream will close the
Cache
.- Parameters:
cache
- aSeekableByteChannel
to read from.- Throws:
IllegalArgumentException
- ifchannel
isnull
.
-
BufferedChannelImageInputStream
-
-
Method Details
-
fillBuffer
- Throws:
IOException
-
bufferEmpty
private boolean bufferEmpty() -
setByteOrder
- Specified by:
setByteOrder
in interfaceImageInputStream
- Overrides:
setByteOrder
in classImageInputStreamImpl
-
read
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in classImageInputStreamImpl
- Throws:
IOException
-
read
- Specified by:
read
in interfaceImageInputStream
- Specified by:
read
in classImageInputStreamImpl
- Throws:
IOException
-
readDirect
- Throws:
IOException
-
readBuffered
private int readBuffered(byte[] bytes, int offset, int length) -
length
public long length()- Specified by:
length
in interfaceImageInputStream
- Overrides:
length
in classImageInputStreamImpl
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceImageInputStream
- Overrides:
close
in classImageInputStreamImpl
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Specified by:
readShort
in interfaceImageInputStream
- Overrides:
readShort
in classImageInputStreamImpl
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Specified by:
readInt
in interfaceImageInputStream
- Overrides:
readInt
in classImageInputStreamImpl
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Specified by:
readLong
in interfaceImageInputStream
- Overrides:
readLong
in classImageInputStreamImpl
- Throws:
IOException
-
seek
- Specified by:
seek
in interfaceImageInputStream
- Overrides:
seek
in classImageInputStreamImpl
- Throws:
IOException
-
flushBefore
- Specified by:
flushBefore
in interfaceImageInputStream
- Overrides:
flushBefore
in classImageInputStreamImpl
- Throws:
IOException
-