public static BInteger fromBencodedValue(String bencodedValue, AtomicInteger index) throws BParsingException {
        if (!bencodedValue.startsWith(String.valueOf(START_SYMBOL), index.get())) {
            throw new BParsingException("Invalid bencoded integer");
        }
        final int startIndex = index.incrementAndGet();
        if (bencodedValue.charAt(index.get()) == '-') {
            index.incrementAndGet();
        }

        for (; index.get() < bencodedValue.length(); index.incrementAndGet()) {
            char currentCharacter = bencodedValue.charAt(index.get());
            if (currentCharacter == END_SYMBOL) {
                break;
            }
            if (!Character.isDigit(currentCharacter)) {
                throw new BParsingException("Illegal character where digit is expected");
            }
        }

        if (index.get() >= bencodedValue.length()) {
            throw new BParsingException("No ending character");
        }
        return new BInteger(Integer.parseInt(bencodedValue.substring(startIndex, index.get())));
    }