Class BufferedChannelImageInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable, javax.imageio.stream.ImageInputStream

    final class BufferedChannelImageInputStream
    extends javax.imageio.stream.ImageInputStreamImpl
    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.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      (package private) BufferedChannelImageInputStream​(Cache cache)
      Constructs a BufferedChannelImageInputStream that will read from a given Cache.
        BufferedChannelImageInputStream​(java.io.File file)
      Constructs a BufferedChannelImageInputStream that will read from a given File.
        BufferedChannelImageInputStream​(java.io.FileInputStream inputStream)
      Constructs a BufferedChannelImageInputStream that will read from a given FileInputStream.
        BufferedChannelImageInputStream​(java.io.RandomAccessFile file)
      Constructs a BufferedChannelImageInputStream that will read from a given RandomAccessFile.
        BufferedChannelImageInputStream​(java.nio.channels.SeekableByteChannel channel)
      Constructs a BufferedChannelImageInputStream that will read from a given SeekableByteChannel.
      private BufferedChannelImageInputStream​(java.nio.channels.SeekableByteChannel channel, boolean closeChannelOnClose)  
        BufferedChannelImageInputStream​(java.nio.file.Path file)
      Constructs a BufferedChannelImageInputStream that will read from a given Path.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean bufferEmpty()  
      void close()  
      private boolean fillBuffer()  
      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 readShort()  
      void seek​(long position)  
      void setByteOrder​(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
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CLOSEABLE_STUB

        private static final java.io.Closeable CLOSEABLE_STUB
      • 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.IOException
        Constructs a BufferedChannelImageInputStream that will read from a given File.
        Parameters:
        file - a File to read from.
        Throws:
        java.lang.IllegalArgumentException - if file is null.
        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.IOException
        Constructs a BufferedChannelImageInputStream that will read from a given Path.
        Parameters:
        file - a Path to read from.
        Throws:
        java.lang.IllegalArgumentException - if file is null.
        java.lang.UnsupportedOperationException - if the file is 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 a BufferedChannelImageInputStream that will read from a given RandomAccessFile.
        Parameters:
        file - a RandomAccessFile to read from.
        Throws:
        java.lang.IllegalArgumentException - if file is null.
      • BufferedChannelImageInputStream

        public BufferedChannelImageInputStream​(java.io.FileInputStream inputStream)
        Constructs a BufferedChannelImageInputStream that will read from a given FileInputStream.

        Closing this stream will not close the FileInputStream.

        Parameters:
        inputStream - a FileInputStream to read from.
        Throws:
        java.lang.IllegalArgumentException - if inputStream is null.
      • BufferedChannelImageInputStream

        public BufferedChannelImageInputStream​(java.nio.channels.SeekableByteChannel channel)
        Constructs a BufferedChannelImageInputStream that will read from a given SeekableByteChannel.

        Closing this stream will not close the SeekableByteChannel.

        Parameters:
        channel - a SeekableByteChannel to read from.
        Throws:
        java.lang.IllegalArgumentException - if channel is null.
      • BufferedChannelImageInputStream

        BufferedChannelImageInputStream​(Cache cache)
        Constructs a BufferedChannelImageInputStream that will read from a given Cache.

        Closing this stream will close the Cache.

        Parameters:
        cache - a SeekableByteChannel to read from.
        Throws:
        java.lang.IllegalArgumentException - if channel is null.
      • 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:
        setByteOrder in interface javax.imageio.stream.ImageInputStream
        Overrides:
        setByteOrder in class javax.imageio.stream.ImageInputStreamImpl
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in interface javax.imageio.stream.ImageInputStream
        Specified by:
        read in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] bytes,
                        int offset,
                        int length)
                 throws java.io.IOException
        Specified by:
        read in interface javax.imageio.stream.ImageInputStream
        Specified by:
        read in class javax.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:
        length in interface javax.imageio.stream.ImageInputStream
        Overrides:
        length in class javax.imageio.stream.ImageInputStreamImpl
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface javax.imageio.stream.ImageInputStream
        Overrides:
        close in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • readShort

        public short readShort()
                        throws java.io.IOException
        Specified by:
        readShort in interface java.io.DataInput
        Specified by:
        readShort in interface javax.imageio.stream.ImageInputStream
        Overrides:
        readShort in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • readInt

        public int readInt()
                    throws java.io.IOException
        Specified by:
        readInt in interface java.io.DataInput
        Specified by:
        readInt in interface javax.imageio.stream.ImageInputStream
        Overrides:
        readInt in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • readLong

        public long readLong()
                      throws java.io.IOException
        Specified by:
        readLong in interface java.io.DataInput
        Specified by:
        readLong in interface javax.imageio.stream.ImageInputStream
        Overrides:
        readLong in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • seek

        public void seek​(long position)
                  throws java.io.IOException
        Specified by:
        seek in interface javax.imageio.stream.ImageInputStream
        Overrides:
        seek in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • flushBefore

        public void flushBefore​(long pos)
                         throws java.io.IOException
        Specified by:
        flushBefore in interface javax.imageio.stream.ImageInputStream
        Overrides:
        flushBefore in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException