Package adams.flow.transformer
Class BinaryFileReader
-
- All Implemented Interfaces:
AdditionalInformationHandler
,ArrayProvider
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,VariableChangeListener
,Actor
,ArrayProvider
,ErrorHandler
,InputConsumer
,OutputProducer
,Serializable
,Comparable
public class BinaryFileReader extends AbstractTransformer implements ArrayProvider
Reads a binary file and forwards the content byte by byte or as byte array.
Input/output:
- accepts:
java.lang.String
java.io.File
- generates:
java.lang.Byte
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: BinaryFileReader
-annotation <adams.core.base.BaseText> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow gets stopped in case this actor encounters an error; useful for critical actors. default: false
-start <long> (property: start) The starting position in the file (1-based index). default: 1 minimum: 1
-end <long> (property: end) The last position in the file (incl; 1-based index; <0 denotes end-of-file ). default: -1 minimum: -1
-output-array <boolean> (property: outputArray) If enabled, outputs the file content as byte array rather than byte by byte. default: false
- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
BACKUP_FILE
the key for storing the current file the backup.static String
BACKUP_POSITION
the key for storing the current position the backup.static String
BACKUP_STREAM
the key for storing the current stream the backup.protected long
m_ActualEnd
the actual last position.protected File
m_CurrentFile
the current file to read from.protected gnu.trove.list.array.TByteArrayList
m_Data
the collected data.protected long
m_End
the end position.protected boolean
m_OutputArray
whether to output an array instead of single items.protected long
m_Position
the current position.protected long
m_Start
the start position.protected FileInputStream
m_Stream
the input stream.-
Fields inherited from class adams.flow.transformer.AbstractTransformer
BACKUP_INPUT, BACKUP_OUTPUT, m_InputToken, m_OutputToken
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description BinaryFileReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]
accepts()
Returns the class that the consumer accepts.protected Hashtable<String,Object>
backupState()
Backs up the current state of the actor before update the variables.protected void
closeStream()
Closes the stream if possible.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.String
endTipText()
Returns the tip text for this property.Class[]
generates()
Returns the class of objects that it generates.long
getEnd()
Returns the last position (incl.).boolean
getOutputArray()
Returns whether to output the file as byte array or byte by byte.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.long
getStart()
Returns the starting position.String
globalInfo()
Returns a string describing the object.boolean
hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.protected void
initialize()
Initializes the members.Token
output()
Returns the generated token.String
outputArrayTipText()
Returns the tip text for this property.protected void
pruneBackup()
Removes entries from the backup.protected void
reset()
Resets the actor.protected void
restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.void
setEnd(long value)
Sets the last position (incl).void
setOutputArray(boolean value)
Sets whether to output the file as byte array or byte by byte.void
setStart(long value)
Sets the starting position.String
startTipText()
Returns the tip text for this property.void
wrapUp()
Cleans up after the execution has finished.-
Methods inherited from class adams.flow.transformer.AbstractTransformer
currentInput, execute, hasInput, input, postExecute
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, preExecute, pruneBackup, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
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
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
BACKUP_POSITION
public static final String BACKUP_POSITION
the key for storing the current position the backup.- See Also:
- Constant Field Values
-
BACKUP_STREAM
public static final String BACKUP_STREAM
the key for storing the current stream the backup.- See Also:
- Constant Field Values
-
BACKUP_FILE
public static final String BACKUP_FILE
the key for storing the current file the backup.- See Also:
- Constant Field Values
-
m_Start
protected long m_Start
the start position.
-
m_End
protected long m_End
the end position.
-
m_Position
protected long m_Position
the current position.
-
m_ActualEnd
protected long m_ActualEnd
the actual last position.
-
m_Stream
protected transient FileInputStream m_Stream
the input stream.
-
m_CurrentFile
protected File m_CurrentFile
the current file to read from.
-
m_OutputArray
protected boolean m_OutputArray
whether to output an array instead of single items.
-
m_Data
protected gnu.trove.list.array.TByteArrayList m_Data
the collected data.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractActor
-
reset
protected void reset()
Resets the actor. Clears the output queue.- Overrides:
reset
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
pruneBackup
protected void pruneBackup()
Removes entries from the backup.- Overrides:
pruneBackup
in classAbstractActor
- See Also:
AbstractActor.reset()
-
backupState
protected Hashtable<String,Object> backupState()
Backs up the current state of the actor before update the variables.- Overrides:
backupState
in classAbstractTransformer
- Returns:
- the backup
- See Also:
AbstractActor.updateVariables()
,AbstractActor.restoreState(Hashtable)
-
restoreState
protected void restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.- Overrides:
restoreState
in classAbstractTransformer
- Parameters:
state
- the backup of the state to restore from- See Also:
AbstractActor.updateVariables()
,AbstractActor.backupState()
-
setStart
public void setStart(long value)
Sets the starting position.- Parameters:
value
- the position (1-based)
-
getStart
public long getStart()
Returns the starting position.- Returns:
- the position (1-based)
-
startTipText
public String startTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setEnd
public void setEnd(long value)
Sets the last position (incl).- Parameters:
value
- the position (1-based)
-
getEnd
public long getEnd()
Returns the last position (incl.).- Returns:
- the position (1-based)
-
endTipText
public String endTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setOutputArray
public void setOutputArray(boolean value)
Sets whether to output the file as byte array or byte by byte.- Specified by:
setOutputArray
in interfaceArrayProvider
- Specified by:
setOutputArray
in interfaceArrayProvider
- Parameters:
value
- true if output is an array
-
getOutputArray
public boolean getOutputArray()
Returns whether to output the file as byte array or byte by byte.- Specified by:
getOutputArray
in interfaceArrayProvider
- Specified by:
getOutputArray
in interfaceArrayProvider
- Returns:
- true if output is an array
-
outputArrayTipText
public String outputArrayTipText()
Returns the tip text for this property.- Specified by:
outputArrayTipText
in interfaceArrayProvider
- Specified by:
outputArrayTipText
in interfaceArrayProvider
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
accepts
public Class[] accepts()
Returns the class that the consumer accepts.- Specified by:
accepts
in interfaceInputConsumer
- Returns:
- java.lang.String.class, java.io.File.class
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Specified by:
generates
in interfaceOutputProducer
- Returns:
- java.lang.Byte.class
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
closeStream
protected void closeStream()
Closes the stream if possible.
-
hasPendingOutput
public boolean hasPendingOutput()
Checks whether there is pending output to be collected after executing the flow item.- Specified by:
hasPendingOutput
in interfaceOutputProducer
- Overrides:
hasPendingOutput
in classAbstractTransformer
- Returns:
- true if there is pending output
-
output
public Token output()
Returns the generated token.- Specified by:
output
in interfaceOutputProducer
- Overrides:
output
in classAbstractTransformer
- Returns:
- the generated token
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished.- Specified by:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractTransformer
-
-