Class CompressionChannel

java.lang.Object
org.apache.sis.internal.storage.inflater.PixelChannel
org.apache.sis.internal.storage.inflater.CompressionChannel
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel
Direct Known Subclasses:
CCITTRLE, LZW, PackBits, ZIP

abstract class CompressionChannel extends PixelChannel
Inflater writing all decompressed values in a temporary buffer. This class does not need to care about subsampling.

The close() method shall be invoked when this channel is no longer used.

Since:
1.1
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Desired size of the buffer where to temporarily copy decompressed data.
    private long
    Stream position after the last byte to read.
    protected final ChannelDataInput
    The source of data to decompress.
    protected final StoreListeners
    Objects where to report warnings.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new channel which will decompress data from the given input.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases resources used by this channel, but without closing the input channel.
    (package private) final ChannelDataInput
    createDataInput(PixelChannel channel, int scanlineStride)
    Creates the data input stream to use for getting uncompressed data.
    protected final boolean
    Returns true if the stream position reached the end of tile.
    final boolean
    Tells whether this channel is still open.
    (package private) static void
    repeat(ByteBuffer target, byte b, int n)
    Copies the given byte n times in the given buffer.
    (package private) final Resources
    Returns the resources for error messages.
    void
    setInputRegion(long start, long byteCount)
    Prepares this inflater for reading a new tile or a new band of a tile.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.nio.channels.ReadableByteChannel

    read
  • Field Details

    • BUFFER_SIZE

      private static final int BUFFER_SIZE
      Desired size of the buffer where to temporarily copy decompressed data. The actual buffer size may be larger, but should not be smaller.
      See Also:
    • input

      protected final ChannelDataInput input
      The source of data to decompress.
    • endPosition

      private long endPosition
      Stream position after the last byte to read.
    • listeners

      protected final StoreListeners listeners
      Objects where to report warnings.
  • Constructor Details

    • CompressionChannel

      protected CompressionChannel(ChannelDataInput input, StoreListeners listeners)
      Creates a new channel which will decompress data from the given input. The setInputRegion(long, long) method must be invoked after construction before a reading process can start.
      Parameters:
      input - the source of data to decompress.
      listeners - object where to report warnings.
  • Method Details

    • setInputRegion

      public void setInputRegion(long start, long byteCount) throws IOException
      Prepares this inflater for reading a new tile or a new band of a tile.
      Specified by:
      setInputRegion in class PixelChannel
      Parameters:
      start - stream position where to start reading.
      byteCount - number of bytes to read from the input.
      Throws:
      IOException - if the stream cannot be seek to the given start position.
    • finished

      protected final boolean finished()
      Returns true if the stream position reached the end of tile.
      Returns:
      whether the stream reached end of tile.
    • createDataInput

      final ChannelDataInput createDataInput(PixelChannel channel, int scanlineStride) throws IOException
      Creates the data input stream to use for getting uncompressed data. The input stream must be on the start position before to invoke this method.

      This method tries to create a buffer of the size of scanline stride, or a multiple of that size, for performance reasons. A well adjusted buffer size reduces calls to ByteBuffer.compact(), which in turn reduces the amount of copy operations between different regions of the buffer.

      Parameters:
      channel - the channel to wrap. This is this unless a Predictor is applied.
      scanlineStride - the scanline stride of the image to read. Used for choosing a buffer size.
      Returns:
      the data input for uncompressed data.
      Throws:
      IOException - if an error occurred while filling the buffer with initial data.
    • repeat

      static void repeat(ByteBuffer target, byte b, int n)
      Copies the given byte n times in the given buffer.
    • isOpen

      public final boolean isOpen()
      Tells whether this channel is still open.
    • close

      public void close()
      Releases resources used by this channel, but without closing the input channel. The input channel is not closed by this operation because it will typically be needed again for decompressing other tiles.
    • resources

      final Resources resources()
      Returns the resources for error messages.