mirror of
				https://github.com/xerial/snappy-java.git
				synced 2025-10-31 03:25:19 +01:00 
			
		
		
		
	Fall back to the previous loading strategy that simply use LoadSnappy.load()
This commit is contained in:
		
							parent
							
								
									9f71f8eb1c
								
							
						
					
					
						commit
						a1f39c8b5a
					
				| @ -24,9 +24,6 @@ | |||||||
| //-------------------------------------- | //-------------------------------------- | ||||||
| package org.xerial.snappy; | package org.xerial.snappy; | ||||||
| 
 | 
 | ||||||
| import java.lang.reflect.Method; |  | ||||||
| import java.net.URL; |  | ||||||
| import java.net.URLClassLoader; |  | ||||||
| import java.nio.ByteBuffer; | import java.nio.ByteBuffer; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -39,44 +36,8 @@ public class Snappy | |||||||
| { | { | ||||||
| 
 | 
 | ||||||
|     static { |     static { | ||||||
|         URL resource = Snappy.class.getResource("/org/xerial/snappy/SnappyNative.class"); |  | ||||||
|         // jar:file:/C:/.../snappy-java-1.0.1-rc4-SNAPSHOT.jar!/org/xerial/snappy/SnappyNative.class |  | ||||||
|         if (resource == null) { |  | ||||||
|         LoadSnappy.load(); |         LoadSnappy.load(); | ||||||
|     } |     } | ||||||
|         else { |  | ||||||
|             String path = resource.toString(); |  | ||||||
|             if (path.startsWith("jar:")) { |  | ||||||
|                 int pos = path.indexOf(".jar!"); |  | ||||||
|                 if (pos >= 0) { |  | ||||||
|                     path = path.substring(4, pos + 4); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             else { |  | ||||||
|                 path = path.replace("SnappyNative", "LoadSnappy"); |  | ||||||
|             } |  | ||||||
|             try { |  | ||||||
|                 URL loaderPath = new URL(path); |  | ||||||
|                 ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); |  | ||||||
|                 if (URLClassLoader.class.isInstance(systemClassLoader)) { |  | ||||||
| 
 |  | ||||||
|                     URLClassLoader cl = URLClassLoader.class.cast(systemClassLoader); |  | ||||||
|                     Method addURLmethod = URLClassLoader.class.getDeclaredMethod("addURL", |  | ||||||
|                             new Class< ? >[] { URL.class }); |  | ||||||
|                     addURLmethod.setAccessible(true); |  | ||||||
| 
 |  | ||||||
|                     addURLmethod.invoke(cl, loaderPath); |  | ||||||
|                     Class< ? > snappyLoader = cl.loadClass("org.xerial.snappy.LoadSnappy"); |  | ||||||
|                     Method loader = snappyLoader.getMethod("load"); |  | ||||||
|                     loader.invoke(null); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             catch (Exception e) { |  | ||||||
|                 e.printStackTrace(); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Get the native library version of the snappy |      * Get the native library version of the snappy | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user