StaticWriter和Writer类之间的冲突

时间:2013-11-14 17:01:24

标签: java writer stringwriter

自从我们最近从WSED 5.2迁移到RAD 7.5以来,我们的代码中出现了一个应用程序破坏错误。

RAD 7.5标志着它,所有在类头的声明(公共类FoStringWriter扩展StringWriter实现FoWriter {)

- Exception IOException in throws clause of Writer.append(CharSequence, int, int) is not compatable with StringWriter.append(CharSequence, int, int)
- Exception IOException in throws clause of Writer.append(char) is not compatable with StringWriter.append(char)
- Exception IOException in throws clause of Writer.append(CharSequence) is not compatable with StringWriter.append(CharSequence)

我在网上找到的每一篇文献都指出这是Eclipse中的一个“错误”,但我的开发人员应该已经拥有最新版本的Eclipse软件。所以我不知道该怎么做这个错误。是否有IBM的修复,我还没有更新到?或者是否有可以纠正此错误的代码修复?

public class FoStringWriter extends StringWriter implements FoWriter {

public void filteredWrite(String str) throws IOException {
FoStringWriter.filteredWrite(str,this);
}

public static void filteredWrite(String str, StringWriter writer) throws IOException {
    if (str == null) str = "";
    TagUtils tagUtils = TagUtils.getInstance();
    str = tagUtils.filter(str);
    HashMap dictionary = new HashMap();
    dictionary.put("&#","&#");
    str = GeneralUtils.translate(str,dictionary);
    writer.write(str);      
}

}

编辑说明:

此过程运行会为我们的应用创建PDF文档。在WSED 5.5中,它有效,但有一些错误但没有阻止PDF被写入。

1 个答案:

答案 0 :(得分:1)

在前额拍打我,因为这是一个看似完全明显的答案解决的另一个“错误”。

只需添加列出的“错误”的方法,我就可以在调用此类时消除错误抛出。

直接从StringWriter复制它们实际上是有效的,无需以任何方式编辑它们。

public StringWriter append(char c) {
    write(c);
    return this;
}

public StringWriter append(CharSequence csq) {
    if (csq == null)
        write("null");
    else
        write(csq.toString());
        return this;
}

public StringWriter append(CharSequence csq, int start, int end) {
    CharSequence cs = (csq == null ? "null" : csq);
    write(cs.subSequence(start, end).toString());
        return this;
}

我很高兴这种方法有效,同时也感到沮丧的是,这是一个非常简单的解决方案,需要花费将近一整周的时间来解决问题。

我认为这个错误背后的原因可能是实施中的冲突。 FoStringWriter扩展了StringWriter,但它本身扩展了Writer,并且这两个类都有自己的“追加”方法,这些方法相互覆盖。通过显式创建它们,可以解决此错误。