Package adams.data.io.output
Class JsonSpectrumWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractDataContainerWriter<Spectrum>
-
- adams.data.io.output.AbstractSpectrumWriter
-
- adams.data.io.output.AbstractTextBasedSpectrumWriter
-
- adams.data.io.output.JsonSpectrumWriter
-
- All Implemented Interfaces:
adams.core.AdditionalInformationHandler,adams.core.CleanUpHandler,adams.core.Destroyable,adams.core.GlobalInfoSupporter,adams.core.io.FileFormatHandler,adams.core.io.PrettyPrintingSupporter,adams.core.logging.LoggingLevelHandler,adams.core.logging.LoggingSupporter,adams.core.option.OptionHandler,adams.core.ShallowCopySupporter<adams.data.io.output.DataContainerWriter>,adams.core.SizeOfHandler,adams.data.io.output.DataContainerWriter<Spectrum>,adams.data.io.output.StreamableDataContainerWriter<Spectrum>,adams.data.io.output.StreamableTextBasedDataContainerWriter<Spectrum>,Serializable,Comparable
public class JsonSpectrumWriter extends AbstractTextBasedSpectrumWriter implements adams.core.io.PrettyPrintingSupporter
Writes spectra in JSON format.
Output format for single spectrum:
- outputting the complete report:
{
"id": "someid",
"format": "NIR",
"waves": [1.0, 2.0],
"amplitudes": [1.1, 2.1],
"report": {
"Sample ID": "someid",
"GLV2": 1.123,
"valid": true
}
}
- outputting specific reference and meta-data values:
{
"id": "someid",
"format": "NIR",
"waves": [1.0, 2.0],
"amplitudes": [1.1, 2.1],
"reference": {
"GLV2": 1.123
},
"meta-data": {
"valid": true
}
}
Multiple spectra get wrapped in an array called 'spectra'.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-output <adams.core.io.PlaceholderFile> (property: output) The file to write the container to. default: ${TMP}/out.tmp-use-reference-and-metadata <boolean> (property: useReferenceAndMetaData) If enabled, the only the specified reference and meta-data report values are output (in separate sections). default: false
-reference-value <adams.data.report.Field> [-reference-value ...] (property: referenceValues) The reference values to output. default:
-metadata-value <adams.data.report.Field> [-metadata-value ...] (property: metaDataValues) The meta-data values to output. default:
-pretty-printing <boolean> (property: prettyPrinting) If enabled, the output is printed in a 'pretty' format. default: false
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected adams.data.report.Field[]m_MetaDataValuesthe meta-data values.protected booleanm_PrettyPrintingwhether to use pretty-printing.protected adams.data.report.Field[]m_ReferenceValuesthe reference values.protected booleanm_UseReferenceAndMetaDatawhether to output speficied reference and meta-data values.
-
Constructor Summary
Constructors Constructor Description JsonSpectrumWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanWriteMultiple()Returns whether writing of multiple containers is supported.voiddefineOptions()Adds options to the internal list of options.StringgetFormatDescription()Returns a string describing the format (used in the file chooser).String[]getFormatExtensions()Returns the extension(s) of the format.adams.data.report.Field[]getMetaDataValues()Returns the meta-data values to output.booleangetPrettyPrinting()Returns whether pretty-printing is used or not.adams.data.report.Field[]getReferenceValues()Returns the reference values to output.booleangetUseReferenceAndMetaData()Returns whether only the specified reference and meta-data report values are output (in separate sections).StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.StringmetaDataValuesTipText()Returns the tip text for this property.StringprettyPrintingTipText()Returns the tip text for this property.StringreferenceValuesTipText()Returns the tip text for this property.voidsetMetaDataValues(adams.data.report.Field[] value)Sets the meta-data values to output.voidsetPrettyPrinting(boolean value)Sets whether to use pretty-printing or not.voidsetReferenceValues(adams.data.report.Field[] value)Sets the reference values to output.voidsetUseReferenceAndMetaData(boolean value)Sets whether only the specified reference and meta-data report values are output (in separate sections).StringuseReferenceAndMetaDataTipText()Returns the tip text for this property.protected booleanwriteData(List<Spectrum> data, Writer writer)Performs the actual writing.-
Methods inherited from class adams.data.io.output.AbstractTextBasedSpectrumWriter
write, write, writeData
-
Methods inherited from class adams.data.io.output.AbstractSpectrumWriter
getWriters, outputTipText
-
Methods inherited from class adams.data.io.output.AbstractDataContainerWriter
checkData, cleanUp, compareTo, destroy, equals, forCommandLine, forName, getAdditionalInformation, getDefaultFormatExtension, getOutput, isOutputFile, reset, setOutput, shallowCopy, shallowCopy, write, write
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface adams.data.io.output.DataContainerWriter
getOutput, isOutputFile, outputTipText, setOutput, write, write
-
-
-
-
Field Detail
-
m_UseReferenceAndMetaData
protected boolean m_UseReferenceAndMetaData
whether to output speficied reference and meta-data values.
-
m_ReferenceValues
protected adams.data.report.Field[] m_ReferenceValues
the reference values.
-
m_MetaDataValues
protected adams.data.report.Field[] m_MetaDataValues
the meta-data values.
-
m_PrettyPrinting
protected boolean m_PrettyPrinting
whether to use pretty-printing.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceadams.core.GlobalInfoSupporter- Specified by:
globalInfoin classadams.core.option.AbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceadams.core.option.OptionHandler- Overrides:
defineOptionsin classadams.data.io.output.AbstractDataContainerWriter<Spectrum>
-
setUseReferenceAndMetaData
public void setUseReferenceAndMetaData(boolean value)
Sets whether only the specified reference and meta-data report values are output (in separate sections).- Parameters:
value- true if to use pretty-printing
-
getUseReferenceAndMetaData
public boolean getUseReferenceAndMetaData()
Returns whether only the specified reference and meta-data report values are output (in separate sections).- Returns:
- true if to use pretty-printing
-
useReferenceAndMetaDataTipText
public String useReferenceAndMetaDataTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setReferenceValues
public void setReferenceValues(adams.data.report.Field[] value)
Sets the reference values to output.- Parameters:
value- the fields
-
getReferenceValues
public adams.data.report.Field[] getReferenceValues()
Returns the reference values to output.- Returns:
- the fields
-
referenceValuesTipText
public String referenceValuesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMetaDataValues
public void setMetaDataValues(adams.data.report.Field[] value)
Sets the meta-data values to output.- Parameters:
value- the fields
-
getMetaDataValues
public adams.data.report.Field[] getMetaDataValues()
Returns the meta-data values to output.- Returns:
- the fields
-
metaDataValuesTipText
public String metaDataValuesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPrettyPrinting
public void setPrettyPrinting(boolean value)
Sets whether to use pretty-printing or not.- Specified by:
setPrettyPrintingin interfaceadams.core.io.PrettyPrintingSupporter- Parameters:
value- true if to use pretty-printing
-
getPrettyPrinting
public boolean getPrettyPrinting()
Returns whether pretty-printing is used or not.- Specified by:
getPrettyPrintingin interfaceadams.core.io.PrettyPrintingSupporter- Returns:
- true if to use pretty-printing
-
prettyPrintingTipText
public String prettyPrintingTipText()
Returns the tip text for this property.- Specified by:
prettyPrintingTipTextin interfaceadams.core.io.PrettyPrintingSupporter- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getFormatDescription
public String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescriptionin interfaceadams.core.io.FileFormatHandler- Specified by:
getFormatDescriptionin classadams.data.io.output.AbstractDataContainerWriter<Spectrum>- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensionsin interfaceadams.core.io.FileFormatHandler- Specified by:
getFormatExtensionsin classadams.data.io.output.AbstractDataContainerWriter<Spectrum>- Returns:
- the extension(s) (without the dot!)
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classadams.core.option.AbstractOptionHandler
-
canWriteMultiple
public boolean canWriteMultiple()
Returns whether writing of multiple containers is supported.- Specified by:
canWriteMultiplein interfaceadams.data.io.output.DataContainerWriter<Spectrum>- Overrides:
canWriteMultiplein classAbstractSpectrumWriter- Returns:
- true if multiple containers are supported
-
writeData
protected boolean writeData(List<Spectrum> data, Writer writer)
Performs the actual writing.- Specified by:
writeDatain classAbstractTextBasedSpectrumWriter- Parameters:
data- the data to writewriter- the writer to write the spectra to- Returns:
- true if successfully written
-
-