diff --git a/Makefile.common b/Makefile.common index aaefa1f..b047701 100755 --- a/Makefile.common +++ b/Makefile.common @@ -109,7 +109,7 @@ SNAPPY_FLAGS := $($(os_arch)_SNAPPY_FLAGS) SNAPPY_OUT:=$(TARGET)/$(snappy)-$(os_arch) -CXXFLAGS := $(CXXFLAGS) -I$(SNAPPY_OUT) -I$(SNAPPY_SRC) +CXXFLAGS := $(CXXFLAGS) -Ilib/include -I$(SNAPPY_OUT) -I$(SNAPPY_SRC) ifneq ($(jni_include),) CXXFLAGS := $(CXXFLAGS) -I"$(jni_include)" endif diff --git a/src/main/java/org/xerial/snappy/Snappy.java b/src/main/java/org/xerial/snappy/Snappy.java index 84ccd03..4530934 100755 --- a/src/main/java/org/xerial/snappy/Snappy.java +++ b/src/main/java/org/xerial/snappy/Snappy.java @@ -22,7 +22,7 @@ public class Snappy * @param uncompressed * input is at buffer[pos() ... limit()) * @param compressed - * output compressed data to buffer[pos()] + * output compressed data to buffer[pos()..] * @return byte size of the compressed data */ public static int compress(ByteBuffer uncompressed, ByteBuffer compressed) { @@ -38,11 +38,6 @@ public class Snappy int uLen = uncompressed.remaining(); int compressedSize = SnappyNative.rawCompress(uncompressed, uPos, uLen, compressed, compressed.position()); - // // pos limit - // // [ ....XXXXXX.........] - // uncompressed.limit(uncompressed.capacity()); - // uncompressed.position(uPos + uLen); - // pos limit // [ ......BBBBBBB.........] compressed.limit(compressed.position() + compressedSize); @@ -53,11 +48,11 @@ public class Snappy /** * @param compressed * input is at buffer[pos() ... limit()) - * @param decompressed + * @param uncompressed * output decompressed data to buffer[pot()) * @return */ - public static boolean decompress(ByteBuffer compressed, ByteBuffer decompressed) { + public static boolean uncompress(ByteBuffer compressed, ByteBuffer decompressed) { if (!compressed.isDirect()) throw new IllegalArgumentException("input is not a direct buffer"); @@ -75,6 +70,13 @@ public class Snappy return ret; } + /** + * Get the uncompressed size of the compressed input + * + * @param compressed + * data [pos() ... limit()) + * @return + */ public static int getUncompressedLength(ByteBuffer compressed) { if (!compressed.isDirect()) throw new IllegalArgumentException("input is not a direct buffer"); @@ -82,6 +84,13 @@ public class Snappy return SnappyNative.getUncompressedLength(compressed, compressed.position(), compressed.remaining()); } + /** + * Get the maximum size of the compressed data of a given byte size + * + * @param byteSize + * byte size of the data to compress + * @return maxmum byte size of the compressed data + */ public static int getMaxCompressedLength(int byteSize) { return SnappyNative.maxCompressedLength(byteSize); } diff --git a/src/main/java/org/xerial/snappy/SnappyErrorCode.java b/src/main/java/org/xerial/snappy/SnappyErrorCode.java new file mode 100755 index 0000000..b0fe529 --- /dev/null +++ b/src/main/java/org/xerial/snappy/SnappyErrorCode.java @@ -0,0 +1,37 @@ +/*-------------------------------------------------------------------------- + * Copyright 2011 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// SnappyErrorCode.java +// Since: 2011/03/30 14:56:50 +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.snappy; + +/** + * Error codes of snappy-java + * + * @author leo + * + */ +public enum SnappyErrorCode { + + FAILED_TO_LOAD_NATIVE_LIBRARY, PARSING_ERROR, ; + +} diff --git a/src/main/java/org/xerial/snappy/SnappyException.java b/src/main/java/org/xerial/snappy/SnappyException.java new file mode 100755 index 0000000..8ffabda --- /dev/null +++ b/src/main/java/org/xerial/snappy/SnappyException.java @@ -0,0 +1,51 @@ +/*-------------------------------------------------------------------------- + * Copyright 2011 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// SnappyException.java +// Since: 2011/03/30 14:56:14 +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.snappy; + +/** + * Exception in snappy-java + * + * @author leo + * + */ +public class SnappyException extends Exception +{ + private static final long serialVersionUID = 1L; + + public final SnappyErrorCode errorCode; + + public SnappyException(SnappyErrorCode errorCode) { + this.errorCode = errorCode; + } + + public SnappyErrorCode getErrorCode() { + return errorCode; + } + + @Override + public String getMessage() { + return String.format("[%s] %s", errorCode.name(), super.getMessage()); + } +} diff --git a/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappy.dll b/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappy.dll index bfa71c6..0aedf65 100755 Binary files a/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappy.dll and b/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappy.dll differ diff --git a/src/test/java/org/xerial/snappy/SnappyTest.java b/src/test/java/org/xerial/snappy/SnappyTest.java index 2dddd1a..f59819e 100755 --- a/src/test/java/org/xerial/snappy/SnappyTest.java +++ b/src/test/java/org/xerial/snappy/SnappyTest.java @@ -68,7 +68,7 @@ public class SnappyTest int uncompressedLen = Snappy.getUncompressedLength(compressed); _logger.info("uncompressed length: " + uncompressedLen); ByteBuffer extract = ByteBuffer.allocateDirect(uncompressedLen); - Snappy.decompress(compressed, extract); + Snappy.uncompress(compressed, extract); extract.limit(uncompressedLen); byte[] b = new byte[uncompressedLen];