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 Summary
Constructors Constructor Description IospHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean[]
convertByteToBoolean(byte[] from)
static char[]
convertByteToChar(byte[] byteArray)
static char[]
convertByteToCharUTF(byte[] byteArray)
static byte[]
convertCharToByte(char[] from)
static byte[]
convertCharToByteUTF(char[] from)
static ArrayStructureBB
copyToArrayBB(StructureData sdata)
Deprecated.use StructureDataDeep.copyToArrayBBstatic long
copyToByteChannel(Array data, WritableByteChannel channel)
Copy data to a channel.static long
copyToOutputStream(Array data, OutputStream out)
Copy data to a OutputStream.static ArrayStructureBB
makeArrayBB(ArrayStructure as)
Deprecated.use StructureDataDeep.copyToArrayBBstatic Object
makePrimitiveArray(int size, DataType dataType)
Create 1D primitive array of the given size and typestatic Object
makePrimitiveArray(int size, DataType dataType, Object fillValue)
Create 1D primitive array of the given size and type, fill it with the given valuestatic 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)
-
-
-
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 variablefillValue
- must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for nonebyteOrder
- 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 variablearr
- primitive array to read data intobyteOrder
- if equal to RandomAccessFile.ORDER_XXXX, set the byte order just before readingconvertChar
- 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 variablefillValue
- 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 variablearr
- 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 fromdataType
- dataType of the variablefillValue
- 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 fromdataType
- dataType of the variablearr
- 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 herechannel
- 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 hereout
- 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 createdataType
- 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 createdataType
- dataType of the variablefillValue
- 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
-
-