Package io.jawk.jrt

Class StreamInputSource

java.lang.Object
io.jawk.jrt.StreamInputSource
All Implemented Interfaces:
InputSource, Closeable, AutoCloseable

public class StreamInputSource extends Object implements InputSource, Closeable
An 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 Details

    • StreamInputSource

      public StreamInputSource(InputStream defaultInput, VariableManager vm, JRT jrt)
      Creates a stream-backed input source.
      Parameters:
      defaultInput - the fallback input stream used when ARGV contains no filename arguments (typically System.in)
      vm - the variable manager providing access to ARGV and ARGC
      jrt - the JRT instance used for string conversion and special variable updates
  • Method Details

    • nextRecord

      public boolean nextRecord() throws IOException
      Advances to the next input record.

      Implementations should keep the current record accessible through InputSource.getRecordText() and InputSource.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:
      nextRecord in interface InputSource
      Returns:
      true when a record is available, false when input is exhausted
      Throws:
      IOException - if an I/O error occurs
    • getRecordText

      public String getRecordText()
      Returns the current record text ($0), or null when the source only exposes pre-split fields for the current record.

      When both InputSource.getRecordText() and InputSource.getFields() return non-null values, the field list is authoritative for field/NF access while the record text is authoritative for the initial $0 value.

      Specified by:
      getRecordText in interface InputSource
      Returns:
      current record text, or null when unavailable
    • getFields

      public List<String> getFields()
      Always returns null so that the runtime splits $0 using the current field separator (FS).
      Specified by:
      getFields in interface InputSource
      Returns:
      null
    • isFromFilenameList

      public boolean isFromFilenameList()
      Indicates whether the current record originates from a named file in the argument list.
      Specified by:
      isFromFilenameList in interface InputSource
      Returns:
      true when sourced from a filename argument
    • setRecordSeparator

      public void setRecordSeparator(String rs)
      Propagates a record-separator change to the active PartitioningReader.
      Parameters:
      rs - the new record separator value
    • close

      public void close() throws IOException
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - never thrown; signature required by Closeable