@Override public final int decodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer) throws IOException { /* note: we do NOT read more than 5 bytes because otherwise might need to shuffle bytes * for output buffer (could perhaps optimize in future?) */ int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { if (bytesRead == 0) { // probably fine, clean EOF return -1; } _reportCorruptHeader(); } int type = inputBuffer[2]; int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed readFully(is, false, outputBuffer, 0, compLen); return compLen; } // compressed readFully(is, true, inputBuffer, 0, 2+compLen); // first 2 bytes are uncompressed length int uncompLen = uint16(inputBuffer, 0); decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return uncompLen; }
System.arraycopy(in, inPos, out, outPos, ctrl+1); } else { copyUpTo32(in, inPos, out, outPos, ctrl); outPos = copyOverlappingShort(out, outPos, ctrl, len); continue; outPos = copyOverlappingLong(out, outPos, ctrl, len-9); continue; copyUpTo32(out, outPos+ctrl, outPos, len-1); outPos += len; continue; copyLong(out, outPos+ctrl, outPos, len, outputEnd32); outPos += len; } while (outPos < outEnd);
private final static void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8) { if ((outputIndex + length) > outputEnd8) { copyLongTail(buffer, inputIndex,outputIndex, length); return; } long inPtr = BYTE_ARRAY_OFFSET + inputIndex; long outPtr = BYTE_ARRAY_OFFSET + outputIndex; while (length >= 8) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); inPtr += 8; outPtr += 8; length -= 8; } if (length > 4) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); } else if (length > 0) { unsafe.putInt(buffer, outPtr, unsafe.getInt(buffer, inPtr)); } }
System.arraycopy(in, inPos, out, outPos, ctrl+1); } else { copyUpTo32(in, inPos, out, outPos, ctrl); outPos = copyOverlappingShort(out, outPos, ctrl, len); continue; outPos = copyOverlappingLong(out, outPos, ctrl, len-9); continue; copyUpTo32(out, outPos+ctrl, outPos, len-1); outPos += len; continue; copyLong(out, outPos+ctrl, outPos, len, outputEnd32); outPos += len; } while (outPos < outEnd);
private final static void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8) { if ((outputIndex + length) > outputEnd8) { copyLongTail(buffer, inputIndex,outputIndex, length); return; } long inPtr = BYTE_ARRAY_OFFSET + inputIndex; long outPtr = BYTE_ARRAY_OFFSET + outputIndex; while (length >= 8) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); inPtr += 8; outPtr += 8; length -= 8; } if (length > 4) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); } else if (length > 0) { unsafe.putInt(buffer, outPtr, unsafe.getInt(buffer, inPtr)); } }
@Override public final int decodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer) throws IOException { /* note: we do NOT read more than 5 bytes because otherwise might need to shuffle bytes * for output buffer (could perhaps optimize in future?) */ int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { if (bytesRead == 0) { // probably fine, clean EOF return -1; } _reportCorruptHeader(); } int type = inputBuffer[2]; int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed readFully(is, false, outputBuffer, 0, compLen); return compLen; } // compressed readFully(is, true, inputBuffer, 0, 2+compLen); // first 2 bytes are uncompressed length int uncompLen = uint16(inputBuffer, 0); decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return uncompLen; }
System.arraycopy(in, inPos, out, outPos, ctrl+1); } else { copyUpTo32(in, inPos, out, outPos, ctrl); outPos = copyOverlappingShort(out, outPos, ctrl, len); continue; outPos = copyOverlappingLong(out, outPos, ctrl, len-9); continue; copyUpTo32(out, outPos+ctrl, outPos, len-1); outPos += len; continue; copyLong(out, outPos+ctrl, outPos, len, outputEnd32); outPos += len; } while (outPos < outEnd);
private final static void copyLong(byte[] buffer, int inputIndex, int outputIndex, int length, int outputEnd8) { if ((outputIndex + length) > outputEnd8) { copyLongTail(buffer, inputIndex,outputIndex, length); return; } long inPtr = BYTE_ARRAY_OFFSET + inputIndex; long outPtr = BYTE_ARRAY_OFFSET + outputIndex; while (length >= 8) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); inPtr += 8; outPtr += 8; length -= 8; } if (length > 4) { unsafe.putLong(buffer, outPtr, unsafe.getLong(buffer, inPtr)); } else if (length > 0) { unsafe.putInt(buffer, outPtr, unsafe.getInt(buffer, inPtr)); } }
@Override public final int decodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer) throws IOException { /* note: we do NOT read more than 5 bytes because otherwise might need to shuffle bytes * for output buffer (could perhaps optimize in future?) */ int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { if (bytesRead == 0) { // probably fine, clean EOF return -1; } _reportCorruptHeader(); } int type = inputBuffer[2]; int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed readFully(is, false, outputBuffer, 0, compLen); return compLen; } // compressed readFully(is, true, inputBuffer, 0, 2+compLen); // first 2 bytes are uncompressed length int uncompLen = uint16(inputBuffer, 0); decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return uncompLen; }
throws IOException int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { return -1; _reportCorruptHeader(); int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed, simple if (compLen <= maxToSkip) { skipFully(is, compLen); return compLen; readFully(is, false, outputBuffer, 0, compLen); return -(compLen+1); readFully(is, true, inputBuffer, 0, 2); int uncompLen = uint16(inputBuffer, 0); skipFully(is, compLen); return uncompLen; readFully(is, true, inputBuffer, 2, compLen); // first 2 bytes are uncompressed length decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return -(uncompLen+1);
throws IOException int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { return -1; _reportCorruptHeader(); int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed, simple if (compLen <= maxToSkip) { skipFully(is, compLen); return compLen; readFully(is, false, outputBuffer, 0, compLen); return -(compLen+1); readFully(is, true, inputBuffer, 0, 2); int uncompLen = uint16(inputBuffer, 0); skipFully(is, compLen); return uncompLen; readFully(is, true, inputBuffer, 2, compLen); // first 2 bytes are uncompressed length decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return -(uncompLen+1);
throws IOException int bytesRead = readHeader(is, inputBuffer); if ((bytesRead < HEADER_BYTES) || inputBuffer[0] != LZFChunk.BYTE_Z || inputBuffer[1] != LZFChunk.BYTE_V) { return -1; _reportCorruptHeader(); int compLen = uint16(inputBuffer, 3); if (type == LZFChunk.BLOCK_TYPE_NON_COMPRESSED) { // uncompressed, simple if (compLen <= maxToSkip) { skipFully(is, compLen); return compLen; readFully(is, false, outputBuffer, 0, compLen); return -(compLen+1); readFully(is, true, inputBuffer, 0, 2); int uncompLen = uint16(inputBuffer, 0); skipFully(is, compLen); return uncompLen; readFully(is, true, inputBuffer, 2, compLen); // first 2 bytes are uncompressed length decodeChunk(inputBuffer, 2, outputBuffer, 0, uncompLen); return -(uncompLen+1);