Methods Summary |
---|
public java.io.Reader | chain(java.io.Reader rdr)Creates a new ConcatReader using the passed in
Reader for instantiation.
ConcatFilter newFilter = new ConcatFilter(rdr);
newFilter.setPrepend(getPrepend());
newFilter.setAppend(getAppend());
// Usually the initialized is set to true. But here it must not.
// Because the prepend and append readers have to be instantiated
// on runtime
//newFilter.setInitialized(true);
return newFilter;
|
public java.io.File | getAppend()Returns append attribute.
return append;
|
public java.io.File | getPrepend()Returns prepend attribute.
return prepend;
|
private void | initialize()Scans the parameters list for the "lines" parameter and uses
it to set the number of lines to be returned in the filtered stream.
also scan for skip parameter.
// get parameters
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if ("prepend".equals(params[i].getName())) {
setPrepend(new File(params[i].getValue()));
continue;
}
if ("append".equals(params[i].getName())) {
setAppend(new File(params[i].getValue()));
continue;
}
}
}
if (prepend != null) {
if (!prepend.isAbsolute()) {
prepend = new File(getProject().getBaseDir(), prepend.getPath());
}
prependReader = new BufferedReader(new FileReader(prepend));
}
if (append != null) {
if (!append.isAbsolute()) {
append = new File(getProject().getBaseDir(), append.getPath());
}
appendReader = new BufferedReader(new FileReader(append));
}
|
public int | read()Returns the next character in the filtered stream. If the desired
number of lines have already been read, the resulting stream is
effectively at an end. Otherwise, the next character from the
underlying stream is read and returned.
// do the "singleton" initialization
if (!getInitialized()) {
initialize();
setInitialized(true);
}
int ch = -1;
// The readers return -1 if they end. So simply read the "prepend"
// after that the "content" and at the end the "append" file.
if (prependReader != null) {
ch = prependReader.read();
if (ch == -1) {
// I am the only one so I have to close the reader
prependReader.close();
prependReader = null;
}
}
if (ch == -1) {
ch = super.read();
}
if (ch == -1) {
// don't call super.close() because that reader is used
// on other places ...
if (appendReader != null) {
ch = appendReader.read();
if (ch == -1) {
// I am the only one so I have to close the reader
appendReader.close();
appendReader = null;
}
}
}
return ch;
|
public void | setAppend(java.io.File append)Sets append attribute.
this.append = append;
|
public void | setPrepend(java.io.File prepend)Sets prepend attribute.
this.prepend = prepend;
|