/** * writes an int using the requested number of bits. * accepts only values less than 2^bitWidth * @param value the value to write * @throws IOException if there is an exception while writing */ public void writeInt(int value) throws IOException { input[inputSize] = value; ++ inputSize; if (inputSize == VALUES_WRITTEN_AT_A_TIME) { pack(); if (packedPosition == slabSize) { slabs.add(BytesInput.from(packed)); totalFullSlabSize += slabSize; if (slabSize < bitWidth * MAX_SLAB_SIZE_MULT) { slabSize *= 2; } initPackedSlab(); } } }
/** * writes an int using the requested number of bits. * accepts only values less than 2^bitWidth * @param value the value to write * @throws IOException if there is an exception while writing */ public void writeInt(int value) throws IOException { input[inputSize] = value; ++ inputSize; if (inputSize == VALUES_WRITTEN_AT_A_TIME) { pack(); if (packedPosition == slabSize) { slabs.add(BytesInput.from(packed)); totalFullSlabSize += slabSize; if (slabSize < bitWidth * MAX_SLAB_SIZE_MULT) { slabSize *= 2; } initPackedSlab(); } } }
/** * @return the bytes representing the packed values * @throws IOException if there is an exception while creating the BytesInput */ public BytesInput toBytes() throws IOException { int packedByteLength = packedPosition + BytesUtils.paddedByteCountFromBits(inputSize * bitWidth); LOG.debug("writing {} bytes", (totalFullSlabSize + packedByteLength)); if (inputSize > 0) { for (int i = inputSize; i < input.length; i++) { input[i] = 0; } pack(); } return concat(concat(slabs), BytesInput.from(packed, 0, packedByteLength)); }
/** * @return the bytes representing the packed values * @throws IOException if there is an exception while creating the BytesInput */ public BytesInput toBytes() throws IOException { int packedByteLength = packedPosition + BytesUtils.paddedByteCountFromBits(inputSize * bitWidth); LOG.debug("writing {} bytes", (totalFullSlabSize + packedByteLength)); if (inputSize > 0) { for (int i = inputSize; i < input.length; i++) { input[i] = 0; } pack(); } return concat(concat(slabs), BytesInput.from(packed, 0, packedByteLength)); }