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
32 public final class FastWriter extends Writer
33 {
34
35 private char[] buff;
36 private int size;
37
38 public FastWriter()
39 {
40 this(1024);
41 }
42
43 public FastWriter(int initialSize)
44 {
45 if (initialSize < 0)
46 {
47 throw new IllegalArgumentException("Initial Size cannot be less than 0");
48 }
49 this.buff = new char[initialSize];
50 }
51
52 public void close() throws IOException
53 {
54
55 }
56
57 public void flush() throws IOException
58 {
59
60 }
61
62 private final void overflow(int len)
63 {
64 if (this.size + len > this.buff.length)
65 {
66 char[] next = new char[(this.size + len) * 2];
67 System.arraycopy(this.buff, 0, next, 0, this.size);
68 this.buff = next;
69 }
70 }
71
72 public void write(char[] cbuf, int off, int len) throws IOException
73 {
74 overflow(len);
75 System.arraycopy(cbuf, off, this.buff, this.size, len);
76 this.size += len;
77 }
78
79 public void write(char[] cbuf) throws IOException
80 {
81 this.write(cbuf, 0, cbuf.length);
82 }
83
84 public void write(int c) throws IOException
85 {
86 this.overflow(1);
87 this.buff[this.size] = (char) c;
88 this.size++;
89 }
90
91 public void write(String str, int off, int len) throws IOException
92 {
93 this.write(str.toCharArray(), off, len);
94 }
95
96 public void write(String str) throws IOException
97 {
98 this.write(str.toCharArray(), 0, str.length());
99 }
100
101 public void reset()
102 {
103 this.size = 0;
104 }
105
106 public String toString()
107 {
108 return new String(this.buff, 0, this.size);
109 }
110 }