Package adams.data.io.input
Class AbstractFlowReader
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.io.input.AbstractFlowReader
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,FileFormatHandler
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,FlowReader
,Serializable
- Direct Known Subclasses:
AbstractNestedFlowReader
,JsonFlowReader
public abstract class AbstractFlowReader extends AbstractOptionHandler implements FlowReader
Ancestor for classes that can read flows.- 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
AbstractFlowReader.InputType
How to read the data.
-
Field Summary
Fields Modifier and Type Field Description protected MessageCollection
m_Errors
for storing errors.protected boolean
m_Quiet
whether to suppress logging output.protected MessageCollection
m_Warnings
for storing warnings.-
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 AbstractFlowReader()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addError(String msg)
Adds the error message.protected void
addError(String msg, Throwable t)
Adds the error message and exception.protected void
addWarning(String msg)
Adds the warning message.protected void
addWarning(String msg, Throwable t)
Adds the warning message and exception.protected void
check()
Hook method to perform some checks before performing the actual read.protected Actor
doReadActor(File file)
Performs the actual reading.protected Actor
doReadActor(InputStream in)
Performs the actual reading.protected Actor
doReadActor(Reader r)
Performs the actual reading.String
getDefaultFormatExtension()
Returns the default extension of the format.MessageCollection
getErrors()
Returns any errors that were encountered while reading.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 AbstractFlowReader.InputType
getInputType()
Returns how to read the data, from a file, stream or reader.static String[]
getReaders()
Returns a list with classnames of readers.MessageCollection
getWarnings()
Returns any warnings that were encountered while reading.protected void
initialize()
Initializes the members.boolean
isQuiet()
Returns whether logging output is suppressed.Actor
readActor(File file)
Reads the flow from the specified file.Actor
readActor(InputStream stream)
Reads the flow from the stream.Actor
readActor(Reader r)
Reads the flow from the given reader.Actor
readActor(String filename)
Reads the flow from the given file.void
setQuiet(boolean value)
Sets whether to suppress logging output.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, defineOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, reset, 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.data.io.input.FlowReader
getCorrespondingWriter
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, defineOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
m_Warnings
protected MessageCollection m_Warnings
for storing warnings.
-
m_Errors
protected MessageCollection m_Errors
for storing errors.
-
m_Quiet
protected boolean m_Quiet
whether to suppress logging output.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
getFormatDescription
public abstract String getFormatDescription()
Returns a string describing the format (used in the file chooser).- Specified by:
getFormatDescription
in interfaceFileFormatHandler
- 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 interfaceFileFormatHandler
- Returns:
- the extension (without the dot!)
-
getDefaultFormatExtension
public String getDefaultFormatExtension()
Returns the default extension of the format.- Specified by:
getDefaultFormatExtension
in interfaceFileFormatHandler
- Returns:
- the default extension (without the dot!)
-
getInputType
protected abstract AbstractFlowReader.InputType getInputType()
Returns how to read the data, from a file, stream or reader.- Returns:
- how to read the data
-
setQuiet
public void setQuiet(boolean value)
Sets whether to suppress logging output.- Parameters:
value
- true if to suppress
-
isQuiet
public boolean isQuiet()
Returns whether logging output is suppressed.- Returns:
- true if suppressed
-
check
protected void check()
Hook method to perform some checks before performing the actual read.
Default implementation only clears warnings/errors.
-
readActor
public Actor readActor(File file)
Reads the flow from the specified file.- Specified by:
readActor
in interfaceFlowReader
- Parameters:
file
- the file to read from- Returns:
- null in case of an error, otherwise the flow
-
readActor
public Actor readActor(String filename)
Reads the flow from the given file.- Specified by:
readActor
in interfaceFlowReader
- Parameters:
filename
- the file to read from- Returns:
- the flow or null in case of an error
-
readActor
public Actor readActor(InputStream stream)
Reads the flow from the stream. The caller must ensure to close the stream.- Specified by:
readActor
in interfaceFlowReader
- Parameters:
stream
- the stream to read from- Returns:
- the flow or null in case of an error
-
readActor
public Actor readActor(Reader r)
Reads the flow from the given reader. The caller must ensure to close the reader.- Specified by:
readActor
in interfaceFlowReader
- Parameters:
r
- the reader to read from- Returns:
- the flow or null in case of an error
-
doReadActor
protected Actor doReadActor(File file)
Performs the actual reading.
Default implementation returns null.- Parameters:
file
- the file to read from- Returns:
- the flow or null in case of an error
- See Also:
getInputType()
-
doReadActor
protected Actor doReadActor(Reader r)
Performs the actual reading.
Default implementation returns null.- Parameters:
r
- the reader to read from- Returns:
- the flow or null in case of an error
- See Also:
getInputType()
-
doReadActor
protected Actor doReadActor(InputStream in)
Performs the actual reading.
Default implementation returns null.- Parameters:
in
- the input stream to read from- Returns:
- the flow or null in case of an error
- See Also:
getInputType()
-
addWarning
protected void addWarning(String msg)
Adds the warning message.- Parameters:
msg
- the warning message to add
-
addWarning
protected void addWarning(String msg, Throwable t)
Adds the warning message and exception.- Parameters:
msg
- the warning message to addt
- the exception, ignored if null
-
getWarnings
public MessageCollection getWarnings()
Returns any warnings that were encountered while reading.- Specified by:
getWarnings
in interfaceFlowReader
- Returns:
- the warnings
-
addError
protected void addError(String msg)
Adds the error message.- Parameters:
msg
- the error message to add
-
addError
protected void addError(String msg, Throwable t)
Adds the error message and exception.- Parameters:
msg
- the error message to addt
- the exception, ignored if null
-
getErrors
public MessageCollection getErrors()
Returns any errors that were encountered while reading.- Specified by:
getErrors
in interfaceFlowReader
- Returns:
- the errors
-
getReaders
public static String[] getReaders()
Returns a list with classnames of readers.- Returns:
- the reader classnames
-
-