Package noaa.coastwatch.io
Class BinaryStreamReader
java.lang.Object
noaa.coastwatch.io.BinaryStreamReader
The 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>
- Since:
- 3.2.2
- Author:
- Peter Hollemans
-
Constructor Summary
ConstructorDescriptionBinaryStreamReader
(InputStream template) Creates a new reader from the specified buffer and template. -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
convertText
(String text, noaa.coastwatch.io.BinaryStreamReader.ValueType type) Converts a text value to a typed value.byte
getByte
(String name, ByteBuffer buffer) Gets a byte value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).byte[]
getByteArray
(String name, ByteBuffer buffer) Gets a byte array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).double
getDouble
(String name, ByteBuffer buffer) Gets a double value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).double[]
getDoubleArray
(String name, ByteBuffer buffer) Gets a double array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).float
getFloat
(String name, ByteBuffer buffer) Gets a float value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).float[]
getFloatArray
(String name, ByteBuffer buffer) Gets a float array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).int
getInt
(String name, ByteBuffer buffer) Gets an integer value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).int[]
getIntArray
(String name, ByteBuffer buffer) Gets an integer array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).long
getLong
(String name, ByteBuffer buffer) Gets a long value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).long[]
getLongArray
(String name, ByteBuffer buffer) Gets a long array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).getNames()
Gets the data value names.int
Gets the byte offset into the binary stream of the specified value.short
getShort
(String name, ByteBuffer buffer) Gets a short value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).short[]
getShortArray
(String name, ByteBuffer buffer) Gets a short array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).getString
(String name, ByteBuffer buffer) Gets a string value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
).getValue
(String name, ByteBuffer inputBuffer) Gets a data value from a byte buffer using this reader's template.static void
Tests this class.
-
Constructor Details
-
BinaryStreamReader
Creates a new reader from the specified buffer and template.- Parameters:
template
- the XML template to use for reading binary data values.- Throws:
IOException
- if an error occurred reading the XML template.SAXException
- if an error occurred validating the XML template.
-
-
Method Details
-
convertText
Converts a text value to a typed value.- Parameters:
text
- the text string to convert.type
- the type to convert to.- Returns:
- the typed value.
-
getByte
Gets a byte value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getByteArray
Gets a byte array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getShort
Gets a short value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getShortArray
Gets a short array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getInt
Gets an integer value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getIntArray
Gets an integer array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getLong
Gets a long value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getLongArray
Gets a long array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getFloat
Gets a float value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getFloatArray
Gets a float array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getDouble
Gets a double value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getDoubleArray
Gets a double array (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getString
Gets a string value (convenience method forgetValue(java.lang.String, java.nio.ByteBuffer)
). -
getOffset
Gets the byte offset into the binary stream of the specified value.- Parameters:
name
- the name of the value to retrieve.- Returns:
- the byte offset.
- Throws:
IllegalArgumentException
- if the data value name does not exist in the template.
-
getValue
Gets a data value from a byte buffer using this reader's template.- Parameters:
name
- the name of the value to retrieve.inputBuffer
- the input buffer to read from.- Returns:
- the data value as a number, array, or string.
- Throws:
IllegalArgumentException
- if the data value name does not exist in the template.
-
getNames
Gets the data value names.- Returns:
- the list of data value names.
-
main
Tests this class.- Parameters:
argv
- the array of command line parameters.- Throws:
Exception
-