public class NcmlWriter extends Object
Modifier and Type | Class and Description |
---|---|
static class |
NcmlWriter.WriteVariablesWithNamesPredicate
Predicate that returns
true for variables whose names are specified to the constructor. |
Modifier and Type | Field and Description |
---|---|
static Predicate<? super Variable> |
writeAllVariablesPredicate
Predicate that always returns
true . |
static Predicate<? super Variable> |
writeCoordinateVariablesPredicate
Predicate that returns
true for variables that are
coordinate variables . |
static Predicate<? super Variable> |
writeMetadataVariablesPredicate
Predicate that returns
true for variables that are metadata variables . |
static Predicate<? super Variable> |
writeNoVariablesPredicate
Predicate that always returns
false . |
Constructor and Description |
---|
NcmlWriter()
Constructor with default values
|
NcmlWriter(org.jdom2.Namespace namespace,
org.jdom2.output.Format xmlFormat,
Predicate<? super Variable> writeValuesPredicate)
Constructor allows you to set parameters.
|
Modifier and Type | Method and Description |
---|---|
org.jdom2.Namespace |
getNamespace()
Gets the XML namespace for the elements in the NcML.
|
Predicate<? super Variable> |
getWriteValuesPredicate()
Gets the predicate that will be applied to variables to determine wither their values should be written in
addition to their metadata.
|
org.jdom2.output.Format |
getXmlFormat()
Gets the object that encapsulates XML formatting options.
|
org.jdom2.Element |
makeAttributeElement(Attribute attribute) |
org.jdom2.Element |
makeDimensionElement(Dimension dim) |
org.jdom2.Element |
makeEnumTypedefElement(EnumTypedef etd) |
org.jdom2.Element |
makeExplicitNetcdfElement(NetcdfFile ncFile,
String location) |
org.jdom2.Element |
makeGroupElement(Group group) |
org.jdom2.Element |
makeNetcdfElement(NetcdfFile ncFile,
String location) |
org.jdom2.Element |
makeValuesElement(Variable variable,
boolean allowRegular)
Creates a
<values> element from the variable's data. |
org.jdom2.Element |
makeVariableElement(Variable var,
boolean showValues) |
void |
writeToFile(org.jdom2.Element elem,
File outFile)
Writes an NcML element to an output file.
|
void |
writeToStream(org.jdom2.Element elem,
OutputStream outStream)
Writes an NcML element to an output stream.
|
String |
writeToString(org.jdom2.Element elem)
Writes an NcML element to a string.
|
void |
writeToWriter(org.jdom2.Element elem,
Writer writer)
Writes an NcML element to a Writer.
|
public static final Predicate<? super Variable> writeAllVariablesPredicate
true
.public static final Predicate<? super Variable> writeCoordinateVariablesPredicate
true
for variables that are
coordinate variables
.public static final Predicate<? super Variable> writeMetadataVariablesPredicate
true
for variables that are metadata variables
.
For such variables, the data is not actually present in the file, so we must include it in the NcML.
It could be synthesized (i.e. generated by an IOSP) or specified in a public NcmlWriter()
public NcmlWriter(@Nullable org.jdom2.Namespace namespace, @Nullable org.jdom2.output.Format xmlFormat, @Nullable Predicate<? super Variable> writeValuesPredicate)
namespace
- if null use ncmlDefaultNamespace.xmlFormat
- if null, use Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX).writeValuesPredicate
- if null, write a Variable's values if Variable.isMetadata(). This determines whether
values should be written or not. The values will be contained within a <values>
element.
By default, the predicate will be writeMetadataVariablesPredicate
. There could be data loss if the
values
of metadata variables aren't included in the NcML, so we recommend that you always use it, possibly as part
of a
compound predicate. For example, suppose you wanted to print the values of metadata and coordinate
variables:
PredicatecompoundPred = Predicates.or(writeMetadataVariablesPredicate, writeCoordinateVariablesPredicate); ncmlWriter.setWriteVariablesPredicate(compoundPred);
public org.jdom2.Namespace getNamespace()
ncmlDefaultNamespace
.public Predicate<? super Variable> getWriteValuesPredicate()
<values>
element.public org.jdom2.output.Format getXmlFormat()
pretty
with UNIX line separators
.public org.jdom2.Element makeAttributeElement(Attribute attribute)
public org.jdom2.Element makeDimensionElement(Dimension dim) throws IllegalArgumentException
IllegalArgumentException
public org.jdom2.Element makeEnumTypedefElement(EnumTypedef etd)
public org.jdom2.Element makeExplicitNetcdfElement(NetcdfFile ncFile, @Nullable String location)
public org.jdom2.Element makeGroupElement(Group group)
public org.jdom2.Element makeNetcdfElement(NetcdfFile ncFile, @Nullable String location)
public org.jdom2.Element makeValuesElement(Variable variable, boolean allowRegular) throws IOException
<values>
element from the variable's data.variable
- the variable to read values fromallowRegular
- true
if regular values should be represented with start
, increment
,
and npts
attributes instead of space-separated Element text. Has no effect if the data isn't
regular.<values>
element.IOException
- if there was an I/O error when reading the variable's data.public org.jdom2.Element makeVariableElement(Variable var, boolean showValues)
public void writeToFile(org.jdom2.Element elem, File outFile) throws IOException
elem
- an NcML element.outFile
- the file to write the NcML document to.IOException
- if there's any problem writing.public void writeToStream(org.jdom2.Element elem, OutputStream outStream) throws IOException
elem
- an NcML element.outStream
- the stream to write the NcML document to. Will be closed at end of the method.IOException
- if there's any problem writing.public String writeToString(org.jdom2.Element elem)
elem
- an NcML element.public void writeToWriter(org.jdom2.Element elem, Writer writer) throws IOException
elem
- an NcML element.writer
- the Writer to write the NcML document to. Will be closed at end of the method.IOException
- if there's any problem writing.