1

我似乎没有重复发帖,所以这里是详细信息...

当我使用来自 XOM(XML 对象模型,Java 库)的非静态方法 Builder.build() 解析文档时,在 Eclipse 控制台中我得到:

[Fatal Error] :1:1: Premature end of file.

这是一个严重的问题,会强制停止程序的运行。

我正在使用的方法的内容如下...

public boolean buildDocument() {

    boolean out = true;
    Builder b = null;
    b = new Builder();

    String xml = "";
    String newXml = "";
    StringBuilder xmlSb = new StringBuilder();
    URL xmlUrl = null;
    try {
        xmlUrl = new URL(this.packAddr);
    } catch (MalformedURLException e1) {
        Pcdl.log.severe(e1.getMessage());
        out = false;
    }

    InputStream is;
    try {

        is = xmlUrl.openStream();
        while (is.available() > 0) {
            xmlSb.append(is.read());
        }

    } catch (IOException e1) {
        e1.printStackTrace();
        Pcdl.log.severe(e1.getMessage());
        out = false;
    }

    xml = xmlSb.toString();

    // Add more lines if needed.  I hope that nobody actually had to use any XML entities.
    newXml = Util.removeUTF8BOM(xml)
            .replace("&", "&")
            ;

    Pcdl.log.info("XML Data Size: " + newXml.length() + " B.");
    System.out.println(newXml);

    // Actually build it.
    try {
        this.doc = b.build(new ByteArrayInputStream(newXml.getBytes("UTF-8")));
    } catch (ParsingException | IOException e) {
        Pcdl.log.severe("Document build error: " + e.getMessage());
        System.out.println(e.getMessage());
        out = false;
    }

    System.out.println(this.doc);
    return out;

}

我在 GitHub 存储库中有整个程序:“ http://github.com/Treyzania/PraseocraftDL/ ”。如果你想以任何方式为这个项目做出贡献,请做!做个叉子,我看看里面有什么。

此方法来自“com.treyzania.praseocraft.ftb.downloader.PackFile”。我知道我的包名很长,但现在更改它们为时已晚。我正在进行的项目是一个获取 XML 文档的程序(示例:http : //pastebin.com/raw.php?i=B42in4c5),并将其编译成 %appdata%/.mc-pcdl 中的 Minecraft modpack /packs/(或类似文件),并编辑一些其他文件以将数据正确注册到 Minecraft Launcher。我试图让这个项目尽可能抽象,所以看起来有比必要的更多的类。我也在尝试尽可能多的事情来自己解决这个问题。没有人在工作。

4

1 回答 1

0

Treyzania solved his problem:

I had to cast

xmlSb.append(is.read());

as

xmlSb.append((char) is.read());

to fix the problem. However, I am using a different method to download the files now, there is no longer any problem in this section of my project.

于 2013-12-20T21:52:44.980 回答