public abstract class BinaryWriter extends EarthDataWriter
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CHUNK_SIZE
Output buffer size in kilobytes.
|
static int |
HOST
Host byte order.
|
static int |
LSB
Least significant byte first.
|
static int |
MSB
Most significant byte first.
|
info, isCanceled, variables, writeProgress, writeVariableName, writeVariables
Constructor and Description |
---|
BinaryWriter(EarthDataInfo info,
java.lang.String file)
Creates a new binary file from the specified earth data info
and file name.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
byteSwap(byte[] array)
Performs a byte swap on a byte array.
|
void |
close()
Closes the writer and frees any resources.
|
abstract byte[] |
convertValue(java.lang.Number value)
Converts a data value to a byte array.
|
void |
flush()
Flushes all unwritten data to the destination.
|
static byte[] |
getBytes(int value)
Gets the bytes representing an integer in MSB order.
|
static byte[] |
getBytes(short value)
Gets the bytes representing a short integer in MSB order.
|
abstract java.lang.Number |
getDefaultMissing()
Gets the default missing value.
|
abstract double |
getTypeMax()
Gets the type maximum as a double.
|
abstract double |
getTypeMin()
Gets the type minimum as a double.
|
abstract double |
getTypeRange()
Gets the type range as a double.
|
void |
setHeader(boolean header)
Sets the header flag.
|
void |
setMissing(java.lang.Number missing)
Sets the missing value.
|
void |
setOrder(int order)
Sets the byte order.
|
void |
setRange(double min,
double max)
Sets the scaling range.
|
void |
setScaling(double[] scaling)
Sets the scaling factor and offset.
|
protected void |
writeHeader(DataVariable var)
Writes a dimension header.
|
protected void |
writeVariable(DataVariable var)
Writes the variable data as a stream of binary data values.
|
addVariable, cancel, finalize, getDestination, getProgress, getProgressLength, getProgressVariable
public static final int HOST
public static final int MSB
public static final int LSB
public static final int DEFAULT_CHUNK_SIZE
public BinaryWriter(EarthDataInfo info, java.lang.String file) throws java.io.IOException
HOST
,
scaling is unity, the missing value is set to the default, and
the header flag is false.info
- the earth data info object.file
- the new binary file name.java.io.IOException
- if an error occurred opening the file.public void setHeader(boolean header)
header
- the header flag. If true, a dimension header is
written before any data.public void setOrder(int order)
order
- the byte order. The options are HOST
for host byte order, MSB
for most significant byte
first and LSB
for least significant byte first.public void setRange(double min, double max)
integer = type_min + type_range*((value - min) / (max - min))where
type_min
and type_range
are
determined by the implementing class. Any data values outside
the specified range are mapped to the missing value.min
- the minimum data value.max
- the maximum data value.public void setScaling(double[] scaling)
integer = value/factor + offset
scaling
- the scaling as [factor, offset]. If null, [1,0]
is used.public void setMissing(java.lang.Number missing)
missing
- the missing value. The missing value is used to
represent missing or out of range data. If null, the missing
value is set to the default.public static byte[] byteSwap(byte[] array)
public static byte[] getBytes(int value)
public static byte[] getBytes(short value)
protected void writeHeader(DataVariable var) throws java.io.IOException
var
- the data variable to write a header for.java.io.IOException
- if an error occurred writing the header data
to the file.public abstract byte[] convertValue(java.lang.Number value)
getTypeMin()
to getTypeMax()
.value
- the value for conversion.public abstract double getTypeMin()
public abstract double getTypeMax()
public abstract double getTypeRange()
public abstract java.lang.Number getDefaultMissing()
protected void writeVariable(DataVariable var) throws java.io.IOException
var
- the data variable to write data for.java.io.IOException
- if an error occurred writing the data
to the file.public void flush() throws java.io.IOException
EarthDataWriter
flush
in class EarthDataWriter
java.io.IOException
- if the data destination had I/O errors.public void close() throws java.io.IOException
EarthDataWriter
flush
method is called prior to closing.close
in class EarthDataWriter
java.io.IOException
- if the data destination had I/O errors.