Class PartitioningReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
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 Summary
ConstructorDescriptionPartitioningReader
(Reader reader, String recordSeparator) Construct the partitioning reader.PartitioningReader
(Reader r, String recordSeparator, boolean fromFileNameList) Construct the partitioning reader. -
Method Summary
Modifier and TypeMethodDescriptionboolean
fromFilenameList.int
read
(char[] b, int start, int len) Consume one record from the reader.final void
setRecordSeparator
(String recordSeparator) Assign a new record separator for this partitioning reader.Methods inherited from class java.io.FilterReader
close, mark, markSupported, read, ready, reset, skip
-
Constructor Details
-
PartitioningReader
Construct the partitioning reader.- Parameters:
reader
- The reader containing the input data stream.recordSeparator
- The record separator, as a regular expression.
-
PartitioningReader
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
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
- Overrides:
read
in classFilterReader
- Throws:
IOException
-
readRecord
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
-