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 intprivate intprivate ByteBufferprivate SeekableByteChannelprivate Closeableprivate static final Closeable(package private) static final intprivate final ByteBufferprivate final byte[]Fields inherited from class ImageInputStreamImpl
bitOffset, byteOrder, flushedPos, streamPos -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)Constructs aBufferedChannelImageInputStreamthat will read from a givenCache.Constructs aBufferedChannelImageInputStreamthat will read from a givenFile.BufferedChannelImageInputStream(FileInputStream inputStream) Constructs aBufferedChannelImageInputStreamthat will read from a givenFileInputStream.Constructs aBufferedChannelImageInputStreamthat will read from a givenRandomAccessFile.Constructs aBufferedChannelImageInputStreamthat will read from a givenSeekableByteChannel.privateBufferedChannelImageInputStream(SeekableByteChannel channel, boolean closeChannelOnClose) Constructs aBufferedChannelImageInputStreamthat will read from a givenPath. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanvoidclose()private booleanvoidflushBefore(long pos) longlength()intread()intread(byte[] bytes, int offset, int length) private intreadBuffered(byte[] bytes, int offset, int length) private intreadDirect(byte[] bytes, int offset, int length) intreadInt()longreadLong()shortvoidseek(long position) voidsetByteOrder(ByteOrder byteOrder) Methods inherited from class 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 aBufferedChannelImageInputStreamthat will read from a givenFile.- Parameters:
file- aFileto read from.- Throws:
IllegalArgumentException- iffileisnull.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 aBufferedChannelImageInputStreamthat will read from a givenPath.- Parameters:
file- aPathto read from.- Throws:
IllegalArgumentException- iffileisnull.UnsupportedOperationException- if thefileis 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 aBufferedChannelImageInputStreamthat will read from a givenRandomAccessFile.- Parameters:
file- aRandomAccessFileto read from.- Throws:
IllegalArgumentException- iffileisnull.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStreamthat will read from a givenFileInputStream.Closing this stream will not close the
FileInputStream.- Parameters:
inputStream- aFileInputStreamto read from.- Throws:
IllegalArgumentException- ifinputStreamisnull.
-
BufferedChannelImageInputStream
Constructs aBufferedChannelImageInputStreamthat will read from a givenSeekableByteChannel.Closing this stream will not close the
SeekableByteChannel.- Parameters:
channel- aSeekableByteChannelto read from.- Throws:
IllegalArgumentException- ifchannelisnull.
-
BufferedChannelImageInputStream
BufferedChannelImageInputStream(Cache cache) Constructs aBufferedChannelImageInputStreamthat will read from a givenCache.Closing this stream will close the
Cache.- Parameters:
cache- aSeekableByteChannelto read from.- Throws:
IllegalArgumentException- ifchannelisnull.
-
BufferedChannelImageInputStream
-
-
Method Details
-
fillBuffer
- Throws:
IOException
-
bufferEmpty
private boolean bufferEmpty() -
setByteOrder
- Specified by:
setByteOrderin interfaceImageInputStream- Overrides:
setByteOrderin classImageInputStreamImpl
-
read
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Throws:
IOException
-
read
- Specified by:
readin interfaceImageInputStream- Specified by:
readin classImageInputStreamImpl- Throws:
IOException
-
readDirect
- Throws:
IOException
-
readBuffered
private int readBuffered(byte[] bytes, int offset, int length) -
length
public long length()- Specified by:
lengthin interfaceImageInputStream- Overrides:
lengthin classImageInputStreamImpl
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceImageInputStream- Overrides:
closein classImageInputStreamImpl- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Specified by:
readShortin interfaceImageInputStream- Overrides:
readShortin classImageInputStreamImpl- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Specified by:
readIntin interfaceImageInputStream- Overrides:
readIntin classImageInputStreamImpl- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Specified by:
readLongin interfaceImageInputStream- Overrides:
readLongin classImageInputStreamImpl- Throws:
IOException
-
seek
- Specified by:
seekin interfaceImageInputStream- Overrides:
seekin classImageInputStreamImpl- Throws:
IOException
-
flushBefore
- Specified by:
flushBeforein interfaceImageInputStream- Overrides:
flushBeforein classImageInputStreamImpl- Throws:
IOException
-