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