/** * Read uncompressed data into the specified array * * @param array * @param byteOffset * @param byteLength * @return written bytes * @throws IOException */ public int rawRead(Object array, int byteOffset, int byteLength) throws IOException { int writtenBytes = 0; for (; writtenBytes < byteLength; ) { if (uncompressedCursor >= uncompressedLimit) { if (hasNextChunk()) { continue; } else { return writtenBytes == 0 ? -1 : writtenBytes; } } int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes); Snappy.arrayCopy(uncompressed, uncompressedCursor, bytesToWrite, array, byteOffset + writtenBytes); writtenBytes += bytesToWrite; uncompressedCursor += bytesToWrite; } return writtenBytes; }
/** * Compress the raw byte array data. * * @param array array data of any type (e.g., byte[], float[], long[], ...) * @param byteOffset * @param byteLength * @throws IOException */ public void rawWrite(Object array, int byteOffset, int byteLength) throws IOException { if (closed) { throw new IOException("Stream is closed"); } int cursor = 0; while (cursor < byteLength) { int readLen = Math.min(byteLength - cursor, blockSize - inputCursor); // copy the input data to uncompressed buffer if (readLen > 0) { Snappy.arrayCopy(array, byteOffset + cursor, readLen, inputBuffer, inputCursor); inputCursor += readLen; } if (inputCursor < blockSize) { return; } compressInput(); cursor += readLen; } }
public static void byteCopy(Object src, int srcOffset, Object dst, int dstOffset, int n) { try { Snappy.arrayCopy(src, srcOffset, n, dst, dstOffset); } catch (IOException e) { Util.uncheckedThrow(e); } }
public static void byteCopy(Object src, int srcOffset, Object dst, int dstOffset, int n) { try { Snappy.arrayCopy(src, srcOffset, n, dst, dstOffset); } catch (IOException e) { Util.uncheckedThrow(e); } }