private int readStringLength(InputStream inputStream) throws IOException, InvalidFormatException {
        StringBuilder stringBuilder = new StringBuilder();
        int currentByte;
        while ((currentByte = inputStream.read()) > -1) {
            char currentChar = (char) currentByte;
            if (currentChar == BencodeString.LENGTH_SEPARATOR) {
                break;
            } else if (!Character.isDigit(currentChar)) {
                throw new InvalidFormatException();
            }
            stringBuilder.append(currentChar);
        }

        return parseInt(stringBuilder.toString());
    }