java.lang.NullPointerException:Inflater 已在 InputStreamReader 上关闭

发布于 2024-10-12 09:48:20 字数 1384 浏览 4 评论 0原文

我遇到以下问题:

当我从项目加载资源时一切正常,但是当我将其放在 .jar 上并尝试加载时出现异常。

代码是:

InputStreamReader reader =
    new InputStreamReader(
        this.getClass().getResource(fileName).openStream())  
CsvReader stream = new CsvReader(reader);  
try {  
    while (stream.readRecord()) {  
        line = stream.getRawRecord();  
        //DO SOMETHING...  
    }  
}catch (Exception e) {  
    System.err.println(e.getMessage());  
    e.printStackTrace();  
} finally {  
    stream.close();  
}

stackTrace 是:

    Inflater has been closed java.lang.NullPointerException: Inflater has been closed
 at java.util.zip.Inflater.ensureOpen(Inflater.java:364)
 at java.util.zip.Inflater.inflate(Inflater.java:237)
 at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:135)
 at java.io.FilterInputStream.read(FilterInputStream.java:116)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
 at java.io.InputStreamReader.read(InputStreamReader.java:167)
 at utils.csvreader.CsvReader.checkDataLength(CsvReader.java:1198)
 at utils.csvreader.CsvReader.readRecord(CsvReader.java:604)

问题发生在 stream.getRawRecord() 上。我还尝试使用 BufferedReader 在 readLine(); 上得到相同的结果

有什么想法吗?

I have the following problem:

When I load the resource from the project all works fine, but when I put it on a .jar and try to load I get an exception.

The code is:

InputStreamReader reader =
    new InputStreamReader(
        this.getClass().getResource(fileName).openStream())  
CsvReader stream = new CsvReader(reader);  
try {  
    while (stream.readRecord()) {  
        line = stream.getRawRecord();  
        //DO SOMETHING...  
    }  
}catch (Exception e) {  
    System.err.println(e.getMessage());  
    e.printStackTrace();  
} finally {  
    stream.close();  
}

And the stackTrace is:

    Inflater has been closed java.lang.NullPointerException: Inflater has been closed
 at java.util.zip.Inflater.ensureOpen(Inflater.java:364)
 at java.util.zip.Inflater.inflate(Inflater.java:237)
 at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:135)
 at java.io.FilterInputStream.read(FilterInputStream.java:116)
 at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
 at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
 at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
 at java.io.InputStreamReader.read(InputStreamReader.java:167)
 at utils.csvreader.CsvReader.checkDataLength(CsvReader.java:1198)
 at utils.csvreader.CsvReader.readRecord(CsvReader.java:604)

The problem happens on stream.getRawRecord(). I also tried with BufferedReader with same result on readLine();

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香草可樂 2024-10-19 09:48:20

这可能是 Java 中的错误。我遇到了类似的问题,如下所述: https://issues.apache.org/jira/ browser/FELIX-1032

您的应用程序是否使用某些特殊的类加载器设置运行?

This can be bug in the Java. I had a similar problem, described here: https://issues.apache.org/jira/browse/FELIX-1032

Is your application running with some special class loader settings?

一个人练习一个人 2024-10-19 09:48:20

从项目加载资源意味着您不处理zip(jar是zip),因此InputStreamReader解析为您想要读取的文件。

我的猜测是,InputStreamReader 在处理 jar 时解析为 null 或错误的文件。记录变量以确保

loading resource from project means that you do not deal with zip (jar is zip), so InputStreamReader resolves to file you want to read.

My guess is that InputStreamReader resolves to null or wrong file when dealing with jar. Log vars to be asure

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文