Package org.harctoolbox.harchardware
Class BufferedExecutor
java.lang.Object
org.harctoolbox.harchardware.BufferedExecutor
- All Implemented Interfaces:
Closeable,AutoCloseable,ICommandLineDevice,IHarcHardware
This class wraps an ICommandExecutor into a ICommandLineDevice.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidReturns the hardware version (not the version of the driver software).booleanisValid()Checks validity of an instance.voidopen()Opens the device with previously set parameters.Reads a line of text.readString(boolean wait) Reads a line of text.booleanready()Tells whether this stream is ready to be read.voidsendString(String cmd) Sends a command (a String) to the instance.voidsetDebug(int debug) Sets a debug parameter.voidsetTimeout(int timeout) Set timeout in milliseconds.voidsetVerbose(boolean verbose) Sets a verbosity flag, causing commands to be executed verbosely.
-
Constructor Details
-
BufferedExecutor
-
-
Method Details
-
sendString
Description copied from interface:ICommandLineDeviceSends a command (a String) to the instance.- Specified by:
sendStringin interfaceICommandLineDevice- Parameters:
cmd- Command string to be sent.- Throws:
IOExceptionHarcHardwareException
-
readString
Description copied from interface:ICommandLineDeviceReads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.- Specified by:
readStringin interfaceICommandLineDevice- Returns:
- A String containing the contents of the line, not including any line-termination characters, or null if no input available.
- Throws:
IOException
-
readString
Description copied from interface:ICommandLineDeviceReads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.- Specified by:
readStringin interfaceICommandLineDevice- Parameters:
wait- if true, wait until something arrives, otherwise return null if nothing there.- Returns:
- A String containing the contents of the line, not including any line-termination characters, or null if no input available.
- Throws:
IOException
-
ready
Description copied from interface:ICommandLineDeviceTells whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready.- Specified by:
readyin interfaceICommandLineDevice- Returns:
- True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
- Throws:
IOException- If an I/O error occurs
-
flushInput
- Specified by:
flushInputin interfaceICommandLineDevice- Throws:
IOException
-
getVersion
Description copied from interface:IHarcHardwareReturns the hardware version (not the version of the driver software). May be null if no relevant information available.- Specified by:
getVersionin interfaceIHarcHardware- Returns:
- Version string. Semantics can vary.
- Throws:
IOException
-
setVerbose
public void setVerbose(boolean verbose) Description copied from interface:IHarcHardwareSets a verbosity flag, causing commands to be executed verbosely. Exact semantic depends on the implementation. Typically, all communication with the device is echoed to stderr.- Specified by:
setVerbosein interfaceIHarcHardware- Parameters:
verbose- on or off
-
setDebug
public void setDebug(int debug) Description copied from interface:IHarcHardwareSets a debug parameter. Exact semantic depends on the implementation.- Specified by:
setDebugin interfaceIHarcHardware
-
setTimeout
Description copied from interface:IHarcHardwareSet timeout in milliseconds. Exact semantics may be dependent on the hardware.- Specified by:
setTimeoutin interfaceIHarcHardware- Parameters:
timeout- Timeout in milliseconds.- Throws:
IOExceptionHarcHardwareException
-
isValid
public boolean isValid()Description copied from interface:IHarcHardwareChecks validity of an instance. Exact meaning can vary.- Specified by:
isValidin interfaceIHarcHardware- Returns:
- validity of the instance.
-
open
Description copied from interface:IHarcHardwareOpens the device with previously set parameters.- Specified by:
openin interfaceIHarcHardware- Throws:
HarcHardwareExceptionIOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-