Package io.jawk.ext
Class StdinExtension
java.lang.Object
io.jawk.ext.AbstractExtension
io.jawk.ext.StdinExtension
- All Implemented Interfaces:
JawkExtension
Enable stdin processing in Jawk, to be used in conjunction with the -ni parameter.
Since normal input processing is turned off via -ni, this is provided to enable a way
to read input from stdin.
To use:
StdinGetline() == 1 { print "--> " $0 }
The extension functions are as follows:
-
StdinHasInput -
Returns 1 when StdinGetline() does not block (i.e., when input is available or upon an EOF), 0 otherwise.
Parameters:- none
- 1 when StdinGetline() does not block, 0 otherwise.
-
StdinGetline -
Retrieve a line of input from stdin. The operation will block until input is available, EOF, or an IO error.
Parameters:- none
- 1 upon successful read of a line of input from stdin, 0 upon an EOF, and -1 when an IO error occurs.
-
StdinBlock -
Block until a call to StdinGetline() would not block.
Parameters:- chained block function - optional
- "Stdin" if this block object is triggered
- Author:
- Danny Daglas
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StdinExtensionSingleton extension instance backed bySystem.in. -
Constructor Summary
ConstructorsConstructorDescriptionCreates aStdinExtensionthat reads fromSystem.in.StdinExtension(InputStream inputStream) Creates aStdinExtensionthat reads from the specified input stream. -
Method Summary
Modifier and TypeMethodDescriptiongetExtensionName.voidinit(VariableManager vm, JRT jrt, AwkSettings settings) Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.stdinBlockFunction(Object... args) Returns a block object that waits for stdin readiness and optionally chains to another block.Reads the next line from stdin, or the AWK empty string at EOF.intReports whether stdin data is available without blocking.Methods inherited from class io.jawk.ext.AbstractExtension
getExtensionFunctionsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jawk.ext.JawkExtension
getExtensionFunctions
-
Field Details
-
INSTANCE
Singleton extension instance backed bySystem.in.
-
-
Constructor Details
-
StdinExtension
public StdinExtension()Creates aStdinExtensionthat reads fromSystem.in. -
StdinExtension
Creates aStdinExtensionthat reads from the specified input stream.- Parameters:
inputStream- the stream to read stdin data from
-
-
Method Details
-
init
Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.It is guaranteed init() is called before invoke() is called.
- Specified by:
initin interfaceJawkExtension- Overrides:
initin classAbstractExtension- Parameters:
vm- Reference to the Variable Managerjrt- Reference to the Runtimesettings- Reference to the settings
-
getExtensionName
Description copied from class:AbstractExtensiongetExtensionName.
- Specified by:
getExtensionNamein interfaceJawkExtension- Overrides:
getExtensionNamein classAbstractExtension- Returns:
- name of the extension package.
-
stdinHasInputFunction
public int stdinHasInputFunction()Reports whether stdin data is available without blocking.- Returns:
1when a read can proceed or EOF was reached, otherwise0
-
stdinGetlineFunction
Reads the next line from stdin, or the AWK empty string at EOF.- Returns:
- Next line of input or an EOF marker compatible with the extension's contract
-
stdinBlockFunction
Returns a block object that waits for stdin readiness and optionally chains to another block.- Parameters:
args- Optional chaining block object- Returns:
- Block object suitable for Jawk's block manager
-