diff --git a/src/main/java/org/xerial/snappy/Snappy.java b/src/main/java/org/xerial/snappy/Snappy.java index ea6b41e..256a5b4 100755 --- a/src/main/java/org/xerial/snappy/Snappy.java +++ b/src/main/java/org/xerial/snappy/Snappy.java @@ -384,9 +384,68 @@ public class Snappy public static int uncompressedLength(byte[] input, int offset, int length) throws SnappyException { if (input == null) throw new NullPointerException("input is null"); + return SnappyNative.uncompressedLength(input, offset, length); } + public static class CompressedDataLength + { + public final int cursor; + public final int uncompressedLength; + + public CompressedDataLength(int cursor, int uncompressedLength) { + this.cursor = cursor; + this.uncompressedLength = uncompressedLength; + } + } + + public static CompressedDataLength getUncompressedLength(byte[] input, int offset, int limit) + throws SnappyException { + if (input == null) + throw new NullPointerException("input is null"); + + long b = 0; + long result = 0; + int cursor = offset; + if (cursor >= limit) + return null; + for (;;) { + b = input[cursor++]; + result = b & 127; + if (b < 128) + break; + if (cursor >= limit) + return null; + b = input[cursor++]; + result |= (b & 127) << 7; + if (b < 128) + break; + if (cursor >= limit) + return null; + b = input[cursor++]; + result |= (b & 127) << 14; + if (b < 128) + break; + if (cursor >= limit) + return null; + b = input[cursor++]; + result |= (b & 127) << 21; + if (b < 128) + break; + if (cursor >= limit) + return null; + b = input[cursor++]; + result |= (b & 127) << 28; + if (b < 16) + break; + return null; // Value is too long to be a varint32 + } + if (result > Integer.MAX_VALUE) + throw new IllegalStateException("cannot uncompress byte array longer than 2^31-1: " + result); + + return new CompressedDataLength(cursor, (int) result); + } + /** * Get the uncompressed byte size of the given compressed input. This * operation taks O(1) time. diff --git a/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappyjava.dll b/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappyjava.dll index c4da58e..ab4dad2 100755 Binary files a/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappyjava.dll and b/src/main/resources/org/xerial/snappy/native/Windows/amd64/snappyjava.dll differ diff --git a/src/main/resources/org/xerial/snappy/native/Windows/x86/snappyjava.dll b/src/main/resources/org/xerial/snappy/native/Windows/x86/snappyjava.dll index 7a0a7b4..8a87909 100755 Binary files a/src/main/resources/org/xerial/snappy/native/Windows/x86/snappyjava.dll and b/src/main/resources/org/xerial/snappy/native/Windows/x86/snappyjava.dll differ