Package ucar.nc2.write
Class NcmlWriter
java.lang.Object
ucar.nc2.write.NcmlWriter
Helper class to write NcML.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPredicate that returnstruefor variables whose names are specified to the constructor. -
Field Summary
FieldsModifier and TypeFieldDescriptionPredicate that always returnstrue.Predicate that returnstruefor variables that arecoordinate variables.Predicate that returnstruefor variables that aremetadata variables.Predicate that always returnsfalse. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default valuesNcmlWriter(org.jdom2.Namespace namespace, org.jdom2.output.Format xmlFormat, Predicate<? super Variable> writeValuesPredicate) Constructor allows you to set parameters. -
Method Summary
Modifier and TypeMethodDescriptionorg.jdom2.NamespaceGets the XML namespace for the elements in the NcML.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.FormatGets the object that encapsulates XML formatting options.org.jdom2.ElementmakeAttributeElement(Attribute attribute) org.jdom2.Elementorg.jdom2.Elementorg.jdom2.ElementmakeExplicitNetcdfElement(NetcdfFile ncFile, String location) org.jdom2.ElementmakeGroupElement(Group group) org.jdom2.ElementmakeNetcdfElement(NetcdfFile ncFile, String location) org.jdom2.ElementmakeValuesElement(Variable variable, boolean allowRegular) Creates a<values>element from the variable's data.org.jdom2.ElementmakeVariableElement(Variable var, boolean showValues) voidwriteToFile(org.jdom2.Element elem, File outFile) Writes an NcML element to an output file.voidwriteToStream(org.jdom2.Element elem, OutputStream outStream) Writes an NcML element to an output stream.writeToString(org.jdom2.Element elem) Writes an NcML element to a string.voidwriteToWriter(org.jdom2.Element elem, Writer writer) Writes an NcML element to a Writer.
-
Field Details
-
writeNoVariablesPredicate
Predicate that always returnsfalse. -
writeMetadataVariablesPredicate
Predicate that returnstruefor variables that aremetadata 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 aelement of the input NcML. -
writeCoordinateVariablesPredicate
Predicate that returnstruefor variables that arecoordinate variables. -
writeAllVariablesPredicate
Predicate that always returnstrue.
-
-
Constructor Details
-
NcmlWriter
public NcmlWriter(@Nullable org.jdom2.Namespace namespace, @Nullable org.jdom2.output.Format xmlFormat, @Nullable Predicate<? super Variable> writeValuesPredicate) Constructor allows you to set parameters. Any parameters may be null for default.- Parameters:
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 bewriteMetadataVariablesPredicate. 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);
-
NcmlWriter
public NcmlWriter()Constructor with default values
-
-
Method Details
-
getNamespace
public org.jdom2.Namespace getNamespace()Gets the XML namespace for the elements in the NcML. By default, it isncmlDefaultNamespace.- Returns:
- the XML namespace.
-
getXmlFormat
public org.jdom2.output.Format getXmlFormat()Gets the object that encapsulates XML formatting options. By default, the format isprettywithUNIX line separators.- Returns:
- the XML formatting options.
-
getWriteValuesPredicate
Gets the predicate that will be applied to variables to determine wither their values should be written in addition to their metadata. The values will be contained within a<values>element.- Returns:
- the predicate.
-
writeToString
Writes an NcML element to a string.- Parameters:
elem- an NcML element.- Returns:
- the string that represents the NcML document.
-
writeToFile
Writes an NcML element to an output file.- Parameters:
elem- an NcML element.outFile- the file to write the NcML document to.- Throws:
IOException- if there's any problem writing.
-
writeToStream
Writes an NcML element to an output stream.- Parameters:
elem- an NcML element.outStream- the stream to write the NcML document to. Will be closed at end of the method.- Throws:
IOException- if there's any problem writing.
-
writeToWriter
Writes an NcML element to a Writer.- Parameters:
elem- an NcML element.writer- the Writer to write the NcML document to. Will be closed at end of the method.- Throws:
IOException- if there's any problem writing.
-
makeExplicitNetcdfElement
-
makeNetcdfElement
-
makeGroupElement
-
makeEnumTypedefElement
-
makeDimensionElement
- Throws:
IllegalArgumentException
-
makeVariableElement
-
makeAttributeElement
-
makeValuesElement
public org.jdom2.Element makeValuesElement(Variable variable, boolean allowRegular) throws IOException Creates a<values>element from the variable's data.- Parameters:
variable- the variable to read values fromallowRegular-trueif regular values should be represented withstart,increment, andnptsattributes instead of space-separated Element text. Has no effect if the data isn't regular.- Returns:
- the
<values>element. - Throws:
IOException- if there was an I/O error when reading the variable's data.
-