private List readLines()

in doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java [118:157]


    private List<String> readLines(String snippetId) throws IOException {
        BufferedReader reader;
        if (encoding == null || "".equals(encoding)) {
            reader = new BufferedReader(new InputStreamReader(source.openStream()));
        } else {
            reader = new BufferedReader(new InputStreamReader(source.openStream(), encoding));
        }

        List<String> lines = new ArrayList<>();
        try (BufferedReader withReader = reader) {
            boolean capture = false;
            String line;
            boolean foundStart = false;
            boolean foundEnd = false;
            boolean hasSnippetId = snippetId != null && !snippetId.isEmpty();
            while ((line = withReader.readLine()) != null) {
                if (!hasSnippetId) {
                    lines.add(line);
                } else {
                    if (isStart(snippetId, line)) {
                        capture = true;
                        foundStart = true;
                    } else if (isEnd(snippetId, line)) {
                        foundEnd = true;
                        break;
                    } else if (capture) {
                        lines.add(line);
                    }
                }
            }

            if (hasSnippetId && !foundStart) {
                throw new IOException("Failed to find START of snippet " + snippetId + " in file at URL: " + source);
            }
            if (hasSnippetId && !foundEnd) {
                throw new IOException("Failed to find END of snippet " + snippetId + " in file at URL: " + source);
            }
        }
        return lines;
    }