Change the native library version retrieval method to look up
a resource file (VERSION) in org.xerial.snappy package. Update issue 32 Status: Fixed
This commit is contained in:
parent
e6b021d3d1
commit
35f7e8edd6
28
pom.xml
28
pom.xml
|
@ -12,6 +12,34 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The Apache Software License, Version 2.0</name>
|
||||||
|
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>leo</id>
|
||||||
|
<name>Taro L. Saito</name>
|
||||||
|
<email>leo@xerial.org</email>
|
||||||
|
<organization>Xerial Project</organization>
|
||||||
|
<roles>
|
||||||
|
<role>Architect</role>
|
||||||
|
<role>Project Manager</role>
|
||||||
|
<role>Chief Developer</role>
|
||||||
|
</roles>
|
||||||
|
<timezone>+9</timezone>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<organization>
|
||||||
|
<name>xerial.org</name>
|
||||||
|
<url>http://www.xerial.org/</url>
|
||||||
|
</organization>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
|
|
@ -26,8 +26,10 @@ package org.xerial.snappy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snappy API for data compression/decompression
|
* Snappy API for data compression/decompression
|
||||||
|
@ -249,7 +251,24 @@ public class Snappy
|
||||||
* @return native library version
|
* @return native library version
|
||||||
*/
|
*/
|
||||||
public static String getNativeLibraryVersion() {
|
public static String getNativeLibraryVersion() {
|
||||||
return ((SnappyNativeAPI) impl).nativeLibraryVersion();
|
|
||||||
|
URL versionFile = SnappyLoader.class.getResource("/org/xerial/snappy/VERSION");
|
||||||
|
|
||||||
|
String version = "unknown";
|
||||||
|
try {
|
||||||
|
if (versionFile != null) {
|
||||||
|
Properties versionData = new Properties();
|
||||||
|
versionData.load(versionFile.openStream());
|
||||||
|
version = versionData.getProperty("version", version);
|
||||||
|
if (version.equals("unknown"))
|
||||||
|
version = versionData.getProperty("VERSION", version);
|
||||||
|
version = version.trim().replaceAll("[^0-9\\.]", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,15 +373,16 @@ public class Snappy
|
||||||
* @param input
|
* @param input
|
||||||
* input byte array
|
* input byte array
|
||||||
* @param inputOffset
|
* @param inputOffset
|
||||||
* byte offset
|
* byte offset in the input byte array
|
||||||
* @param inputLength
|
* @param inputLength
|
||||||
* byte length of the input data
|
* byte length of the input data
|
||||||
* @param output
|
* @param output
|
||||||
* output buffer, MUST be a primitive type array
|
* output buffer, MUST be a primitive type array
|
||||||
* @param outputOffset
|
* @param outputOffset
|
||||||
* byte offset
|
* byte offset in the output buffer
|
||||||
* @return the byte size of the uncompressed data
|
* @return the byte size of the uncompressed data
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* when failed to uncompress the input data
|
||||||
*/
|
*/
|
||||||
public static int rawUncompress(byte[] input, int inputOffset, int inputLength, Object output, int outputOffset)
|
public static int rawUncompress(byte[] input, int inputOffset, int inputLength, Object output, int outputOffset)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -420,7 +440,7 @@ public class Snappy
|
||||||
* @param compressed
|
* @param compressed
|
||||||
* buffer[pos() ... limit()) containing the input data
|
* buffer[pos() ... limit()) containing the input data
|
||||||
* @param uncompressed
|
* @param uncompressed
|
||||||
* output of the the uncompressed data. It uses buffer[pot()..]
|
* output of the the uncompressed data. It uses buffer[pos()..]
|
||||||
* @return uncompressed data size
|
* @return uncompressed data size
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -451,7 +471,7 @@ public class Snappy
|
||||||
* Uncompress the input data as char array
|
* Uncompress the input data as char array
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* @return the umcompressed data
|
* @return the uncompressed data
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static char[] uncompressCharArray(byte[] input) throws IOException {
|
public static char[] uncompressCharArray(byte[] input) throws IOException {
|
||||||
|
@ -493,7 +513,7 @@ public class Snappy
|
||||||
* operation takes O(1) time.
|
* operation takes O(1) time.
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* @return umcompressed byte size of the the given input data
|
* @return uncompressed byte size of the the given input data
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* when failed to uncompress the given input. The error code is
|
* when failed to uncompress the given input. The error code is
|
||||||
* {@link SnappyErrorCode#PARSING_ERROR}
|
* {@link SnappyErrorCode#PARSING_ERROR}
|
||||||
|
@ -509,7 +529,7 @@ public class Snappy
|
||||||
* @param input
|
* @param input
|
||||||
* @param offset
|
* @param offset
|
||||||
* @param length
|
* @param length
|
||||||
* @return umcompressed byte size of the the given input data
|
* @return uncompressed byte size of the the given input data
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* when failed to uncompress the given input. The error code is
|
* when failed to uncompress the given input. The error code is
|
||||||
* {@link SnappyErrorCode#PARSING_ERROR}
|
* {@link SnappyErrorCode#PARSING_ERROR}
|
||||||
|
|
|
@ -33,7 +33,7 @@ void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
||||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||||
(JNIEnv * env, jobject self)
|
(JNIEnv * env, jobject self)
|
||||||
{
|
{
|
||||||
return env->NewStringUTF("1.0.3");
|
return env->NewStringUTF("1.0.4");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -98,31 +98,31 @@ public class SnappyLoaderTest
|
||||||
// Actually load Snappy.class in a child class loader
|
// Actually load Snappy.class in a child class loader
|
||||||
|
|
||||||
Class< ? > S1 = L1.loadClass("org.xerial.snappy.Snappy");
|
Class< ? > S1 = L1.loadClass("org.xerial.snappy.Snappy");
|
||||||
Method m = S1.getMethod("getNativeLibraryVersion");
|
Method m = S1.getMethod("compress", String.class);
|
||||||
String v = (String) m.invoke(null);
|
byte[] v = (byte[]) m.invoke(null, "hello world");
|
||||||
|
|
||||||
// Load Snappy.class from another child class loader
|
// Load Snappy.class from another child class loader
|
||||||
Class< ? > S2 = L2.loadClass("org.xerial.snappy.Snappy");
|
Class< ? > S2 = L2.loadClass("org.xerial.snappy.Snappy");
|
||||||
Method m2 = S2.getMethod("getNativeLibraryVersion");
|
Method m2 = S2.getMethod("compress", String.class);
|
||||||
String v2 = (String) m2.invoke(null);
|
byte[] v2 = (byte[]) m2.invoke(null, "hello world");
|
||||||
|
|
||||||
assertEquals(v, v2);
|
assertArrayEquals(v, v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void load() throws Exception {
|
public void load() throws Exception {
|
||||||
SnappyLoader.load();
|
SnappyLoader.load();
|
||||||
_logger.debug(Snappy.getNativeLibraryVersion());
|
_logger.debug(Snappy.maxCompressedLength(1024));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autoLoad() throws Exception {
|
public void autoLoad() throws Exception {
|
||||||
_logger.debug(Snappy.getNativeLibraryVersion());
|
_logger.debug(Snappy.maxCompressedLength(1024));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Test for loading native library specified in -Djava.library.path
|
// Test for loading native library specified in -Djava.library.path
|
||||||
System.setProperty(SnappyLoader.KEY_SNAPPY_USE_SYSTEMLIB, "true");
|
System.setProperty(SnappyLoader.KEY_SNAPPY_USE_SYSTEMLIB, "true");
|
||||||
_logger.debug(Snappy.getNativeLibraryVersion());
|
_logger.debug(Snappy.maxCompressedLength(1024));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue