code: private void writeLengthAndValue() throws IOException {
          if (dataPos == dataSize)
             return;
          int curLen = 0;
          int lenByte = data[dataPos++] & 0xff;
          if (isIndefinite(lenByte)) {
              byte[] lenBytes = (byte[])ndefsList.get(index++);
              System.arraycopy(lenBytes, 0, newData, newDataPos,
                               lenBytes.length);
              newDataPos += lenBytes.length;
              return;
          }
          if (isLongForm(lenByte)) {
              lenByte &= LEN_MASK;
              for (int i = 0; i < lenByte; i++) {
                  curLen = (curLen << 8) + (data[dataPos++] & 0xff);
              }
              if (curLen < 0) {
                  throw new IOException("Invalid length bytes");
              }
          } else {
              curLen = (lenByte & LEN_MASK);
          }
          writeLength(curLen);
          writeValue(curLen);
      }
docs: Write the length and if it is an indefinite length
  then calculate the definite length from the positions
  of the indefinite length and its matching EOC terminator.
  Then, write the value.