1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.util;
20
21 import java.io.IOException;
22 import java.io.Writer;
23
24
25
26
27
28
29
30
31 public final class FastWriter extends Writer
32 {
33
34 private char[] buff;
35 private int size;
36
37 public FastWriter()
38 {
39 this(1024);
40 }
41
42 public FastWriter(int initialSize)
43 {
44 if (initialSize < 0)
45 {
46 throw new IllegalArgumentException("Initial Size cannot be less than 0");
47 }
48 this.buff = new char[initialSize];
49 }
50
51 public void close() throws IOException
52 {
53
54 }
55
56 public void flush() throws IOException
57 {
58
59 }
60
61 private final void overflow(int len)
62 {
63 if (this.size + len > this.buff.length)
64 {
65 char[] next = new char[(this.size + len) * 2];
66 System.arraycopy(this.buff, 0, next, 0, this.size);
67 this.buff = next;
68 }
69 }
70
71 public void write(char[] cbuf, int off, int len) throws IOException
72 {
73 overflow(len);
74 System.arraycopy(cbuf, off, this.buff, this.size, len);
75 this.size += len;
76 }
77
78 public void write(char[] cbuf) throws IOException
79 {
80 this.write(cbuf, 0, cbuf.length);
81 }
82
83 public void write(int c) throws IOException
84 {
85 this.overflow(1);
86 this.buff[this.size] = (char) c;
87 this.size++;
88 }
89
90 public void write(String str, int off, int len) throws IOException
91 {
92 overflow(len);
93 str.getChars(off, off+len, this.buff, size);
94 this.size += len;
95 }
96
97 public void write(String str) throws IOException
98 {
99 this.write(str, 0, str.length());
100 }
101
102 public void reset()
103 {
104 this.size = 0;
105 }
106
107 public String toString()
108 {
109 return new String(this.buff, 0, this.size);
110 }
111 }