mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-26 07:24:54 +02:00
Removed garbage code
This commit is contained in:
parent
dc0e8a3150
commit
4ee2936297
@ -31,6 +31,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.DigestInputStream;
|
import java.security.DigestInputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -57,8 +58,8 @@ import java.util.Properties;
|
|||||||
* <li>One of the libraries embedded in snappy-java-(version).jar extracted into
|
* <li>One of the libraries embedded in snappy-java-(version).jar extracted into
|
||||||
* (System property: <i>java.io.tempdir</i> or if
|
* (System property: <i>java.io.tempdir</i> or if
|
||||||
* <i>org.xerial.snappy.tempdir</i> is set, use this folder.)
|
* <i>org.xerial.snappy.tempdir</i> is set, use this folder.)
|
||||||
* <li>Folders in LD_PATH environment variable (This is the default path that
|
* <li>Folders specified by java.lib.path system property (This is the default
|
||||||
* JVM searches for native libraries)
|
* path that JVM searches for native libraries)
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
@ -109,7 +110,7 @@ public class SnappyLoader
|
|||||||
|
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
final String nativeLoaderClassName = "org.xerial.snappy.SnappyNativeLoader";
|
final String nativeLoaderClassName = "org.xerial.snappy.SnappyNativeLoader";
|
||||||
final String[] preloadClass = new String[] { "org.xerial.snappy.SnappyNative",
|
final String[] classesToPreload = new String[] { "org.xerial.snappy.SnappyNative",
|
||||||
"org.xerial.snappy.SnappyErrorCode" };
|
"org.xerial.snappy.SnappyErrorCode" };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -123,15 +124,15 @@ public class SnappyLoader
|
|||||||
// Load a byte code
|
// Load a byte code
|
||||||
byte[] byteCode = getByteCode("/org/xerial/snappy/SnappyNativeLoader.bytecode");
|
byte[] byteCode = getByteCode("/org/xerial/snappy/SnappyNativeLoader.bytecode");
|
||||||
// In addition, load the SnappyNative and SnappyException class in the system class loader
|
// In addition, load the SnappyNative and SnappyException class in the system class loader
|
||||||
List<byte[]> preloadClassByteCode = new ArrayList<byte[]>(preloadClass.length);
|
List<byte[]> preloadClassByteCode = new ArrayList<byte[]>(classesToPreload.length);
|
||||||
for (String each : preloadClass) {
|
for (String each : classesToPreload) {
|
||||||
preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/"))));
|
preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new class to the system class loader
|
// Create a new class to the system class loader
|
||||||
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
||||||
java.lang.reflect.Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] {
|
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
||||||
String.class, byte[].class, int.class, int.class, ProtectionDomain.class });
|
byte[].class, int.class, int.class, ProtectionDomain.class });
|
||||||
|
|
||||||
ClassLoader systemClassLoader = getSystemClassLoader();
|
ClassLoader systemClassLoader = getSystemClassLoader();
|
||||||
defineClass.setAccessible(true);
|
defineClass.setAccessible(true);
|
||||||
@ -140,9 +141,9 @@ public class SnappyLoader
|
|||||||
defineClass.invoke(systemClassLoader, nativeLoaderClassName, byteCode, 0, byteCode.length,
|
defineClass.invoke(systemClassLoader, nativeLoaderClassName, byteCode, 0, byteCode.length,
|
||||||
System.class.getProtectionDomain());
|
System.class.getProtectionDomain());
|
||||||
|
|
||||||
for (int i = 0; i < preloadClass.length; ++i) {
|
for (int i = 0; i < classesToPreload.length; ++i) {
|
||||||
byte[] b = preloadClassByteCode.get(i);
|
byte[] b = preloadClassByteCode.get(i);
|
||||||
defineClass.invoke(systemClassLoader, preloadClass[i], b, 0, b.length,
|
defineClass.invoke(systemClassLoader, classesToPreload[i], b, 0, b.length,
|
||||||
System.class.getProtectionDomain());
|
System.class.getProtectionDomain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,12 +154,11 @@ public class SnappyLoader
|
|||||||
// Load the loader class
|
// Load the loader class
|
||||||
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
|
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
|
||||||
if (loaderClass != null) {
|
if (loaderClass != null) {
|
||||||
java.lang.reflect.Method loadMethod = loaderClass.getDeclaredMethod("load",
|
Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class });
|
||||||
new Class[] { String.class });
|
|
||||||
File nativeLib = findNativeLibrary();
|
File nativeLib = findNativeLibrary();
|
||||||
loadMethod.invoke(null, nativeLib.getAbsolutePath());
|
loadMethod.invoke(null, nativeLib.getAbsolutePath());
|
||||||
|
|
||||||
for (String each : preloadClass) {
|
for (String each : classesToPreload) {
|
||||||
systemClassLoader.loadClass(each);
|
systemClassLoader.loadClass(each);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ import java.io.IOException;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to access the native code of Snappy
|
* Interface to access the native code of Snappy. Although the methods in this
|
||||||
|
* class are public, do not use them.
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @author leo
|
* @author leo
|
||||||
*
|
*
|
||||||
@ -67,7 +69,7 @@ public class SnappyNative
|
|||||||
public native static boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
public native static boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
||||||
|
|
||||||
protected static void throw_error(int errorCode) throws IOException {
|
protected static void throw_error(int errorCode) throws IOException {
|
||||||
throw new IOException(SnappyErrorCode.getErrorMessage(errorCode));
|
throw new IOException(String.format("%s(%d)", SnappyErrorCode.getErrorMessage(errorCode), errorCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,17 +89,7 @@ public class SnappyLoaderTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void load() throws Exception {
|
public void load() throws Exception {
|
||||||
//SnappyLoader.load();
|
SnappyLoader.load();
|
||||||
// Class< ? > c1 = Class.forName("org.xerial.snappy.SnappyNative");
|
_logger.debug(Snappy.getNativeLibraryVersion());
|
||||||
// Class< ? > c2 = Class.forName("org.xerial.snappy.Snappy");
|
|
||||||
// ClassLoader cl1 = c1.getClassLoader();
|
|
||||||
// ClassLoader cl2 = c2.getClassLoader();
|
|
||||||
// Method m = c1.getDeclaredMethod("nativeLibraryVersion");
|
|
||||||
// m.setAccessible(true);
|
|
||||||
// String version = (String) m.invoke(null);
|
|
||||||
// _logger.info(version);
|
|
||||||
|
|
||||||
//_logger.info(SnappyNative.nativeLibraryVersion());
|
|
||||||
_logger.info(Snappy.getNativeLibraryVersion());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,15 +296,9 @@ public class SnappyTest
|
|||||||
fail("cannot reach here since the input is invalid data");
|
fail("cannot reach here since the input is invalid data");
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
_logger.debug(e);
|
||||||
//assertEquals(SnappyErrorCode.FAILED_TO_UNCOMPRESS, e.errorCode);
|
//assertEquals(SnappyErrorCode.FAILED_TO_UNCOMPRESS, e.errorCode);
|
||||||
}
|
}
|
||||||
// catch (Exception e) {
|
|
||||||
// Class< ? > c = e.getClass();
|
|
||||||
// ClassLoader cl = c.getClassLoader();
|
|
||||||
//
|
|
||||||
// ClassLoader cl2 = SnappyException.class.getClassLoader();
|
|
||||||
// _logger.error(e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user