public class BinaryStreamReader
extends java.lang.Object
BinaryStreamReader
class reads streams of
binary data described by an XML template. The following is an
example binary stream template for a NOAA-1b AMSU header record:
<?xml version="1.0"?> <binaryStream xmlns="http://coastwatch.noaa.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://coastwatch.noaa.gov http://coastwatch.noaa.gov/xml/binaryStream.xsd"> <!-- File ID section --> <string name="creationSite" length="3"> <valueMap valueType="string"> <entry key="CMS" value="Centre de Meteorologie Spatiale, France"/> <entry key="DSS" value="Dundee Satellite Receiving Station, UK"/> <entry key="NSS" value="National Environmental Satellite, Data and Information Service, USA"/> <entry key="UKM" value="United Kingdom Meteorological Office, UK"/> </valueMap> </string> <skip length="1"/> <ushort name="formatVersion"/> <ushort name="formatVersionYear"/> <ushort name="formatVersionDay"/> <ushort name="headerRecords" absoluteOffset="14"/> <string name="datasetName" absoluteOffset="22" length="42"/> <ushort name="spacecraft" absoluteOffset="72"> <valueMap valueType="string"> <entry key="2" value="NOAA-16"/> <entry key="4" value="NOAA-15"/> <entry key="6" value="NOAA-17"/> <entry key="7" value="NOAA-18"/> <entry key="8" value="NOAA-19"/> </valueMap> </ushort> <ubyte name="instrument" absoluteOffset="75"> <valueMap valueType="string"> <entry key="5" value="AMSU-A1 102 / AMSU-A2 103"/> <entry key="9" value="AMSU-A1 103 / AMSU-A2 102"/> <entry key="13" value="AMSU-A1 104 / AMSU-A2 104"/> <entry key="17" value="AMSU-A1 105 / AMSU-A2 107"/> <entry key="33" value="AMSU-A1 109 / AMSU-A2 105"/> </valueMap> </ubyte> <ushort name="dataType"> <valueMap valueType="string"> <entry key="10" value="AMSU-A"/> </valueMap> </ushort> <uint name="startDay1950" absoluteOffset="80"/> <ushort name="startYear"/> <ushort name="startDay"/> <uint name="startTimeUTC"/> <ushort name="endYear" absoluteOffset="96"/> <ushort name="endDay"/> <uint name="endTimeUTC"/> <short name="scanOffset" absoluteOffset="108"/> <!-- Dataset quality section --> <uint name="instrumentStatusA2" absoluteOffset="120"/> <uint name="instrumentStatusA1" absoluteOffset="132"/> <ushort name="dataRecords" absoluteOffset="144"/> <ushort name="calibratedScanLines"/> <ushort name="missingScanLines"/> <ushort name="dataGaps"/> <ushort name="dataSource" absoluteOffset="170"> <valueMap valueType="string"> <entry key="1" value="Fairbanks, AK"/> <entry key="2" value="Wallops Island, VA"/> <entry key="3" value="SOCC"/> <entry key="4" value="Svalbard, Norway"/> <entry key="5" value="Monterey, CA"/> </valueMap> </ushort> <!-- Temperature-radiance conversion section --> <int name="ch1CentralWave" scale="1e-6" absoluteOffset="688"/> <int name="ch1Constant1" scale="1e-6"/> <int name="ch1Constant2" scale="1e-6"/> <int name="ch2CentralWave" scale="1e-6"/> <int name="ch2Constant1" scale="1e-6"/> <int name="ch2Constant2" scale="1e-6"/> <int name="ch3CentralWave" scale="1e-6"/> <int name="ch3Constant1" scale="1e-6"/> <int name="ch3Constant2" scale="1e-6"/> <int name="ch4CentralWave" scale="1e-6"/> <int name="ch4Constant1" scale="1e-6"/> <int name="ch4Constant2" scale="1e-6"/> <int name="ch5CentralWave" scale="1e-6"/> <int name="ch5Constant1" scale="1e-6"/> <int name="ch5Constant2" scale="1e-6"/> <int name="ch6CentralWave" scale="1e-6"/> <int name="ch6Constant1" scale="1e-6"/> <int name="ch6Constant2" scale="1e-6"/> <int name="ch7CentralWave" scale="1e-6"/> <int name="ch7Constant1" scale="1e-6"/> <int name="ch7Constant2" scale="1e-6"/> <int name="ch8CentralWave" scale="1e-6"/> <int name="ch8Constant1" scale="1e-6"/> <int name="ch8Constant2" scale="1e-6"/> <int name="ch9CentralWave" scale="1e-6"/> <int name="ch9Constant1" scale="1e-6"/> <int name="ch9Constant2" scale="1e-6"/> <int name="ch10CentralWave" scale="1e-6"/> <int name="ch10Constant1" scale="1e-6"/> <int name="ch10Constant2" scale="1e-6"/> <int name="ch11CentralWave" scale="1e-6"/> <int name="ch11Constant1" scale="1e-6"/> <int name="ch11Constant2" scale="1e-6"/> <int name="ch12CentralWave" scale="1e-6"/> <int name="ch12Constant1" scale="1e-6"/> <int name="ch12Constant2" scale="1e-6"/> <int name="ch13CentralWave" scale="1e-6"/> <int name="ch13Constant1" scale="1e-6"/> <int name="ch13Constant2" scale="1e-6"/> <int name="ch14CentralWave" scale="1e-6"/> <int name="ch14Constant1" scale="1e-6"/> <int name="ch14Constant2" scale="1e-6"/> <int name="ch15CentralWave" scale="1e-6"/> <int name="ch15Constant1" scale="1e-6"/> <int name="ch15Constant2" scale="1e-6"/> <!-- Navigation section --> <string name="ellipsoidModel" absoluteOffset="880" length="8"/> </binaryStream>
Constructor and Description |
---|
BinaryStreamReader(java.io.InputStream template)
Creates a new reader from the specified buffer and template.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
convertText(java.lang.String text,
noaa.coastwatch.io.BinaryStreamReader.ValueType type)
Converts a text value to a typed value.
|
byte |
getByte(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a byte value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
byte[] |
getByteArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a byte array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
double |
getDouble(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a double value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
double[] |
getDoubleArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a double array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
float |
getFloat(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a float value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
float[] |
getFloatArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a float array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
int |
getInt(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets an integer value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
int[] |
getIntArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets an integer array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
long |
getLong(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a long value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
long[] |
getLongArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a long array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
java.util.Set<java.lang.String> |
getNames()
Gets the data value names.
|
int |
getOffset(java.lang.String name)
Gets the byte offset into the binary stream of the specified
value.
|
short |
getShort(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a short value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
short[] |
getShortArray(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a short array (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
java.lang.String |
getString(java.lang.String name,
java.nio.ByteBuffer buffer)
Gets a string value (convenience method for
getValue(java.lang.String, java.nio.ByteBuffer) ). |
java.lang.Object |
getValue(java.lang.String name,
java.nio.ByteBuffer inputBuffer)
Gets a data value from a byte buffer using this reader's
template.
|
static void |
main(java.lang.String[] argv)
Tests this class.
|
public BinaryStreamReader(java.io.InputStream template) throws org.xml.sax.SAXException, java.io.IOException
template
- the XML template to use for reading binary
data values.java.io.IOException
- if an error occurred reading the XML
template.org.xml.sax.SAXException
- if an error occurred validating the XML
template.public static java.lang.Object convertText(java.lang.String text, noaa.coastwatch.io.BinaryStreamReader.ValueType type)
text
- the text string to convert.type
- the type to convert to.public byte getByte(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public byte[] getByteArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public short getShort(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public short[] getShortArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public int getInt(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public int[] getIntArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public long getLong(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public long[] getLongArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public float getFloat(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public float[] getFloatArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public double getDouble(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public double[] getDoubleArray(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public java.lang.String getString(java.lang.String name, java.nio.ByteBuffer buffer)
getValue(java.lang.String, java.nio.ByteBuffer)
).public int getOffset(java.lang.String name)
name
- the name of the value to retrieve.java.lang.IllegalArgumentException
- if the data value name does
not exist in the template.public java.lang.Object getValue(java.lang.String name, java.nio.ByteBuffer inputBuffer)
name
- the name of the value to retrieve.inputBuffer
- the input buffer to read from.java.lang.IllegalArgumentException
- if the data value name does
not exist in the template.public java.util.Set<java.lang.String> getNames()
public static void main(java.lang.String[] argv) throws java.lang.Exception
argv
- the array of command line parameters.java.lang.Exception