class StreamPartReader {

    public static String readPart(Reader reader, char openingChar, char closingChar) throws IOException {
        StringBuilder part = new StringBuilder(PART_BUFFER_SIZE);

        int characterCode = reader.read();
        int pairCounter = 0;
        char character;
        boolean read = false;
        while (characterCode != -1) {
            character = (char) characterCode;
            if (character == openingChar) {
                read = true;
                pairCounter++;
            }

            if (read) {
                part.append(character);
            }

            if (character == closingChar) {
                pairCounter--;
                if (pairCounter == 0) {
                    break;
                }
            }

            characterCode = reader.read();
        }

        if (pairCounter != 0) {
            throw new IllegalStateException("Stream ended but no ending char found! Possibly because of dangling opening char.");
        }

        return part.toString();
    }

    private  StreamPartReader();

}