org.jawk.jrt
Class PartitioningReader
java.lang.Object
java.io.Reader
java.io.FilterReader
org.jawk.jrt.PartitioningReader
- All Implemented Interfaces:
- java.io.Closeable, java.lang.Readable
public class PartitioningReader
- extends java.io.FilterReader
A reader which consumes one record at a time from
an underlying input reader.
Greedy Regex Matching
The current implementation matches RS 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 RS is turned off. It is assumed
the user will employ a non-ambiguous regex for RS.
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 desireable in all cases (i.e., interactive
input against some sort of ambiguous newline
regex). To enable greedy RS regex consumption,
use -Djawk.forceGreedyRS=true
.
Fields inherited from class java.io.FilterReader |
in |
Fields inherited from class java.io.Reader |
lock |
Constructor Summary |
PartitioningReader(java.io.Reader r,
java.lang.String rs_string)
Construct the partitioning reader. |
PartitioningReader(java.io.Reader r,
java.lang.String rs_string,
boolean from_filename_list)
Construct the partitioning reader. |
Method Summary |
boolean |
fromFilenameList()
|
int |
read(char[] b,
int start,
int len)
|
java.lang.String |
readRecord()
Consume one record from the reader. |
void |
RS(java.lang.String rs_string)
Assign a new record separator for this partitioning reader. |
boolean |
willBlock()
|
Methods inherited from class java.io.FilterReader |
close, mark, markSupported, read, ready, reset, skip |
Methods inherited from class java.io.Reader |
read, read |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PartitioningReader
public PartitioningReader(java.io.Reader r,
java.lang.String rs_string)
- Construct the partitioning reader.
- Parameters:
r
- The reader containing the input data stream.rs_string
- The record separator, as a regular expression.
PartitioningReader
public PartitioningReader(java.io.Reader r,
java.lang.String rs_string,
boolean from_filename_list)
- Construct the partitioning reader.
- Parameters:
r
- The reader containing the input data stream.rs_string
- The record separator, as a regular expression.from_filename_list
- Whether the underlying input reader
is a file from the filename list (the parameters passed
into AWK after the script argument).
RS
public void RS(java.lang.String rs_string)
- Assign a new record separator for this partitioning reader.
- Parameters:
rs_string
- The new record separator, as a regular expression.
fromFilenameList
public boolean 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 java.io.IOException
- Overrides:
read
in class java.io.FilterReader
- Throws:
java.io.IOException
willBlock
public boolean willBlock()
readRecord
public java.lang.String readRecord()
throws java.io.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:
java.io.IOException
- upon an IO error