Java中缓冲inputStream时出现奇怪的IOException

发布于 2024-10-19 10:43:48 字数 623 浏览 4 评论 0原文

我有一个关于缓冲 pdf 和 odt 文件的 inputStream 的奇怪问题。它们不是那么大,只有 5 - 15 页,但它总是这样结束

java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at java.io.FilterInputStream.read(FilterInputStream.java:90)

你可以看到

编辑:抱歉大家提出了这样一个愚蠢的问题,当时是凌晨 4 点:-) 问题是 5 个测试中有 4 个失败了,所以我预计类加载器会找到这些资源,但它没有。有一个拼写错误“文件/文件”......仍然不明白为什么其中一个通过了

I have a weird issue regarding buffering inputStream of pdf and odt files. They are not so big, just 5 - 15 pages, but it always ends up like this

java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at java.io.FilterInputStream.read(FilterInputStream.java:90)

You can see the source code here. I'm asking here, because it doesn't seem to be Apache Tika issue, but rather JVM issue.

EDITED: Sorry guys for such a stupid question, it was 4am :-) The problem was that 4 from 5 tests failed so I anticipated that classloader found those resources, but it didn't. There was a typo "file / files" ... Stil don't understand why one of them passed

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

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

发布评论

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

评论(2

黯然#的苍凉 2024-10-26 10:43:48

很抱歉问一个明显的问题,但是您尝试加载的资源文件可以在测试的类路径中访问吗?

String resourceLocation = "file/Designandrealizationofanintranetportal.pdf";

Sorry to ask an obvious question, but are the resource files that you're trying to load accessible in the test's classpath?

String resourceLocation = "file/Designandrealizationofanintranetportal.pdf";
叫思念不要吵 2024-10-26 10:43:48

这不太可能是 JVM/Java 类库问题。要么是你的测试用例有问题,要么是 Tika 出了问题。

当尝试从已关闭的 Stream 中读取数据时,会发生异常。标准流类不会自发关闭。


如果我想找出真正的问题是什么,我会使用调试器运行其中一个测试用例,在 BufferedInputStream.close() 方法上设置断点,并尝试找出问题所在,以及为什么它被称为。

It is highly unlikely to be a JVM / Java class library problem. It will either be your testcase or Tika that is at fault.

The exception occurs when something tries to read from a Stream that has already been closed. And the standard stream classes don't close themselves spontaneously.


If I was going to figure out what the real problem was, I'd run one of the testcases using a debugger, set a breakpoint on the BufferedInputStream.close() method, and try to figure out where, and why it was being called.

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