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 TypeMethodDescriptionbooleanAdvance to the next input file for the per-file main input loop used when BEGINFILE/ENDFILE rules ornextfileare present.voidclose()Releases any open file-backed reader held by this source.Returns the error description recorded when the current input file could not be opened byadvanceToNextFile(), ornullwhen the current input is readable.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.booleanReads the next record of the current input file only, never advancing to the next input file.voidPropagates a record-separator change to the activePartitioningReader.Methods inherited from class java.lang.Object
clone, equals, finalize, 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.For custom implementations, this flag also controls whether consuming a record advances the per-file record counter
FNR. Records read by the built-in stream input always advanceFNR— including standard input — per POSIX.- 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
-
advanceToNextFile
Advance to the next input file for the per-file main input loop used when BEGINFILE/ENDFILE rules ornextfileare present. Variable assignment arguments are applied along the way, exactly likenextRecord()does when it crosses a file boundary.On success, FILENAME, FNR, ARGIND, and ERRNO are updated and
$0is cleared, so the BEGINFILE rules observe the new file before any record is read. A file that cannot be opened is still reported as available: ERRNO carries the error description andgetCurrentFileOpenError()returns it until the next advance, enabling gawk's non-fatal BEGINFILE error handling.- Returns:
truewhen a new input file (or the initial stdin stream) is current;falsewhen input is exhausted- Throws:
IOException- if an I/O error occurs while traversing ARGV
-
nextRecordInCurrentFile
Reads the next record of the current input file only, never advancing to the next input file. Used by the per-file main input loop so that ENDFILE rules can run at each file boundary.- Returns:
truewhen a record is available;falseat the end of the current input file- Throws:
IOException- if an I/O error occurs
-
getCurrentFileOpenError
Returns the error description recorded when the current input file could not be opened byadvanceToNextFile(), ornullwhen the current input is readable.- Returns:
- the pending open error, or
null
-
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
-