Package adams.data.io.output
Class AbstractSpreadSheetWriter
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.output.AbstractSpreadSheetWriter
-
- All Implemented Interfaces:
AdditionalInformationHandler
,Destroyable
,GlobalInfoSupporter
,EncodingSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,SpreadSheetWriter
,Serializable
- Direct Known Subclasses:
AbstractMultiSheetSpreadSheetWriter
,AbstractSpreadSheetWriterWithMissingValueSupport
,AbstractWekaSpreadSheetWriter
,AccessSpreadSheetWriter
,PropertiesSpreadSheetWriter
,SimpleArffSpreadSheetWriter
,SimpleStreamSpreadSheetWriter
,SqlDumpSpreadSheetWriter
public abstract class AbstractSpreadSheetWriter extends AbstractOptionHandler implements SpreadSheetWriter, EncodingSupporter, AdditionalInformationHandler
Ancestor for classes that can write spreadsheet objects.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractSpreadSheetWriter.OutputType
How to write the data.
-
Field Summary
Fields Modifier and Type Field Description protected BaseCharset
m_Encoding
the encoding to use.protected boolean
m_Stopped
whether the read process was stopped through an external source.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractSpreadSheetWriter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
canCompress(String filename)
Returns whether the file should get compressed, i.e.,supportsCompressedOutput()
returns true and the filename ends with ".gz".protected boolean
doWrite(SpreadSheet content, OutputStream out)
Performs the actual writing.protected boolean
doWrite(SpreadSheet content, Writer writer)
Performs the actual writing.protected boolean
doWrite(SpreadSheet content, String filename)
Performs the actual writing.String
encodingTipText()
Returns the tip text for this property.String
getAdditionalInformation()
Returns the additional information.String
getDefaultFormatExtension()
Returns the default extension of the format.BaseCharset
getEncoding()
Returns the encoding to use.abstract String
getFormatDescription()
Returns a string describing the format (used in the file chooser).abstract String[]
getFormatExtensions()
Returns the extension(s) of the format.protected abstract AbstractSpreadSheetWriter.OutputType
getOutputType()
Returns how the data is written.static String[]
getWriters()
Returns a list with classnames of writers.protected void
initialize()
Initializes the members.boolean
isStopped()
Returns whether the reading was stopped.protected void
preWriteFile(String filename)
Hook method before writing to a file.void
reset()
Resets the writer.void
setEncoding(BaseCharset value)
Sets the encoding to use.void
stopExecution()
Stops the reading (might not be immediate, depending on reader).protected boolean
supportsCompressedOutput()
Returns whether to automatically compress.boolean
write(SpreadSheet content, File file)
Writes the given content to the specified file.boolean
write(SpreadSheet content, OutputStream stream)
Writes the spreadsheet in CSV format to the given output stream.boolean
write(SpreadSheet content, Writer writer)
Writes the spreadsheet in CSV format to the given writer.boolean
write(SpreadSheet content, String filename)
Writes the spreadsheet in CSV format to the given file.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, defineOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, 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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, defineOptions, getOptionManager, toCommandLine
-
Methods inherited from interface adams.data.io.output.SpreadSheetWriter
getCorrespondingReader
-
-
-
-
Field Detail
-
m_Stopped
protected boolean m_Stopped
whether the read process was stopped through an external source.
-
m_Encoding
protected BaseCharset m_Encoding
the encoding to use.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
reset
public void reset()
Resets the writer.- Specified by:
reset
in interfaceSpreadSheetWriter
- Overrides:
reset
in classAbstractOptionHandler
-
getFormatDescription
public abstract String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceSpreadSheetWriter
- Returns:
- a description suitable for displaying in the file chooser
-
getFormatExtensions
public abstract String[] getFormatExtensions()
Returns the extension(s) of the format.- Specified by:
getFormatExtensions
in interfaceSpreadSheetWriter
- Returns:
- the extension (without the dot!)
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default extension of the format.- Returns:
- the default extension (without the dot!)
-
getAdditionalInformation
public String getAdditionalInformation()
Returns the additional information.- Specified by:
getAdditionalInformation
in interfaceAdditionalInformationHandler
- Returns:
- the additional information, null or 0-length string for no information
-
setEncoding
public void setEncoding(BaseCharset value)
Sets the encoding to use.- Specified by:
setEncoding
in interfaceEncodingSupporter
- Parameters:
value
- the encoding, e.g. "UTF-8" or "UTF-16", empty string for default
-
getEncoding
public BaseCharset getEncoding()
Returns the encoding to use.- Specified by:
getEncoding
in interfaceEncodingSupporter
- Returns:
- the encoding, e.g. "UTF-8" or "UTF-16", empty string for default
-
encodingTipText
public String encodingTipText()
Returns the tip text for this property.- Specified by:
encodingTipText
in interfaceEncodingSupporter
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getOutputType
protected abstract AbstractSpreadSheetWriter.OutputType getOutputType()
Returns how the data is written.- Returns:
- the type
-
supportsCompressedOutput
protected boolean supportsCompressedOutput()
Returns whether to automatically compress.
Default implementation returns false.- Returns:
- true if to automatically decompress
-
canCompress
protected boolean canCompress(String filename)
Returns whether the file should get compressed, i.e.,supportsCompressedOutput()
returns true and the filename ends with ".gz".- Parameters:
filename
- the filename to check- Returns:
- true if decompression should occur
-
preWriteFile
protected void preWriteFile(String filename)
Hook method before writing to a file.
Default implementation does nothing.- Parameters:
filename
- the filename to check
-
write
public boolean write(SpreadSheet content, File file)
Writes the given content to the specified file. Handles compression automatically, if the filename ends with ".gz",supportsCompressedOutput()
returns true and file is not being appended.- Specified by:
write
in interfaceSpreadSheetWriter
- Parameters:
content
- the content to writefile
- the file to write to- Returns:
- true if successfully written
- See Also:
supportsCompressedOutput()
,AppendableSpreadSheetWriter
-
write
public boolean write(SpreadSheet content, String filename)
Writes the spreadsheet in CSV format to the given file. Handles compression automatically, if the filename ends with ".gz",supportsCompressedOutput()
returns true and file is not being appended.- Specified by:
write
in interfaceSpreadSheetWriter
- Parameters:
content
- the spreadsheet to writefilename
- the file to write the spreadsheet to- Returns:
- true if successfully written
- See Also:
supportsCompressedOutput()
,AppendableSpreadSheetWriter
-
write
public boolean write(SpreadSheet content, OutputStream stream)
Writes the spreadsheet in CSV format to the given output stream. The caller must ensure that the stream gets closed.- Specified by:
write
in interfaceSpreadSheetWriter
- Parameters:
content
- the spreadsheet to writestream
- the output stream to write the spreadsheet to- Returns:
- true if successfully written
-
write
public boolean write(SpreadSheet content, Writer writer)
Writes the spreadsheet in CSV format to the given writer. The caller must ensure that the writer gets closed.- Specified by:
write
in interfaceSpreadSheetWriter
- Parameters:
content
- the spreadsheet to writewriter
- the writer to write the spreadsheet to- Returns:
- true if successfully written
-
doWrite
protected boolean doWrite(SpreadSheet content, String filename)
Performs the actual writing.
Default implementation returns always false.- Parameters:
content
- the spreadsheet to writefilename
- the file to write the spreadsheet to- Returns:
- true if successfully written
-
doWrite
protected boolean doWrite(SpreadSheet content, Writer writer)
Performs the actual writing. The caller must ensure that the writer gets closed.
Default implementation returns always false.- Parameters:
content
- the spreadsheet to writewriter
- the writer to write the spreadsheet to- Returns:
- true if successfully written
-
doWrite
protected boolean doWrite(SpreadSheet content, OutputStream out)
Performs the actual writing. The caller must ensure that the output stream gets closed.
Default implementation returns always false.- Parameters:
content
- the spreadsheet to writeout
- the output stream to write the spreadsheet to- Returns:
- true if successfully written
-
stopExecution
public void stopExecution()
Stops the reading (might not be immediate, depending on reader).- Specified by:
stopExecution
in interfaceStoppable
-
isStopped
public boolean isStopped()
Returns whether the reading was stopped.- Specified by:
isStopped
in interfaceStoppableWithFeedback
- Returns:
- true if stopped
-
getWriters
public static String[] getWriters()
Returns a list with classnames of writers.- Returns:
- the writer classnames
-
-