Class PredictorChannel

java.lang.Object
org.apache.sis.internal.storage.inflater.PixelChannel
org.apache.sis.internal.storage.inflater.PredictorChannel
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel
Direct Known Subclasses:
HorizontalPredictor

abstract class PredictorChannel extends PixelChannel
Implementation of a Predictor to be executed after decompression.
Since:
1.1
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    If read(ByteBuffer) could not process some trailing bytes, a copy of those bytes for processing in the next method invocation.
    private int
    Number of values in the deferred array.
    private final CompressionChannel
    The channel from which to read data.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a predictor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract int
    apply(ByteBuffer buffer, int start)
    Applies the predictor on data in the given buffer, from the given start position until current buffer position.
    final void
    Closes input.
    final boolean
    Tells whether this channel is still open.
    int
    read(ByteBuffer target)
    Decompresses some bytes from the input into the given destination buffer.
    void
    setInputRegion(long start, long byteCount)
    Prepares this predictor for reading a new tile or a new band of a planar image.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • input

      private final CompressionChannel input
      The channel from which to read data.
    • deferred

      private byte[] deferred
      If read(ByteBuffer) could not process some trailing bytes, a copy of those bytes for processing in the next method invocation.
    • deferredCount

      private int deferredCount
      Number of values in the deferred array.
  • Constructor Details

    • PredictorChannel

      protected PredictorChannel(CompressionChannel input)
      Creates a predictor. The setInputRegion(long, long) method must be invoked after construction before a reading process can start.
      Parameters:
      input - the channel that decompress data.
  • Method Details

    • setInputRegion

      public void setInputRegion(long start, long byteCount) throws IOException
      Prepares this predictor for reading a new tile or a new band of a planar image.
      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.
    • apply

      protected abstract int apply(ByteBuffer buffer, int start)
      Applies the predictor on data in the given buffer, from the given start position until current buffer position.
      Parameters:
      buffer - the buffer on which to apply the predictor.
      start - position of first sample value to process.
      Returns:
      position after the last sample value processed. Should be Buffer.position(), unless the predictor needs more data for processing the last bytes.
    • read

      public int read(ByteBuffer target) throws IOException
      Decompresses some bytes from the input into the given destination buffer.
      Parameters:
      target - the buffer into which bytes are to be transferred.
      Returns:
      the number of bytes read, or -1 if end-of-stream.
      Throws:
      IOException - if some other I/O error occurs.
    • isOpen

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

      public final void close()
      Closes input. Note that it will not closes the channel wrapped by input because that channel will typically be needed again for decompressing other tiles.