1 19 20 package org.netbeans.modules.java.source.engine; 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 import java.io.StringWriter ; 25 import javax.swing.text.BadLocationException ; 26 27 30 public class StringSourceRewriter implements SourceRewriter { 31 PrintWriter out; 32 StringWriter sout; 33 34 public StringSourceRewriter() { 35 sout = new StringWriter (); 36 out = new PrintWriter (sout); 37 } 38 39 public void writeTo(String s) throws IOException , BadLocationException { 40 out.print(s); 41 } 42 43 public void skipThrough(SourceReader in, int offset) throws IOException , BadLocationException { 44 in.seek(offset); 45 } 46 47 public void copyTo(SourceReader in, int offset) throws IOException { 48 char[] buf = in.getCharsTo(offset); 49 out.write(buf); 50 } 51 52 public void copyRest(SourceReader in) throws IOException { 53 char[] buf = new char[4096]; 54 int i; 55 while ((i = in.read(buf)) > 0) 56 out.write(buf, 0, i); 57 } 58 59 public void close(boolean save) throws IOException { 60 out.flush(); 61 } 62 63 66 public String toString() { 67 return sout.toString(); 68 } 69 } 70 | Popular Tags |