@TestClass(value="org.openscience.cdk.io.CML2WriterTest") public class CMLWriter extends DefaultChemObjectWriter
IMoleculeSet
or a IMolecule
object to CML 2 code.
Chemical Markup Language is an XML-based file format .
Output can be redirected to other Writer objects like StringWriter
and FileWriter
. An example:
StringWriter output = new StringWriter(); boolean makeFragment = true; CMLWriter cmlwriter = new CMLWriter(output, makeFragment); cmlwriter.write(molecule); cmlwriter.close(); String cmlcode = output.toString();
Output to a file called "molecule.cml" can done with:
FileWriter output = new FileWriter("molecule.cml"); CMLWriter cmlwriter = new CMLWriter(output); cmlwriter.write(molecule); cmlwriter.close();
For atoms it outputs: coordinates, element type and formal charge. For bonds it outputs: order, atoms (2, or more) and wedges.
FileWriter
,
StringWriter
Constructor and Description |
---|
CMLWriter() |
CMLWriter(OutputStream output) |
CMLWriter(Writer out)
Constructs a new CMLWriter class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(Class classObject)
Returns whether the given
IChemObject can be read or written. |
void |
close()
Flushes the output and closes this object
|
IResourceFormat |
getFormat()
Returns the
IResourceFormat class for this IO class. |
IOSetting[] |
getIOSettings()
Returns an array of
IOSetting s defined by this IChemObjectIO class. |
void |
registerCustomizer(ICMLCustomizer customizer) |
void |
setWriter(OutputStream output)
Sets the OutputStream from which this ChemObjectWriter should write
the contents.
|
void |
setWriter(Writer writer)
Sets the Writer from which this ChemObjectWriter should write
the contents.
|
void |
write(IChemObject object)
Serializes the IChemObject to CML and redirects it to the output Writer.
|
addChemObjectIOListener, removeChemObjectIOListener
public CMLWriter(Writer out)
out
- Writer to redirect the output to.public CMLWriter(OutputStream output)
public CMLWriter()
public void registerCustomizer(ICMLCustomizer customizer)
@TestMethod(value="testGetFormat") public IResourceFormat getFormat()
IChemObjectIO
IResourceFormat
class for this IO class.public void setWriter(Writer writer) throws CDKException
IChemObjectWriter
CDKException
public void setWriter(OutputStream output) throws CDKException
IChemObjectWriter
CDKException
@TestMethod(value="testClose") public void close() throws IOException
IOException
@TestMethod(value="testAccepts") public boolean accepts(Class classObject)
IChemObjectIO
IChemObject
can be read or written.classObject
- IChemObject
of which is tested if it can be handled.IChemObject
can be handled.public void write(IChemObject object) throws CDKException
object
- A Molecule of MoleculeSet objectCDKException
- is thrown if the output
does not support the data in the objectpublic IOSetting[] getIOSettings()
IChemObjectIO
IOSetting
s defined by this IChemObjectIO class.getIOSettings
in interface IChemObjectIO
getIOSettings
in class DefaultChemObjectWriter
IOSetting
s for this class.