This page was generated using Webiyo. See its source code and unit tests.
|
org/webiyo/examples/sourceforge/ChangeLogReader.javapackage org.webiyo.examples.sourceforge; import java.io.*; import java.util.ArrayList; import java.util.List; class ChangeLogReader extends BufferedReader { public static final String ENTRY_SEPARATOR = "----------------------------"; public static final String FILE_SEPARATOR = "============================================================================="; private String currentLine = ""; private boolean endOfEntry = true; public ChangeLogReader(String cvsLogOutput) { super(new StringReader(cvsLogOutput)); } public ChangeLogReader(InputStream inputStream) { super(new InputStreamReader(inputStream)); } public String readLine() throws IOException { currentLine = super.readLine(); if (currentLine == null) { endOfEntry = true; return null; } else if (currentLine.equals(FILE_SEPARATOR)) { endOfEntry = true; return null; } else if (currentLine.equals(ENTRY_SEPARATOR)) { endOfEntry = true; return null; } else { endOfEntry = false; return currentLine; } } public List<LogEntry> readAll() throws IOException { List<LogEntry> items = new ArrayList<LogEntry>(); while (true) { LogEntry entry = readItem(); if (entry == null) break; items.add(entry); } return items; } public LogEntry readItem() throws IOException { if (!ENTRY_SEPARATOR.equals(currentLine)) { skipHeader(); } readLine(); if (endOfEntry) return null; String fields = readLine(); if (endOfEntry) return null; StringBuilder comment = new StringBuilder(); while (true) { String line = readLine(); if (endOfEntry) break; comment.append(line + "\n"); } return new LogEntry(fields, comment.toString()); } // end of public methods private void skipHeader() throws IOException { while (true) { readLine(); if (endOfEntry) return; } } } |