public void writeBit(boolean bit) { if (DEBUG) LOG.debug("writing: " + (bit ? "1" : "0")); currentByte = setBytePosition(currentByte, currentBytePosition++, bit); if (currentBytePosition == 8) { baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); currentByte = 0; currentBytePosition = 0; } }
public void writeByte(int val) { if (DEBUG) LOG.debug("writing: " + toBinary(val) + " (" + val + ")"); currentByte |= ((val & 0xFF) << currentBytePosition); baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); currentByte >>>= 8; }
public void writeBit(boolean bit) { if (DEBUG) LOG.debug("writing: " + (bit ? "1" : "0")); currentByte = setBytePosition(currentByte, currentBytePosition++, bit); if (currentBytePosition == 8) { baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); currentByte = 0; currentBytePosition = 0; } }
public BytesInput finish() { if (!finished) { if (currentBytePosition > 0) { baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); } } finished = true; return BytesInput.from(baos); }
public byte[] finish() { if (!finished) { if (currentBytePosition > 0) { baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); } } byte[] buf = baos.toByteArray(); finished = true; return buf; }
public void writeByte(int val) { if (DEBUG) LOG.debug("writing: " + toBinary(val) + " (" + val + ")"); currentByte |= ((val & 0xFF) << currentBytePosition); baos.write(currentByte); if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); currentByte >>>= 8; }
private void writeOrAppendBitPackedRun() throws IOException { if (bitPackedGroupCount >= 63) { // we've packed as many values as we can for this run, // end it and start a new one endPreviousBitPackedRun(); } if (bitPackedRunHeaderPointer == -1) { // this is a new bit-packed-run, allocate a byte for the header // and keep a "pointer" to it so that it can be mutated later baos.write(0); // write a sentinel value bitPackedRunHeaderPointer = baos.getCurrentIndex(); } packer.pack8Values(bufferedValues, 0, packBuffer, 0); baos.write(packBuffer); // empty the buffer, they've all been written numBufferedValues = 0; // clear the repeat count, as some repeated values // may have just been bit packed into this run repeatCount = 0; ++bitPackedGroupCount; }
/** * Write the given integer, serialized using the given number of bits. * It is assumed that the integer can be correctly serialized within * the provided bit size. * @param val the value to serialize * @param bitsToWrite the number of bits to use */ public void writeNBitInteger(int val, int bitsToWrite) { if (DEBUG) LOG.debug("writing: " + toBinary(val, bitsToWrite) + " (" + val + ")"); val <<= currentBytePosition; int upperByte = currentBytePosition + bitsToWrite; currentByte |= val; while (upperByte >= 8) { baos.write(currentByte); //this only writes the lowest byte if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); upperByte -= 8; currentByte >>>= 8; } currentBytePosition = (currentBytePosition + bitsToWrite) % 8; }
/** * Write the given integer, serialized using the given number of bits. * It is assumed that the integer can be correctly serialized within * the provided bit size. * @param val the value to serialize * @param bitsToWrite the number of bits to use */ public void writeNBitInteger(int val, int bitsToWrite) { if (DEBUG) LOG.debug("writing: " + toBinary(val, bitsToWrite) + " (" + val + ")"); val <<= currentBytePosition; int upperByte = currentBytePosition + bitsToWrite; currentByte |= val; while (upperByte >= 8) { baos.write(currentByte); //this only writes the lowest byte if (DEBUG) LOG.debug("to buffer: " + toBinary(currentByte)); upperByte -= 8; currentByte >>>= 8; } currentBytePosition = (currentBytePosition + bitsToWrite) % 8; }
private void flushBlockBuffer() { //since we store the min delta, the deltas will be converted to be the difference to min delta and all positive for (int i = 0; i < deltaValuesToFlush; i++) { deltaBlockBuffer[i] = deltaBlockBuffer[i] - minDeltaInCurrentBlock; } writeMinDelta(); int miniBlocksToFlush = getMiniBlockCountToFlush(deltaValuesToFlush); calculateBitWidthsForDeltaBlockBuffer(miniBlocksToFlush); for (int i = 0; i < config.miniBlockNumInABlock; i++) { writeBitWidthForMiniBlock(i); } for (int i = 0; i < miniBlocksToFlush; i++) { //writing i th miniblock int currentBitWidth = bitWidths[i]; BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(currentBitWidth); int miniBlockStart = i * config.miniBlockSizeInValues; for (int j = miniBlockStart; j < (i + 1) * config.miniBlockSizeInValues; j += 8) {//8 values per pack // mini block is atomic in terms of flushing // This may write more values when reach to the end of data writing to last mini block, // since it may not be aligend to miniblock, // but doesnt matter. The reader uses total count to see if reached the end. packer.pack8Values(deltaBlockBuffer, j, miniBlockByteBuffer, 0); baos.write(miniBlockByteBuffer, 0, currentBitWidth); } } minDeltaInCurrentBlock = Integer.MAX_VALUE; deltaValuesToFlush = 0; }