Class MemoryDataTransfer

java.lang.Object
org.apache.sis.internal.storage.io.MemoryDataTransfer
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel, DataTransfer

final class MemoryDataTransfer extends Object implements DataTransfer, ReadableByteChannel
A DataTransfer with all data in the given buffer, without channel.
Implementation note: This class implements also an empty ReadableByteChannel as safety. When using ChannelDataInput without channel, only an existing Buffer pre-filled with the data should be used. If we have a bug in our reading process, the empty channel will cause an EOFException to be thrown instead of a NullPointerException.
Since:
0.7
Version:
1.1
  • Field Details

  • Constructor Details

  • Method Details

    • reader

      DataTransfer reader()
      Returns the most efficient DataTransfer instance to use.
    • seek

      public void seek(long position) throws IOException
      Moves to the given byte position in the buffer.
      Specified by:
      seek in interface DataTransfer
      Parameters:
      position - the position where to move.
      Throws:
      IOException - if the stream cannot be moved to the given position.
    • filename

      public String filename()
      Delegates to the actual implementation.
      Specified by:
      filename in interface DataTransfer
    • dataSizeShift

      public int dataSizeShift()
      Description copied from interface: DataTransfer
      Returns the size of the Java primitive type which is the element of the array. The size is expressed as the number of bits to shift: java dataSize = 1 << dataSizeShift;
      Specified by:
      dataSizeShift in interface DataTransfer
    • dataArray

      public Object dataArray()
      Description copied from interface: DataTransfer
      Returns the data as a char[], short[], int[], long[], float[] or double[] array. This is either the array given in argument to the subclass constructor, or the array created by DataTransfer.createDataArray(int).
      Specified by:
      dataArray in interface DataTransfer
    • dataArrayAsBuffer

      public Buffer dataArrayAsBuffer()
      Description copied from interface: DataTransfer
      Returns DataTransfer.dataArray() wrapped in a buffer.
      Specified by:
      dataArrayAsBuffer in interface DataTransfer
    • view

      public Buffer view()
      Description copied from interface: DataTransfer
      Returns the view created by the last call to DataTransfer.createView(), or null if none.
      Specified by:
      view in interface DataTransfer
    • createView

      public Buffer createView()
      Description copied from interface: DataTransfer
      Creates a new buffer of the type required by the array to fill. This method is guaranteed to be invoked exactly once, after the ChannelData.buffer contains enough data.
      Specified by:
      createView in interface DataTransfer
    • createDataArray

      public void createDataArray(int length)
      Description copied from interface: DataTransfer
      Creates a destination array of the given length.
      Specified by:
      createDataArray in interface DataTransfer
    • setDest

      public void setDest(Object array)
      Description copied from interface: DataTransfer
      Sets the destination to the given data array, which may be null.
      Specified by:
      setDest in interface DataTransfer
    • readFully

      public void readFully(Buffer view, int offset, int length)
      Reads length values from the buffer and stores them into the array known to subclass, starting at index offset.
      Specified by:
      readFully in interface DataTransfer
      Parameters:
      view - ignored.
      offset - the starting position within dest to write.
      length - the number of values to read.
    • read

      public int read(ByteBuffer dst)
      Returns -1 since an empty channel has reached the end-of-stream.
      Specified by:
      read in interface ReadableByteChannel
    • isOpen

      public boolean isOpen()
      The channel is always open.
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Does nothing - keep the channel open.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException