Class StreamInputSource
- All Implemented Interfaces:
InputSource,Closeable,AutoCloseable
InputSource that reads records from an InputStream,
traversing the ARGV array to open filenames and apply
name=value variable assignments exactly like the classic AWK
command-line flow.
When no filename arguments are present in ARGV, records are read
from the supplied default InputStream (usually System.in).
This class is the default InputSource used internally by the
runtime when no custom source has been configured via
AwkSettings#setInputSource(...).
API note: this type is public to allow runtime wiring between packages, but
it is considered an internal implementation detail. Embedding applications
should implement InputSource directly rather than depend on this
class, whose behavior may change in future releases.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStreamInputSource(InputStream defaultInput, VariableManager vm, JRT jrt) Creates a stream-backed input source. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases any open file-backed reader held by this source.Always returnsnullso that the runtime splits$0using the current field separator (FS).Returns the current record text ($0), ornullwhen the source only exposes pre-split fields for the current record.booleanIndicates whether the current record originates from a named file in the argument list.booleanAdvances to the next input record.voidPropagates a record-separator change to the activePartitioningReader.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jawk.jrt.InputSource
getRecord
-
Constructor Details
-
StreamInputSource
Creates a stream-backed input source.- Parameters:
defaultInput- the fallback input stream used whenARGVcontains no filename arguments (typicallySystem.in)vm- the variable manager providing access toARGVandARGCjrt- the JRT instance used for string conversion and special variable updates
-
-
Method Details
-
nextRecord
Advances to the next input record.Implementations should keep the current record accessible through
InputSource.getRecordText()andInputSource.getFields()until a subsequent call successfully advances to a new record. This allows END blocks to continue observing the last consumed record after the final EOF probe.- Specified by:
nextRecordin interfaceInputSource- Returns:
truewhen a record is available,falsewhen input is exhausted- Throws:
IOException- if an I/O error occurs
-
getRecordText
Returns the current record text ($0), ornullwhen the source only exposes pre-split fields for the current record.When both
InputSource.getRecordText()andInputSource.getFields()return non-null values, the field list is authoritative for field/NF access while the record text is authoritative for the initial$0value.- Specified by:
getRecordTextin interfaceInputSource- Returns:
- current record text, or
nullwhen unavailable
-
getFields
Always returnsnullso that the runtime splits$0using the current field separator (FS).- Specified by:
getFieldsin interfaceInputSource- Returns:
null
-
isFromFilenameList
public boolean isFromFilenameList()Indicates whether the current record originates from a named file in the argument list.- Specified by:
isFromFilenameListin interfaceInputSource- Returns:
truewhen sourced from a filename argument
-
setRecordSeparator
Propagates a record-separator change to the activePartitioningReader.- Parameters:
rs- the new record separator value
-
close
Releases any open file-backed reader held by this source.This method is idempotent and safe to call multiple times. It does not close the default input stream (
System.in).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- never thrown; signature required byCloseable
-