mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-06 13:44:29 +02:00
Fix: workaround io error 'stream closed' caused by bugs in URLClassloader (#412)
This commit is contained in:
parent
027c0c2703
commit
d72a2bc805
@ -25,7 +25,9 @@
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
@ -235,7 +237,7 @@ public class SnappyLoader
|
||||
InputStream reader = null;
|
||||
FileOutputStream writer = null;
|
||||
try {
|
||||
reader = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
||||
reader = getResourceAsInputStream(nativeLibraryFilePath);
|
||||
try {
|
||||
writer = new FileOutputStream(extractedLibFile);
|
||||
|
||||
@ -273,7 +275,7 @@ public class SnappyLoader
|
||||
InputStream nativeIn = null;
|
||||
InputStream extractedLibIn = null;
|
||||
try {
|
||||
nativeIn = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
||||
nativeIn = getResourceAsInputStream(nativeLibraryFilePath);
|
||||
extractedLibIn = new FileInputStream(extractedLibFile);
|
||||
|
||||
if (!contentsEquals(nativeIn, extractedLibIn)) {
|
||||
@ -394,4 +396,16 @@ public class SnappyLoader
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private static InputStream getResourceAsInputStream(String resourcePath) throws IOException {
|
||||
URL url = SnappyLoader.class.getResource(resourcePath);
|
||||
URLConnection connection = url.openConnection();
|
||||
if (connection instanceof JarURLConnection) {
|
||||
JarURLConnection jarConnection = (JarURLConnection) connection;
|
||||
jarConnection.setUseCaches(false); // workaround for https://bugs.openjdk.org/browse/JDK-8205976
|
||||
return jarConnection.getInputStream();
|
||||
} else {
|
||||
return connection.getInputStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user