1 14 15 package com.sun.facelets.util; 16 17 import java.io.IOException ; 18 import java.io.Writer ; 19 20 24 public final class FastWriter extends Writer { 25 26 private char[] buff; 27 private int size; 28 29 public FastWriter() { 30 this(1024); 31 } 32 33 public FastWriter(int initialSize) { 34 if (initialSize < 0) { 35 throw new IllegalArgumentException ("Initial Size cannot be less than 0"); 36 } 37 this.buff = new char[initialSize]; 38 } 39 40 public void close() throws IOException { 41 } 43 44 public void flush() throws IOException { 45 } 47 48 private final void overflow(int len) { 49 if (this.size + len > this.buff.length) { 50 char[] next = new char[(this.size + len) * 2]; 51 System.arraycopy(this.buff, 0, next, 0, this.size); 52 this.buff = next; 53 } 54 } 55 56 public void write(char[] cbuf, int off, int len) throws IOException { 57 overflow(len); 58 System.arraycopy(cbuf, off, this.buff, this.size, len); 59 this.size += len; 60 } 61 62 public void write(char[] cbuf) throws IOException { 63 this.write(cbuf, 0, cbuf.length); 64 } 65 66 public void write(int c) throws IOException { 67 this.overflow(1); 68 this.buff[this.size] = (char) c; 69 this.size++; 70 } 71 72 public void write(String str, int off, int len) throws IOException { 73 this.write(str.toCharArray(), off, len); 74 } 75 76 public void write(String str) throws IOException { 77 this.write(str.toCharArray(), 0, str.length()); 78 } 79 80 public void reset() { 81 this.size = 0; 82 } 83 84 public String toString() { 85 return new String (this.buff, 0, this.size); 86 } 87 } | Popular Tags |