|
|
|
Re: XPAND FILE directive - is it possible to write to an InputStream [message #527984 is a reply to message #527940] |
Sat, 17 April 2010 21:40  |
Eclipse User |
|
|
|
Turns out its a lot easier to just wrap a StringBuffer with a class that implements Output:
public class StringOutput implements Output {
private Outlet outlet;
private StringBuffer sb = new StringBuffer();
private Stack<SyntaxElement> stack = new Stack<SyntaxElement>();
@Override
public void addOutlet(Outlet outlet) {
this.outlet = outlet;
}
@Override
public void closeFile() {
}
@Override
public Outlet getOutlet(String name) {
return outlet;
}
@Override
public void openFile(String path, String outletName) {
}
@Override
public SyntaxElement popStatement() {
return stack.pop();
}
@Override
public void pushStatement(SyntaxElement stmt, XpandExecutionContext ctx) {
stack.push(stmt);
}
@Override
public void write(String bytes) {
sb.append(bytes);
}
public void clear() {
sb.delete(0, sb.length());
}
public String toString() {
return sb.toString();
}
}
Then to use it programatically:
output = new StringOutput();
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
|
|
|
Powered by
FUDForum. Page generated in 1.12915 seconds