Package ucar.nc2.iosp

Class IospHelper

java.lang.Object
ucar.nc2.iosp.IospHelper

public class IospHelper extends Object
Helper methods for IOSP's for reading data.
Since:
Jan 3, 2008
  • Constructor Details

    • IospHelper

      public IospHelper()
  • Method Details

    • readDataFill

      public static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue, int byteOrder) throws IOException
      Read data subset from RandomAccessFile, create primitive array of size Layout.getTotalNelems. Reading is controlled by the Layout object.
      Parameters:
      raf - read from here.
      index - handles skipping around in the file.
      dataType - dataType of the variable
      fillValue - must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for none
      byteOrder - if equal to RandomAccessFile.ORDER_XXXX, set the byte order just before reading
      Returns:
      primitive array with data read in
      Throws:
      IOException - on read error
    • readDataFill

      public static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue, int byteOrder, boolean convertChar) throws IOException
      Throws:
      IOException
    • readData

      public static Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder, boolean convertChar) throws IOException
      Read data subset from RandomAccessFile, place in given primitive array. Reading is controlled by the Layout object.
      Parameters:
      raf - read from here.
      layout - handles skipping around in the file.
      dataType - dataType of the variable
      arr - primitive array to read data into
      byteOrder - if equal to RandomAccessFile.ORDER_XXXX, set the byte order just before reading
      convertChar - true if bytes should be converted to char for dataType CHAR
      Returns:
      primitive array with data read in
      Throws:
      IOException - on read error
    • readDataFill

      public static Object readDataFill(PositioningDataInputStream is, Layout index, DataType dataType, Object fillValue) throws IOException
      Read data subset from PositioningDataInputStream, create primitive array of size Layout.getTotalNelems. Reading is controlled by the Layout object.
      Parameters:
      is - read from here.
      index - handles skipping around in the file.
      dataType - dataType of the variable
      fillValue - must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for none
      Returns:
      primitive array with data read in
      Throws:
      IOException - on read error
    • readData

      public static Object readData(PositioningDataInputStream raf, Layout index, DataType dataType, Object arr) throws IOException
      Read data subset from PositioningDataInputStream, place in given primitive array. Reading is controlled by the Layout object.
      Parameters:
      raf - read from here.
      index - handles skipping around in the file.
      dataType - dataType of the variable
      arr - primitive array to read data into
      Returns:
      primitive array with data read in
      Throws:
      IOException - on read error
    • readDataFill

      public static Object readDataFill(LayoutBB layout, DataType dataType, Object fillValue)
      Read data subset from ByteBuffer, create primitive array of size Layout.getTotalNelems. Reading is controlled by the Layout object.
      Parameters:
      layout - handles skipping around in the file, provide ByteBuffer to read from
      dataType - dataType of the variable
      fillValue - must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for none
      Returns:
      primitive array with data read in
    • readData

      public static Object readData(LayoutBB layout, DataType dataType, Object arr)
      Read data subset from ByteBuffer, place in given primitive array. Reading is controlled by the LayoutBB object.
      Parameters:
      layout - handles skipping around in the file, privide ByteBuffer to read from
      dataType - dataType of the variable
      arr - primitive array to read data into
      Returns:
      the primitive array with data read in
    • copyToByteChannel

      public static long copyToByteChannel(Array data, WritableByteChannel channel) throws IOException
      Copy data to a channel. Used by ncstream. Not doing Structures correctly yet.
      Parameters:
      data - copy from here
      channel - copy to here
      Returns:
      number of bytes copied
      Throws:
      IOException - on write error
    • copyToOutputStream

      public static long copyToOutputStream(Array data, OutputStream out) throws IOException
      Copy data to a OutputStream. Used by ncstream. Not doing Structures correctly yet.
      Parameters:
      data - copy from here
      out - copy to here
      Returns:
      number of bytes copied
      Throws:
      IOException - on write error
    • makeArrayBB

      public static ArrayStructureBB makeArrayBB(ArrayStructure as) throws IOException
      Deprecated.
      use StructureDataDeep.copyToArrayBB
      Throws:
      IOException
    • copyToArrayBB

      public static ArrayStructureBB copyToArrayBB(StructureData sdata)
      Deprecated.
      use StructureDataDeep.copyToArrayBB
    • makePrimitiveArray

      public static Object makePrimitiveArray(int size, DataType dataType)
      Create 1D primitive array of the given size and type
      Parameters:
      size - the size of the array to create
      dataType - dataType of the variable
      Returns:
      primitive array with data read in
    • makePrimitiveArray

      public static Object makePrimitiveArray(int size, DataType dataType, Object fillValue)
      Create 1D primitive array of the given size and type, fill it with the given value
      Parameters:
      size - the size of the array to create
      dataType - dataType of the variable
      fillValue - must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for none
      Returns:
      primitive array with data read in
    • convertByteToCharUTF

      public static char[] convertByteToCharUTF(byte[] byteArray)
    • convertCharToByteUTF

      public static byte[] convertCharToByteUTF(char[] from)
    • convertByteToChar

      public static char[] convertByteToChar(byte[] byteArray)
    • convertCharToByte

      public static byte[] convertCharToByte(char[] from)
    • convertByteToBoolean

      public static boolean[] convertByteToBoolean(byte[] from)
    • transferData

      public static long transferData(Array result, WritableByteChannel channel) throws IOException
      Throws:
      IOException
    • readSection

      public static Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException
      Throws:
      IOException
      InvalidRangeException