Skip to content
Snippets Groups Projects
Commit 1884f515 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Don't close input stream in readCacheFileImpl.

readCacheFileImpl would close the input stream, which caused the next read from that same stream to fail.

Generally we shouldn't close stream which we didn't create.
parent d2667c64
No related branches found
No related tags found
No related merge requests found
...@@ -349,17 +349,32 @@ public class QuantizationCacheManager { ...@@ -349,17 +349,32 @@ public class QuantizationCacheManager {
* @return Cache file or null, if exception occurs. * @return Cache file or null, if exception occurs.
*/ */
private static ICacheFile readCacheFileImpl(final InputStream inputStream) { private static ICacheFile readCacheFileImpl(final InputStream inputStream) {
try (final DataInputStream dis = new DataInputStream(inputStream)) { final DataInputStream dis;
final CacheFileHeader header = new CacheFileHeader(); if (inputStream instanceof DataInputStream) {
dis = (DataInputStream) inputStream;
} else {
dis = new DataInputStream(inputStream);
}
final CacheFileHeader header = new CacheFileHeader();
try {
header.readFromStream(dis); header.readFromStream(dis);
} catch (final IOException e) {
System.err.println("Failed to read CacheFileHeader from input stream");
e.printStackTrace();
return null;
}
final ICacheFile cacheFile = getCacheFile(header.getQuantizationType()); final ICacheFile cacheFile = getCacheFile(header.getQuantizationType());
assert (cacheFile != null); assert (cacheFile != null);
try {
cacheFile.readFromStream(dis, header); cacheFile.readFromStream(dis, header);
return cacheFile;
} catch (final IOException e) { } catch (final IOException e) {
System.err.println("Failed to read cache file from input stream.");
e.printStackTrace();
return null; return null;
} }
return cacheFile;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment