Fixes issue 22
Thanks for the report. getUncompressedLength() was an experimental method, that tries to migrate C++ code of the Snappy into Java. I removed this method.
This commit is contained in:
parent
c6e2aebe11
commit
36f0208eb1
|
@ -419,63 +419,6 @@ public class Snappy
|
|||
return impl.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 IOException {
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue