ucar.nc2.iosp
Class IospHelper

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

public class IospHelper
extends 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 ArrayStructureBB copyToArrayBB(StructureData sdata)
           
static long copyToByteChannel(Array data, WritableByteChannel channel)
          Copy data to a channel.
static ArrayStructureBB makeArrayBB(ArrayStructure as)
           
static Object makePrimitiveArray(int size, DataType dataType)
          Create 1D primitive array of the given size and type
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
static Object readData(LayoutBB layout, DataType dataType, Object arr)
          Read data subset from ByteBuffer, place in given primitive array.
static Object readData(PositioningDataInputStream raf, Layout index, DataType dataType, Object arr)
          Read data subset from PositioningDataInputStream, place in given primitive array.
static Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder, boolean convertChar)
          Read data subset from RandomAccessFile, place in given primitive array.
static Object readDataFill(LayoutBB layout, DataType dataType, Object fillValue)
          Read data subset from ByteBuffer, create primitive array of size Layout.getTotalNelems.
static Object readDataFill(PositioningDataInputStream is, Layout index, DataType dataType, Object fillValue)
          Read data subset from PositioningDataInputStream, create primitive array of size Layout.getTotalNelems.
static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue, int byteOrder)
          Read data subset from RandomAccessFile, create primitive array of size Layout.getTotalNelems.
static Object readDataFill(RandomAccessFile raf, Layout index, DataType dataType, Object fillValue, int byteOrder, boolean convertChar)
           
static Array readSection(ParsedSectionSpec cer)
           
static long transferData(Array result, 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 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 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:
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 Byte, Short, Integer, Long, Float, Double, or String, matching dataType, 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)
                           throws IOException
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, 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:
IOException - on read error

readData

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

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

makeArrayBB

public static ArrayStructureBB makeArrayBB(ArrayStructure as)
                                    throws IOException
Throws:
IOException

copyToArrayBB

public static ArrayStructureBB copyToArrayBB(StructureData sdata)

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 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,
                                WritableByteChannel channel)
                         throws IOException,
                                InvalidRangeException
Throws:
IOException
InvalidRangeException

readSection

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


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.