diff --git a/pom.xml b/pom.xml index 37cf2ca..af61c9d 100755 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,34 @@ UTF-8 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + leo + Taro L. Saito + leo@xerial.org + Xerial Project + + Architect + Project Manager + Chief Developer + + +9 + + + + + xerial.org + http://www.xerial.org/ + + diff --git a/src/main/java/org/xerial/snappy/Snappy.java b/src/main/java/org/xerial/snappy/Snappy.java index 3d41e31..dac227f 100755 --- a/src/main/java/org/xerial/snappy/Snappy.java +++ b/src/main/java/org/xerial/snappy/Snappy.java @@ -26,8 +26,10 @@ package org.xerial.snappy; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.util.Properties; /** * Snappy API for data compression/decompression @@ -249,7 +251,24 @@ public class Snappy * @return native library version */ 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 * input byte array * @param inputOffset - * byte offset + * byte offset in the input byte array * @param inputLength * byte length of the input data * @param output * output buffer, MUST be a primitive type array * @param outputOffset - * byte offset + * byte offset in the output buffer * @return the byte size of the uncompressed data * @throws IOException + * when failed to uncompress the input data */ public static int rawUncompress(byte[] input, int inputOffset, int inputLength, Object output, int outputOffset) throws IOException { @@ -420,7 +440,7 @@ public class Snappy * @param compressed * buffer[pos() ... limit()) containing the input data * @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 * * @throws IOException @@ -451,7 +471,7 @@ public class Snappy * Uncompress the input data as char array * * @param input - * @return the umcompressed data + * @return the uncompressed data * @throws IOException */ public static char[] uncompressCharArray(byte[] input) throws IOException { @@ -493,7 +513,7 @@ public class Snappy * operation takes O(1) time. * * @param input - * @return umcompressed byte size of the the given input data + * @return uncompressed byte size of the the given input data * @throws IOException * when failed to uncompress the given input. The error code is * {@link SnappyErrorCode#PARSING_ERROR} @@ -509,7 +529,7 @@ public class Snappy * @param input * @param offset * @param length - * @return umcompressed byte size of the the given input data + * @return uncompressed byte size of the the given input data * @throws IOException * when failed to uncompress the given input. The error code is * {@link SnappyErrorCode#PARSING_ERROR} diff --git a/src/main/java/org/xerial/snappy/SnappyNative.cpp b/src/main/java/org/xerial/snappy/SnappyNative.cpp index 53452a0..c4b9b4a 100755 --- a/src/main/java/org/xerial/snappy/SnappyNative.cpp +++ b/src/main/java/org/xerial/snappy/SnappyNative.cpp @@ -33,7 +33,7 @@ void throw_exception(JNIEnv *env, jobject self, int errorCode) JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion (JNIEnv * env, jobject self) { - return env->NewStringUTF("1.0.3"); + return env->NewStringUTF("1.0.4"); } /* diff --git a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java index cd7291f..81ecd53 100755 --- a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java +++ b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java @@ -98,31 +98,31 @@ public class SnappyLoaderTest // Actually load Snappy.class in a child class loader Class< ? > S1 = L1.loadClass("org.xerial.snappy.Snappy"); - Method m = S1.getMethod("getNativeLibraryVersion"); - String v = (String) m.invoke(null); + Method m = S1.getMethod("compress", String.class); + byte[] v = (byte[]) m.invoke(null, "hello world"); // Load Snappy.class from another child class loader Class< ? > S2 = L2.loadClass("org.xerial.snappy.Snappy"); - Method m2 = S2.getMethod("getNativeLibraryVersion"); - String v2 = (String) m2.invoke(null); + Method m2 = S2.getMethod("compress", String.class); + byte[] v2 = (byte[]) m2.invoke(null, "hello world"); - assertEquals(v, v2); + assertArrayEquals(v, v2); } @Test public void load() throws Exception { SnappyLoader.load(); - _logger.debug(Snappy.getNativeLibraryVersion()); + _logger.debug(Snappy.maxCompressedLength(1024)); } @Test public void autoLoad() throws Exception { - _logger.debug(Snappy.getNativeLibraryVersion()); + _logger.debug(Snappy.maxCompressedLength(1024)); } public static void main(String[] args) { // Test for loading native library specified in -Djava.library.path System.setProperty(SnappyLoader.KEY_SNAPPY_USE_SYSTEMLIB, "true"); - _logger.debug(Snappy.getNativeLibraryVersion()); + _logger.debug(Snappy.maxCompressedLength(1024)); } }