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 classAbstractSpreadSheetWriter.OutputTypeHow to write the data.
-
Field Summary
Fields Modifier and Type Field Description protected BaseCharsetm_Encodingthe encoding to use.protected booleanm_Stoppedwhether 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 booleancanCompress(String filename)Returns whether the file should get compressed, i.e.,supportsCompressedOutput()returns true and the filename ends with ".gz".protected booleandoWrite(SpreadSheet content, OutputStream out)Performs the actual writing.protected booleandoWrite(SpreadSheet content, Writer writer)Performs the actual writing.protected booleandoWrite(SpreadSheet content, String filename)Performs the actual writing.StringencodingTipText()Returns the tip text for this property.StringgetAdditionalInformation()Returns the additional information.StringgetDefaultFormatExtension()Returns the default extension of the format.BaseCharsetgetEncoding()Returns the encoding to use.abstract StringgetFormatDescription()Returns a string describing the format (used in the file chooser).abstract String[]getFormatExtensions()Returns the extension(s) of the format.protected abstract AbstractSpreadSheetWriter.OutputTypegetOutputType()Returns how the data is written.static String[]getWriters()Returns a list with classnames of writers.protected voidinitialize()Initializes the members.booleanisStopped()Returns whether the reading was stopped.protected voidpreWriteFile(String filename)Hook method before writing to a file.voidreset()Resets the writer.voidsetEncoding(BaseCharset value)Sets the encoding to use.voidstopExecution()Stops the reading (might not be immediate, depending on reader).protected booleansupportsCompressedOutput()Returns whether to automatically compress.booleanwrite(SpreadSheet content, File file)Writes the given content to the specified file.booleanwrite(SpreadSheet content, OutputStream stream)Writes the spreadsheet in CSV format to the given output stream.booleanwrite(SpreadSheet content, Writer writer)Writes the spreadsheet in CSV format to the given writer.booleanwrite(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:
initializein classAbstractOptionHandler
-
reset
public void reset()
Resets the writer.- Specified by:
resetin interfaceSpreadSheetWriter- Overrides:
resetin classAbstractOptionHandler
-
getFormatDescription
public abstract String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescriptionin 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:
getFormatExtensionsin 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:
getAdditionalInformationin 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:
setEncodingin 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:
getEncodingin 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:
encodingTipTextin 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:
writein 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:
writein 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:
writein 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:
writein 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:
stopExecutionin interfaceStoppable
-
isStopped
public boolean isStopped()
Returns whether the reading was stopped.- Specified by:
isStoppedin interfaceStoppableWithFeedback- Returns:
- true if stopped
-
getWriters
public static String[] getWriters()
Returns a list with classnames of writers.- Returns:
- the writer classnames
-
-