1 18 19 package org.objectweb.jac.util; 20 21 import java.io.FilterWriter ; 22 import java.io.Writer ; 23 import java.io.IOException ; 24 25 30 31 public class LineNumberWriter extends FilterWriter 32 { 33 int last = -1; 35 int lines = 1; 36 37 public LineNumberWriter(Writer out) { 38 super(out); 39 } 40 41 public void write(int b) throws IOException { 42 if ( (b == '\r' && last != '\n') || 43 (b=='\n') ) { 44 lines++; 45 } 46 out.write(b); 47 last = b; 48 } 49 50 public void write(char[] b, int off, int len) throws IOException 51 { 52 while (len-- > 0) { 53 write(b[off++]); 54 } 55 } 56 57 public void write(String str, int off, int len) throws IOException 58 { 59 while (len-- > 0) { 60 write(str.charAt(off++)); 61 } 62 } 63 64 67 public int getLines() { 68 return lines; 69 } 70 } 71 72 | Popular Tags |