ucar.nc2.iosp
Class IospHelper

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

public class IospHelper
extends java.lang.Object

Helper methods for IOSP's

Since:
Jan 3, 2008
Author:
caron

Constructor Summary
IospHelper()
           
 
Method Summary
static char[] convertByteToChar(byte[] byteArray)
           
static byte[] convertCharToByte(char[] from)
           
static void copyFromByteBuffer(java.nio.ByteBuffer bb, StructureMembers.Member m, IndexIterator result)
           
static java.lang.Object makePrimitiveArray(int size, DataType dataType)
          Create 1D primitive array of the given size and type
static java.lang.Object makePrimitiveArray(int size, DataType dataType, java.lang.Object fillValue)
          Create 1D primitive array of the given size and type, fill it with the given value
static java.lang.Object readData(LayoutBB layout, DataType dataType, java.lang.Object arr)
          Read data subset from ByteBuffer, place in given primitive array.
static java.lang.Object readData(PositioningDataInputStream raf, Layout index, DataType dataType, java.lang.Object arr)
          Read data subset from PositioningDataInputStream, place in given primitive array.
static java.lang.Object readData(RandomAccessFile raf, Layout index, DataType dataType, java.lang.Object arr, int byteOrder)
          Read data subset from RandomAccessFile, place in given primitive array.
static java.lang.Object readDataFill(LayoutBB layout, DataType dataType, java.lang.Object fillValue)
          Read data subset from PositioningDataInputStream, create primitive array of size Layout.getTotalNelems.
static java.lang.Object readDataFill(PositioningDataInputStream is, Layout index, DataType dataType, java.lang.Object fillValue)
          Read data subset from PositioningDataInputStream, create primitive array of size Layout.getTotalNelems.
static java.lang.Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, java.lang.Object fillValue, int byteOrder)
          Read data subset from RandomAccessFile, create primitive array of size Layout.getTotalNelems.
static Array readSection(ParsedSectionSpec cer)
           
static long transferData(Array result, java.nio.channels.WritableByteChannel channel)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IospHelper

public IospHelper()
Method Detail

readDataFill

public static java.lang.Object readDataFill(RandomAccessFile raf,
                                            Layout index,
                                            DataType dataType,
                                            java.lang.Object fillValue,
                                            int byteOrder)
                                     throws java.io.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 Byte, Short, Integer, Long, Float, Double, or String, matching dataType, 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:
java.io.IOException - on read error

readData

public static java.lang.Object readData(RandomAccessFile raf,
                                        Layout index,
                                        DataType dataType,
                                        java.lang.Object arr,
                                        int byteOrder)
                                 throws java.io.IOException
Read data subset from RandomAccessFile, 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
byteOrder - if equal to RandomAccessFile.ORDER_XXXX, set the byte order just before reading
Returns:
primitive array with data read in
Throws:
java.io.IOException - on read error

readDataFill

public static java.lang.Object readDataFill(PositioningDataInputStream is,
                                            Layout index,
                                            DataType dataType,
                                            java.lang.Object fillValue)
                                     throws java.io.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 Byte, Short, Integer, Long, Float, Double, or String, matching dataType, or null for none
Returns:
primitive array with data read in
Throws:
java.io.IOException - on read error

readData

public static java.lang.Object readData(PositioningDataInputStream raf,
                                        Layout index,
                                        DataType dataType,
                                        java.lang.Object arr)
                                 throws java.io.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:
java.io.IOException - on read error

readDataFill

public static java.lang.Object readDataFill(LayoutBB layout,
                                            DataType dataType,
                                            java.lang.Object fillValue)
                                     throws java.io.IOException
Read data subset from PositioningDataInputStream, create primitive array of size Layout.getTotalNelems. Reading is controlled by the Layout object.

Parameters:
layout - handles skipping around in the file, privide ByteBuffer to read from
dataType - dataType of the variable
fillValue - must Byte, Short, Integer, Long, Float, Double, or String, matching dataType, or null for none
Returns:
primitive array with data read in
Throws:
java.io.IOException - on read error

readData

public static java.lang.Object readData(LayoutBB layout,
                                        DataType dataType,
                                        java.lang.Object arr)
                                 throws java.io.IOException
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
Throws:
java.io.IOException - on read error

copyFromByteBuffer

public static void copyFromByteBuffer(java.nio.ByteBuffer bb,
                                      StructureMembers.Member m,
                                      IndexIterator result)

makePrimitiveArray

public static java.lang.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 java.lang.Object makePrimitiveArray(int size,
                                                  DataType dataType,
                                                  java.lang.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 Byte, Short, Integer, Long, Float, Double, or String, matching dataType
Returns:
primitive array with data read in

convertByteToChar

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

convertCharToByte

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

transferData

public static long transferData(Array result,
                                java.nio.channels.WritableByteChannel channel)
                         throws java.io.IOException,
                                InvalidRangeException
Throws:
java.io.IOException
InvalidRangeException

readSection

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