mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-07 06:04:28 +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;
|
package org.xerial.snappy;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.JarURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -235,7 +237,7 @@ public class SnappyLoader
|
|||||||
InputStream reader = null;
|
InputStream reader = null;
|
||||||
FileOutputStream writer = null;
|
FileOutputStream writer = null;
|
||||||
try {
|
try {
|
||||||
reader = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
reader = getResourceAsInputStream(nativeLibraryFilePath);
|
||||||
try {
|
try {
|
||||||
writer = new FileOutputStream(extractedLibFile);
|
writer = new FileOutputStream(extractedLibFile);
|
||||||
|
|
||||||
@ -273,7 +275,7 @@ public class SnappyLoader
|
|||||||
InputStream nativeIn = null;
|
InputStream nativeIn = null;
|
||||||
InputStream extractedLibIn = null;
|
InputStream extractedLibIn = null;
|
||||||
try {
|
try {
|
||||||
nativeIn = SnappyLoader.class.getResourceAsStream(nativeLibraryFilePath);
|
nativeIn = getResourceAsInputStream(nativeLibraryFilePath);
|
||||||
extractedLibIn = new FileInputStream(extractedLibFile);
|
extractedLibIn = new FileInputStream(extractedLibFile);
|
||||||
|
|
||||||
if (!contentsEquals(nativeIn, extractedLibIn)) {
|
if (!contentsEquals(nativeIn, extractedLibIn)) {
|
||||||
@ -394,4 +396,16 @@ public class SnappyLoader
|
|||||||
}
|
}
|
||||||
return version;
|
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