问题
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
回答1:
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";
回答2:
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.
来源:https://stackoverflow.com/questions/5124544/strange-ioexception-when-buffering-inputstream-in-java