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