Methods Summary |
---|
public java.io.Reader | chain(java.io.Reader rdr)Creates a new PrefixLines filter using the passed in
Reader for instantiation.
PrefixLines newFilter = new PrefixLines(rdr);
newFilter.setPrefix(getPrefix());
newFilter.setInitialized(true);
return newFilter;
|
private java.lang.String | getPrefix()Returns the prefix which will be added at the start of each input line.
return prefix;
|
private void | initialize()Initializes the prefix if it is available from the parameters.
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (PREFIX_KEY.equals(params[i].getName())) {
prefix = params[i].getValue();
break;
}
}
}
|
public int | read()Returns the next character in the filtered stream. One line is read
from the original input, and the prefix added. The resulting
line is then used until it ends, at which point the next original line
is read, etc.
if (!getInitialized()) {
initialize();
setInitialized(true);
}
int ch = -1;
if (queuedData != null && queuedData.length() == 0) {
queuedData = null;
}
if (queuedData != null) {
ch = queuedData.charAt(0);
queuedData = queuedData.substring(1);
if (queuedData.length() == 0) {
queuedData = null;
}
} else {
queuedData = readLine();
if (queuedData == null) {
ch = -1;
} else {
if (prefix != null) {
queuedData = prefix + queuedData;
}
return read();
}
}
return ch;
|
public void | setPrefix(java.lang.String prefix)Sets the prefix to add at the start of each input line.
this.prefix = prefix;
|