private int checkForEndOfString(final int bracesParameter) throws IOException
    {
        if (bracesParameter == 0)
        {
            return 0;
        }
        // Check the next 3 bytes if available
        byte[] nextThreeBytes = new byte[3];
        int amountRead = source.read(nextThreeBytes);
        if (amountRead > 0)
        {
            source.rewind(amountRead);
        }
        if (amountRead < 3)
        {
            return bracesParameter;
        }
        // The following cases are valid indicators for the end of the string
        // 1. Next line contains another COSObject: CR + LF + '/'
        // 2. COSDictionary ends in the next line: CR + LF + '>'
        // 3. Next line contains another COSObject: LF + '/'
        // 4. COSDictionary ends in the next line: LF + '>'
        // 5. Next line contains another COSObject: CR + '/'
        // 6. COSDictionary ends in the next line: CR + '>'
        if (((isCR(nextThreeBytes[0]) || isLF(nextThreeBytes[0]))
                && (nextThreeBytes[1] == '/' || nextThreeBytes[1] == '>')) //
                || //
                (isCR(nextThreeBytes[0]) && isLF(nextThreeBytes[1])
                        && (nextThreeBytes[2] == '/' || nextThreeBytes[2] == '>')) //
        )
        {
            return 0;
        }
        return bracesParameter;
    }
@Test
    void testCheckForEndOfString() throws IOException
    {
        // (Test)
        byte[] inputBytes = { 40, 84, 101, 115, 116, 41 };

        RandomAccessReadBuffer buffer = new RandomAccessReadBuffer(inputBytes);
        BaseParser baseParser = new COSParser(buffer);
        COSString cosString = baseParser.parseCOSString();
        assertEquals("Test", cosString.getString());

        String output = "(Test";
        // ((Test) + LF + "/ "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 10, '/', ' ' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());

        // ((Test) + CR + "/ "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 13, '/', ' ' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());

        // ((Test) + CR + LF + "/ "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 13, 10, '/' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());

        // ((Test) + LF + "> "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 10, '>', ' ' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());

        // ((Test) + CR + "> "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 13, '>', ' ' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());

        // ((Test) + CR + LF + "> "
        inputBytes = new byte[] { '(', '(', 'T', 'e', 's', 't', ')', 13, 10, '>' };

        buffer = new RandomAccessReadBuffer(inputBytes);
        baseParser = new COSParser(buffer);
        cosString = baseParser.parseCOSString();
        assertEquals(output, cosString.getString());
    }