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 StringBACKUP_FILEthe key for storing the current file the backup.static StringBACKUP_POSITIONthe key for storing the current position the backup.static StringBACKUP_STREAMthe key for storing the current stream the backup.protected longm_ActualEndthe actual last position.protected Filem_CurrentFilethe current file to read from.protected gnu.trove.list.array.TByteArrayListm_Datathe collected data.protected longm_Endthe end position.protected booleanm_OutputArraywhether to output an array instead of single items.protected longm_Positionthe current position.protected longm_Startthe start position.protected FileInputStreamm_Streamthe 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 voidcloseStream()Closes the stream if possible.voiddefineOptions()Adds options to the internal list of options.protected StringdoExecute()Executes the flow item.StringendTipText()Returns the tip text for this property.Class[]generates()Returns the class of objects that it generates.longgetEnd()Returns the last position (incl.).booleangetOutputArray()Returns whether to output the file as byte array or byte by byte.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.longgetStart()Returns the starting position.StringglobalInfo()Returns a string describing the object.booleanhasPendingOutput()Checks whether there is pending output to be collected after executing the flow item.protected voidinitialize()Initializes the members.Tokenoutput()Returns the generated token.StringoutputArrayTipText()Returns the tip text for this property.protected voidpruneBackup()Removes entries from the backup.protected voidreset()Resets the actor.protected voidrestoreState(Hashtable<String,Object> state)Restores the state of the actor before the variables got updated.voidsetEnd(long value)Sets the last position (incl).voidsetOutputArray(boolean value)Sets whether to output the file as byte array or byte by byte.voidsetStart(long value)Sets the starting position.StringstartTipText()Returns the tip text for this property.voidwrapUp()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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractActor
-
reset
protected void reset()
Resets the actor. Clears the output queue.- Overrides:
resetin classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin classAbstractActor- Returns:
- null if no info available, otherwise short string
-
pruneBackup
protected void pruneBackup()
Removes entries from the backup.- Overrides:
pruneBackupin classAbstractActor- See Also:
AbstractActor.reset()
-
backupState
protected Hashtable<String,Object> backupState()
Backs up the current state of the actor before update the variables.- Overrides:
backupStatein 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:
restoreStatein 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:
setOutputArrayin interfaceArrayProvider- Specified by:
setOutputArrayin 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:
getOutputArrayin interfaceArrayProvider- Specified by:
getOutputArrayin interfaceArrayProvider- Returns:
- true if output is an array
-
outputArrayTipText
public String outputArrayTipText()
Returns the tip text for this property.- Specified by:
outputArrayTipTextin interfaceArrayProvider- Specified by:
outputArrayTipTextin 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:
acceptsin interfaceInputConsumer- Returns:
- java.lang.String.class, java.io.File.class
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Specified by:
generatesin interfaceOutputProducer- Returns:
- java.lang.Byte.class
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecutein 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:
hasPendingOutputin interfaceOutputProducer- Overrides:
hasPendingOutputin classAbstractTransformer- Returns:
- true if there is pending output
-
output
public Token output()
Returns the generated token.- Specified by:
outputin interfaceOutputProducer- Overrides:
outputin classAbstractTransformer- Returns:
- the generated token
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished.- Specified by:
wrapUpin interfaceActor- Overrides:
wrapUpin classAbstractTransformer
-
-