/** * Zero-copy decompress using memory addresses. * * @param inputAddr input memory address * @param inputSize input byte size * @param destAddr destination address of the uncompressed data * @return the uncompressed data size * @throws IOException */ public static long rawUncompress(long inputAddr, long inputSize, long destAddr) throws IOException { return impl.rawUncompress(inputAddr, inputSize, destAddr); }
/** * Uncompress the content in the input buffer. The uncompressed data is * written to the output buffer. * <p/> * Note that if you pass the wrong data or the range [inputOffset, * inputOffset + inputLength) that cannot be uncompressed, your JVM might * crash due to the access violation exception issued in the native code * written in C++. To avoid this type of crash, use * {@link #isValidCompressedBuffer(byte[], int, int)} first. * * @param input input byte array * @param inputOffset 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 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 { if (input == null || output == null) { throw new NullPointerException("input or output is null"); } return impl.rawUncompress(input, inputOffset, inputLength, output, outputOffset); }
/** * Uncompress the input[offset, offset+length) as a short array * * @param input * @param offset * @param length * @return the uncompressed data * @throws IOException */ public static short[] uncompressShortArray(byte[] input, int offset, int length) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, offset, length); short[] result = new short[uncompressedLength / 2]; impl.rawUncompress(input, offset, length, result, 0); return result; }
/** * Uncompress the input[offset, .., offset+length) as a char array * * @param input * @param offset * @param length * @return the uncompressed data * @throws IOException */ public static char[] uncompressCharArray(byte[] input, int offset, int length) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, offset, length); char[] result = new char[uncompressedLength / 2]; impl.rawUncompress(input, offset, length, result, 0); return result; }
/** * Uncompress the input as a double array * * @param input * @return the uncompressed data * @throws IOException */ public static double[] uncompressDoubleArray(byte[] input) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length); double[] result = new double[uncompressedLength / 8]; impl.rawUncompress(input, 0, input.length, result, 0); return result; }
/** * Uncompress the input[offset, offset+length) as a float array * * @param input * @param offset * @param length * @return the uncompressed data * @throws IOException */ public static float[] uncompressFloatArray(byte[] input, int offset, int length) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, offset, length); float[] result = new float[uncompressedLength / 4]; impl.rawUncompress(input, offset, length, result, 0); return result; }
/** * Uncompress the input[offset, offset+length) as an int array * * @param input * @param offset * @param length * @return the uncompressed data * @throws IOException */ public static int[] uncompressIntArray(byte[] input, int offset, int length) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, offset, length); int[] result = new int[uncompressedLength / 4]; impl.rawUncompress(input, offset, length, result, 0); return result; }
/** * Uncompress the input[offset, offset+length) as a long array * * @param input * @param offset * @param length * @return the uncompressed data * @throws IOException */ public static long[] uncompressLongArray(byte[] input, int offset, int length) throws IOException { int uncompressedLength = Snappy.uncompressedLength(input, offset, length); long[] result = new long[uncompressedLength / 8]; impl.rawUncompress(input, offset, length, result, 0); return result; }
int decompressedSize = impl.rawUncompress(compressed, cPos, cLen, uncompressed, uncompressed.position()); uncompressed.limit(uncompressed.position() + decompressedSize);
@Override public long rawUncompress(byte[] input, byte[] output) throws IOException { return snappyNative.rawUncompress(input, 0, input.length, output, 0); }
@Override public double[] unCompressDouble(byte[] compInput, int offset, int length) { try { int uncompressedLength = Snappy.uncompressedLength(compInput, offset, length); double[] result = new double[uncompressedLength / 8]; snappyNative.rawUncompress(compInput, offset, length, result, 0); return result; } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } }
@Override public byte[] unCompressByte(byte[] compInput, int offset, int length) { int uncompressedLength = 0; byte[] data; try { uncompressedLength = Snappy.uncompressedLength(compInput, offset, length); data = new byte[uncompressedLength]; snappyNative.rawUncompress(compInput, offset, length, data, 0); } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw new RuntimeException(e); } return data; }