public abstract class HDFWriter extends EarthDataWriter implements HDFSD
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed
Flag to signify that the file is closed.
|
static int |
DEFAULT_CHUNK_SIZE
Default HDF chunk size in bytes.
|
protected int |
sdid
HDF file id.
|
info, isCanceled, variables, writeProgress, writeVariableName, writeVariables
Modifier | Constructor and Description |
---|---|
protected |
HDFWriter(EarthDataInfo info,
java.lang.String file)
Creates a new HDF file from the specified earth data info and
file name.
|
protected |
HDFWriter(java.lang.String file)
Opens an existing HDF file for writing using the specified file
name.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the writer and frees any resources.
|
void |
flush()
Flushes all unwritten data to the destination.
|
boolean |
getChunked()
Gets the HDF chunking flag.
|
int |
getChunkSize()
Gets the current chunk size in bytes.
|
boolean |
getCompressed()
Gets the HDF compression flag.
|
java.lang.String |
getFilename()
Gets the HDF scientific dataset file name.
|
int |
getSDID()
Gets the HDF scientific dataset ID.
|
static int |
getType(java.lang.Class c,
boolean isUnsigned)
Gets the HDF type associated with a Java primitive class.
|
static void |
setAttribute(int sdid,
java.lang.String name,
java.lang.Object value)
Sets an HDF attribute value.
|
static void |
setAttributes(int sdid,
java.util.Map map,
boolean overwrite)
Sets a number of attributes based on a map.
|
static void |
setChunkCompress(int sdsid,
boolean compressed,
int[] chunk_lengths)
Sets the chunking and compression for an SDS HDF variable.
|
void |
setChunked(boolean chunked)
Sets the HDF chunking flag.
|
void |
setChunkSize(int size)
Sets the chunk size.
|
void |
setCompressed(boolean compressed)
Sets the HDF compression flag.
|
protected abstract void |
setGlobalInfo()
Writes the earth data info metadata.
|
protected abstract void |
setVariableInfo(int sdsid,
DataVariable var)
Writes the data variable metadata.
|
protected void |
writeVariable(DataVariable var,
boolean chunked,
boolean compressed)
Creates and writes an HDF variable.
|
addVariable, cancel, finalize, getDestination, getProgress, getProgressLength, getProgressVariable
public static final int DEFAULT_CHUNK_SIZE
protected int sdid
protected boolean closed
protected HDFWriter(java.lang.String file) throws hdf.hdflib.HDFException
EarthDataInfo
instance variable.file
- the HDF file name.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.protected HDFWriter(EarthDataInfo info, java.lang.String file) throws hdf.hdflib.HDFException
info
- the earth data info object.file
- the new HDF file name.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.setGlobalInfo()
public int getSDID()
HDFSD
public java.lang.String getFilename()
HDFSD
getFilename
in interface HDFSD
public void setCompressed(boolean compressed)
flush
will cause variable data will be
written compressed.compressed
- the compression flag.flush()
public void setChunked(boolean chunked)
flush
will cause variable data will be written in
a chunked form.chunked
- the chunking flag.flush()
public boolean getChunked()
public boolean getCompressed()
public static int getType(java.lang.Class c, boolean isUnsigned) throws java.lang.ClassNotFoundException
c
- the Java primitive class.isUnsigned
- the unsigned flag, true if unsigned type desired.java.lang.ClassNotFoundException
- if a type cannot be found that
matches the Java class.public static void setAttribute(int sdid, java.lang.String name, java.lang.Object value) throws hdf.hdflib.HDFException, java.lang.ClassNotFoundException
sdid
- the HDF scientific dataset ID.name
- the attribute name.value
- the attribute value. If the attribute value is a
Java String
, a character string is written. If the
attribute is a Java primitive wrapped in an object, only one
value is written. If the attribute value is a Java primitive
array, multiple values are written.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.java.lang.ClassNotFoundException
- if the HDF attribute type is unknown.public static void setAttributes(int sdid, java.util.Map map, boolean overwrite) throws hdf.hdflib.HDFException, java.lang.ClassNotFoundException
sdid
- the HDF scientific dataset or variable ID for writing.map
- the attribute map.overwrite
- set to true to overwrite an attribute value that
already exists in the file, or false to leave existing attribute
values the same.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.java.lang.ClassNotFoundException
- if the HDF attribute type is unknown.public void setChunkSize(int size)
size
- the chunk size in bytes.public int getChunkSize()
protected abstract void setGlobalInfo() throws hdf.hdflib.HDFException, java.io.IOException, java.lang.ClassNotFoundException, java.io.UnsupportedEncodingException
hdf.hdflib.HDFException
- if an error occurred in an HDF routine.java.io.IOException
- if an error occurred writing the file metadata.java.lang.ClassNotFoundException
- if the HDF attribute type is unknown.java.io.UnsupportedEncodingException
- if the transform class encoding
is not supported.protected abstract void setVariableInfo(int sdsid, DataVariable var) throws hdf.hdflib.HDFException, java.io.IOException, java.lang.ClassNotFoundException
sdsid
- the variable HDF scientific dataset ID.var
- the variable for which to write info.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.java.io.IOException
- if an error occurred writing the file metadata.java.lang.ClassNotFoundException
- if the HDF attribute type is unknown.protected void writeVariable(DataVariable var, boolean chunked, boolean compressed) throws hdf.hdflib.HDFException, java.io.IOException, java.lang.ClassNotFoundException
var
- the variable for writing.chunked
- the chunking flag, true is chunking should be used.compressed
- the compression flag, true if compression should
be used.hdf.hdflib.HDFException
- if an error occurred in an HDF routine.java.io.IOException
- if an error occurred writing the file metadata.java.lang.ClassNotFoundException
- if the HDF attribute type is unknown.public void flush() throws java.io.IOException
EarthDataWriter
flush
in class EarthDataWriter
java.io.IOException
- if the data destination had I/O errors.public static void setChunkCompress(int sdsid, boolean compressed, int[] chunk_lengths) throws hdf.hdflib.HDFException
sdsid
- the HDF SDS variable ID.compressed
- the compression flag, true if compression should
be used. Compression is set to GZIP at level 6.chunk_lengths
- the chunk lengths, one for each dimension.
If null, no chunking if performed.hdf.hdflib.HDFException
- if an HDF error occurred.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.