mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-19 20:14:33 +02:00
Removed invalid decompression error code
This commit is contained in:
parent
fd5cec5441
commit
e3c232db7c
@ -127,20 +127,15 @@ public class Snappy
|
|||||||
* @throws SnappyException
|
* @throws SnappyException
|
||||||
*/
|
*/
|
||||||
public static byte[] uncompress(byte[] input) throws SnappyException {
|
public static byte[] uncompress(byte[] input) throws SnappyException {
|
||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
byte[] result = new byte[Snappy.uncompressedLength(input)];
|
||||||
byte[] result = new byte[uncompressedLength];
|
|
||||||
int byteSize = Snappy.uncompress(input, 0, input.length, result, 0);
|
int byteSize = Snappy.uncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short[] uncompressShortArray(byte[] input) throws SnappyException {
|
public static short[] uncompressShortArray(byte[] input) throws SnappyException {
|
||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input);
|
||||||
short[] result = new short[uncompressedLength / 2];
|
short[] result = new short[uncompressedLength / 2];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,8 +143,6 @@ public class Snappy
|
|||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
||||||
char[] result = new char[uncompressedLength / 2];
|
char[] result = new char[uncompressedLength / 2];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,8 +150,6 @@ public class Snappy
|
|||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
||||||
int[] result = new int[uncompressedLength / 4];
|
int[] result = new int[uncompressedLength / 4];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +157,6 @@ public class Snappy
|
|||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
||||||
float[] result = new float[uncompressedLength / 4];
|
float[] result = new float[uncompressedLength / 4];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +164,6 @@ public class Snappy
|
|||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
||||||
long[] result = new long[uncompressedLength / 8];
|
long[] result = new long[uncompressedLength / 8];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +171,6 @@ public class Snappy
|
|||||||
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
|
||||||
double[] result = new double[uncompressedLength / 8];
|
double[] result = new double[uncompressedLength / 8];
|
||||||
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
int byteSize = SnappyNative.rawUncompress(input, 0, input.length, result, 0);
|
||||||
if (byteSize != uncompressedLength)
|
|
||||||
throw new SnappyException(SnappyErrorCode.INVALID_DECOMPRESSION);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,6 +398,20 @@ public class Snappy
|
|||||||
return SnappyNative.uncompressedLength(input, offset, length);
|
return SnappyNative.uncompressedLength(input, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the uncompressed byte size of the given compressed input. This
|
||||||
|
* operation takes O(1) time.
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* @return umcompressed byte size of the the given input data
|
||||||
|
* @throws SnappyException
|
||||||
|
* when failed to uncompress the given input. The error code is
|
||||||
|
* {@link SnappyErrorCode#PARSING_ERROR}
|
||||||
|
*/
|
||||||
|
public static int uncompressedLength(byte[] input) throws SnappyException {
|
||||||
|
return SnappyNative.uncompressedLength(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum byte size needed for compressing a data of the given byte
|
* Get the maximum byte size needed for compressing a data of the given byte
|
||||||
* size.
|
* size.
|
||||||
|
@ -32,12 +32,12 @@ package org.xerial.snappy;
|
|||||||
*/
|
*/
|
||||||
public enum SnappyErrorCode {
|
public enum SnappyErrorCode {
|
||||||
|
|
||||||
|
// DO NOT change the id of the error codes since these IDs are also used in SnappyNative.cpp
|
||||||
UNKNOWN(0),
|
UNKNOWN(0),
|
||||||
FAILED_TO_LOAD_NATIVE_LIBRARY(1),
|
FAILED_TO_LOAD_NATIVE_LIBRARY(1),
|
||||||
PARSING_ERROR(2),
|
PARSING_ERROR(2),
|
||||||
NOT_A_DIRECT_BUFFER(3),
|
NOT_A_DIRECT_BUFFER(3),
|
||||||
OUT_OF_MEMORY(4),
|
OUT_OF_MEMORY(4);
|
||||||
INVALID_DECOMPRESSION(5);
|
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user