Package com.twelvemonkeys.imageio.stream
Class BufferedChannelImageInputStream
- java.lang.Object
-
- javax.imageio.stream.ImageInputStreamImpl
-
- com.twelvemonkeys.imageio.stream.BufferedChannelImageInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.DataInput,java.lang.AutoCloseable,javax.imageio.stream.ImageInputStream
final class BufferedChannelImageInputStream extends javax.imageio.stream.ImageInputStreamImplA bufferedImageInputStreamthat is backed by aSeekableByteChanneland provides greatly improved performance compared toFileCacheImageInputStreamorMemoryCacheImageInputStreamfor shorter reads, like single byte or bit reads.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufferprivate intbufferLimitprivate intbufferPosprivate java.nio.ByteBufferbyteBufferprivate java.nio.channels.SeekableByteChannelchannelprivate java.io.Closeablecloseableprivate static java.io.CloseableCLOSEABLE_STUB(package private) static intDEFAULT_BUFFER_SIZEprivate java.nio.ByteBufferintegralCacheprivate byte[]integralCacheArray
-
Constructor Summary
Constructors Modifier Constructor Description (package private)BufferedChannelImageInputStream(Cache cache)Constructs aBufferedChannelImageInputStreamthat will read from a givenCache.BufferedChannelImageInputStream(java.io.File file)Constructs aBufferedChannelImageInputStreamthat will read from a givenFile.BufferedChannelImageInputStream(java.io.FileInputStream inputStream)Constructs aBufferedChannelImageInputStreamthat will read from a givenFileInputStream.BufferedChannelImageInputStream(java.io.RandomAccessFile file)Constructs aBufferedChannelImageInputStreamthat will read from a givenRandomAccessFile.BufferedChannelImageInputStream(java.nio.channels.SeekableByteChannel channel)Constructs aBufferedChannelImageInputStreamthat will read from a givenSeekableByteChannel.privateBufferedChannelImageInputStream(java.nio.channels.SeekableByteChannel channel, boolean closeChannelOnClose)BufferedChannelImageInputStream(java.nio.file.Path file)Constructs aBufferedChannelImageInputStreamthat will read from a givenPath.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanbufferEmpty()voidclose()private booleanfillBuffer()voidflushBefore(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()shortreadShort()voidseek(long position)voidsetByteOrder(java.nio.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 Detail
-
CLOSEABLE_STUB
private static final java.io.Closeable CLOSEABLE_STUB
-
DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
byteBuffer
private java.nio.ByteBuffer byteBuffer
-
buffer
private byte[] buffer
-
bufferPos
private int bufferPos
-
bufferLimit
private int bufferLimit
-
integralCache
private final java.nio.ByteBuffer integralCache
-
integralCacheArray
private final byte[] integralCacheArray
-
channel
private java.nio.channels.SeekableByteChannel channel
-
closeable
private java.io.Closeable closeable
-
-
Constructor Detail
-
BufferedChannelImageInputStream
public BufferedChannelImageInputStream(java.io.File file) throws java.io.IOExceptionConstructs aBufferedChannelImageInputStreamthat will read from a givenFile.- Parameters:
file- aFileto read from.- Throws:
java.lang.IllegalArgumentException- iffileisnull.java.lang.SecurityException- if a security manager is installed, and it denies read access to the file.java.io.IOException- if an I/O error occurs while opening the file.
-
BufferedChannelImageInputStream
public BufferedChannelImageInputStream(java.nio.file.Path file) throws java.io.IOExceptionConstructs aBufferedChannelImageInputStreamthat will read from a givenPath.- Parameters:
file- aPathto read from.- Throws:
java.lang.IllegalArgumentException- iffileisnull.java.lang.UnsupportedOperationException- if thefileis associated with a provider that does not support creating file channels.java.io.IOException- if an I/O error occurs while opening the file.java.lang.SecurityException- if a security manager is installed, and it denies read access to the file.
-
BufferedChannelImageInputStream
public BufferedChannelImageInputStream(java.io.RandomAccessFile file)
Constructs aBufferedChannelImageInputStreamthat will read from a givenRandomAccessFile.- Parameters:
file- aRandomAccessFileto read from.- Throws:
java.lang.IllegalArgumentException- iffileisnull.
-
BufferedChannelImageInputStream
public BufferedChannelImageInputStream(java.io.FileInputStream inputStream)
Constructs aBufferedChannelImageInputStreamthat will read from a givenFileInputStream.Closing this stream will not close the
FileInputStream.- Parameters:
inputStream- aFileInputStreamto read from.- Throws:
java.lang.IllegalArgumentException- ifinputStreamisnull.
-
BufferedChannelImageInputStream
public BufferedChannelImageInputStream(java.nio.channels.SeekableByteChannel channel)
Constructs aBufferedChannelImageInputStreamthat will read from a givenSeekableByteChannel.Closing this stream will not close the
SeekableByteChannel.- Parameters:
channel- aSeekableByteChannelto read from.- Throws:
java.lang.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:
java.lang.IllegalArgumentException- ifchannelisnull.
-
BufferedChannelImageInputStream
private BufferedChannelImageInputStream(java.nio.channels.SeekableByteChannel channel, boolean closeChannelOnClose)
-
-
Method Detail
-
fillBuffer
private boolean fillBuffer() throws java.io.IOException- Throws:
java.io.IOException
-
bufferEmpty
private boolean bufferEmpty()
-
setByteOrder
public void setByteOrder(java.nio.ByteOrder byteOrder)
- Specified by:
setByteOrderin interfacejavax.imageio.stream.ImageInputStream- Overrides:
setByteOrderin classjavax.imageio.stream.ImageInputStreamImpl
-
read
public int read() throws java.io.IOException- Specified by:
readin interfacejavax.imageio.stream.ImageInputStream- Specified by:
readin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
read
public int read(byte[] bytes, int offset, int length) throws java.io.IOException- Specified by:
readin interfacejavax.imageio.stream.ImageInputStream- Specified by:
readin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
readDirect
private int readDirect(byte[] bytes, int offset, int length) throws java.io.IOException- Throws:
java.io.IOException
-
readBuffered
private int readBuffered(byte[] bytes, int offset, int length)
-
length
public long length()
- Specified by:
lengthin interfacejavax.imageio.stream.ImageInputStream- Overrides:
lengthin classjavax.imageio.stream.ImageInputStreamImpl
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejavax.imageio.stream.ImageInputStream- Overrides:
closein classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException- Specified by:
readShortin interfacejava.io.DataInput- Specified by:
readShortin interfacejavax.imageio.stream.ImageInputStream- Overrides:
readShortin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException- Specified by:
readIntin interfacejava.io.DataInput- Specified by:
readIntin interfacejavax.imageio.stream.ImageInputStream- Overrides:
readIntin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException- Specified by:
readLongin interfacejava.io.DataInput- Specified by:
readLongin interfacejavax.imageio.stream.ImageInputStream- Overrides:
readLongin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
seek
public void seek(long position) throws java.io.IOException- Specified by:
seekin interfacejavax.imageio.stream.ImageInputStream- Overrides:
seekin classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
flushBefore
public void flushBefore(long pos) throws java.io.IOException- Specified by:
flushBeforein interfacejavax.imageio.stream.ImageInputStream- Overrides:
flushBeforein classjavax.imageio.stream.ImageInputStreamImpl- Throws:
java.io.IOException
-
-