1 19 20 package org.netbeans.modules.subversion.ui.blame; 21 22 import java.io.Reader ; 23 import java.io.IOException ; 24 import java.util.List ; 25 26 32 public final class LinesReader extends Reader { 33 34 private List lines; 35 private int lineIndex; 36 private int columnIndex; 37 private boolean closed; 38 39 42 LinesReader(List lines) { 43 this.lines = lines; 44 } 45 46 public void close() throws IOException { 47 if (closed) throw new IOException ("Closed"); closed = true; 49 } 50 51 public int read(char cbuf[], int off, int len) throws IOException { 52 if (closed) throw new IOException ("Closed"); 54 if (lineIndex >= lines.size()) return -1; 55 56 AnnotateLine aline = (AnnotateLine) lines.get(lineIndex); 57 String line = aline.getContent() + "\n"; int lineLen = line.length(); 59 int unread = lineLen - columnIndex; 60 int toRead = Math.min(unread, len); 61 line.getChars(columnIndex, columnIndex + toRead, cbuf, off); 62 columnIndex += toRead; 63 if (columnIndex >= lineLen) { 64 columnIndex = 0; 65 lineIndex++; 66 } 67 return toRead; 68 } 69 } 70 | Popular Tags |