我想实现支持FilterInputStream
界面的BufferedInputStream
,特别是readLine()
方法。
当前代码如下所示(标准antlr):
theInput = new BufferedInputStream( Files.newInputStream(inputPath) );
theOutput = new PrintStream(Files.newOutputStream(outputPath));
grammar.execute(theInput, theOutput);
建议的代码看起来像这样:
theInput = new RemoveCommentsInputStream( Files.newInputStream(inputPath) );
theOutput = new PrintStream(Files.newOutputStream(outputPath));
grammar.execute(theInput, theOutput);
RemoveCommentsInputStream
的作用类似于java.io.FilterInputStream
。
问题在于FilterInputStream
延伸InputStream
,但execute()
需要BufferedInputStream
。
这个用例是我想编写一个过滤器,在我将代码传递给antlr之前删除代码的注释和其他内容。实现规则来处理antlr中的cruft很困难,因为规则基于输入中某些字符的列位置。但是在普通的旧java中很容易摆脱它。
有什么建议吗?