code: public void setNextByte(final byte[] pValue, final int pLength, final boolean pPadBefore) {
  		int totalSize = (int) Math.ceil(pLength / BYTE_SIZE_F);
  		ByteBuffer buffer = ByteBuffer.allocate(totalSize);
  		int size = Math.max(totalSize - pValue.length, 0);
  		if (pPadBefore) {
  			for (int i = 0; i < size; i++) {
  				buffer.put((byte) 0);
  			}
  		}
  		buffer.put(pValue, 0, Math.min(totalSize, pValue.length));
  		if (!pPadBefore) {
  			for (int i = 0; i < size; i++) {
  				buffer.put((byte) 0);
  			}
  		}
  		byte tab[] = buffer.array();
  		if (currentBitIndex % BYTE_SIZE != 0) {
  			int index = 0;
  			int max = currentBitIndex + pLength;
  			while (currentBitIndex < max) {
  				int mod = currentBitIndex % BYTE_SIZE;
  				int modTab = index % BYTE_SIZE;
  				int length = Math.min(max - currentBitIndex, Math.min(BYTE_SIZE - mod, BYTE_SIZE - modTab));
  				byte val = (byte) (tab[index / BYTE_SIZE] & getMask(modTab, length));
  				if (mod == 0) {
  					val = (byte) (val << Math.min(modTab, BYTE_SIZE - length));
  				} else {
  					val = (byte) ((val & DEFAULT_VALUE) >> mod);
  				}
  				byteTab[currentBitIndex / BYTE_SIZE] |= val;
  				currentBitIndex += length;
  				index += length;
  			}
  
  		} else {
  			System.arraycopy(tab, 0, byteTab, currentBitIndex / BYTE_SIZE, tab.length);
  			currentBitIndex += pLength;
  		}
  	}
docs: Method to write bytes with the max length
  
  @param pValue
  the value to write
  @param pLength
  the length of the data in bits
  @param pPadBefore
  if true pad with 0