1 16 package com.google.gwt.dev.util; 17 18 import java.io.CharArrayWriter ; 19 import java.nio.BufferOverflowException ; 20 import java.nio.BufferUnderflowException ; 21 22 25 public class StringCopier { 26 private final CharArrayWriter out = new CharArrayWriter (); 27 private final char[] in; 28 private int inPos = 0; 29 30 public StringCopier(char[] in) { 31 this.in = in; 32 } 33 34 public void commit(char[] replaceWith, int startReplace, int endReplace) { 35 if (startReplace < inPos) { 36 throw new BufferUnderflowException (); 37 } 38 if (endReplace > in.length) { 39 throw new BufferOverflowException (); 40 } 41 42 out.write(in, inPos, startReplace - inPos); 44 45 out.write(replaceWith, 0, replaceWith.length); 47 48 inPos = endReplace; 50 } 51 52 public char[] finish() { 53 out.write(in, inPos, in.length - inPos); 55 inPos = in.length; 56 return out.toCharArray(); 57 } 58 } 59 | Popular Tags |