Java中缓冲inputStream时出现奇怪的IOException
我有一个关于缓冲 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很抱歉问一个明显的问题,但是您尝试加载的资源文件可以在测试的类路径中访问吗?
Sorry to ask an obvious question, but are the resource files that you're trying to load accessible in the test's classpath?
这不太可能是 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.