1
2
3
4
5 package org.rcfaces.core.internal.util;
6
7 import javax.faces.FacesException;
8
9 import org.rcfaces.core.internal.lang.StringAppender;
10
11
12
13
14
15 public class FastWriter {
16 private static final String REVISION = "$Revision: 1.18 $";
17
18 protected final StringAppender sa;
19
20 private boolean closed = false;
21
22
23
24
25 public FastWriter() {
26 sa = new StringAppender();
27 }
28
29 public FastWriter(int initialSize) {
30 sa = new StringAppender(initialSize);
31 }
32
33 public final FastWriter write(char c) {
34 if (closed) {
35 throw new FacesException("Writer is closed !");
36 }
37 sa.append(c);
38
39 return this;
40 }
41
42 public final FastWriter write(String str) {
43 if (closed) {
44 throw new FacesException("Writer is closed !");
45 }
46
47 sa.append(str);
48
49 return this;
50 }
51
52 public final String getBuffer() {
53 return sa.toString();
54 }
55
56 public final int getSize() {
57 return sa.length();
58 }
59
60 public final FastWriter ensure(int length) {
61 if (closed) {
62 throw new FacesException("Writer is closed !");
63 }
64
65 sa.ensure(length);
66
67 return this;
68 }
69
70 protected void close() {
71 this.closed = true;
72 }
73 }