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