Class PartitioningReader

java.lang.Object
java.io.Reader
java.io.FilterReader
org.sentrysoftware.jawk.jrt.PartitioningReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class PartitioningReader extends FilterReader
A reader which consumes one record at a time from an underlying input reader.

Greedy Regex Matching

The current implementation matches setRecordSeparator against contents of an input buffer (the underlying input stream filling the input buffer). Records are split against the matched regular expression input, treating the regular expression as a record separator.

By default, greedy regular expression matching for setRecordSeparator is turned off. It is assumed the user will employ a non-ambiguous regex for setRecordSeparator. For example, ab*c is a non-ambiguous regex, but ab?c?b is an ambiguous regex because it can match ab or abc, and the reader may accept either one, depending on input buffer boundaries. The implemented way to employ greedy regex matching is to consume subsequent input until the match does not occur at the end of the input buffer, or no input is available. However, this behavior is not desirable in all cases (i.e., interactive input against some sort of ambiguous newline regex). To enable greedy setRecordSeparator regex consumption, use -Djawk.forceGreedyRS=true.

Author:
Danny Daglas
  • Constructor Details

    • PartitioningReader

      public PartitioningReader(Reader reader, String recordSeparator)
      Construct the partitioning reader.
      Parameters:
      reader - The reader containing the input data stream.
      recordSeparator - The record separator, as a regular expression.
    • PartitioningReader

      public PartitioningReader(Reader r, String recordSeparator, boolean fromFileNameList)
      Construct the partitioning reader.
      Parameters:
      r - The reader containing the input data stream.
      recordSeparator - The record separator, as a regular expression.
      fromFileNameList - Whether the underlying input reader is a file from the filename list (the parameters passed into AWK after the script argument).
  • Method Details

    • setRecordSeparator

      public final void setRecordSeparator(String recordSeparator)
      Assign a new record separator for this partitioning reader.
      Parameters:
      recordSeparator - The new record separator, as a regular expression.
    • fromFilenameList

      public boolean fromFilenameList()

      fromFilenameList.

      Returns:
      true whether the underlying input reader is from a filename list argument; false otherwise
    • read

      public int read(char[] b, int start, int len) throws IOException
      Overrides:
      read in class FilterReader
      Throws:
      IOException
    • readRecord

      public String readRecord() throws IOException
      Consume one record from the reader. It uses the record separator regular expression to mark start/end of records.
      Returns:
      the next record, null if no more records exist
      Throws:
      IOException - upon an IO error