01: // (c) copyright 2006 by eXXcellent solutions, Ulm. Author: bschmid
02:
03: package org.wings.io;
04:
05: import java.io.IOException;
06:
07: /**
08: * This device buffers all input in an internal {@link org.wings.util.SStringBuilder}
09: * until {@link Device#flush()} or {@link Device#close()}
10: * is called.
11: */
12: public class CachingDevice implements Device {
13: private final StringBuilderDevice bufferDevice = new StringBuilderDevice(
14: 4096);
15: private final Device finalDevice;
16:
17: public CachingDevice(Device finalDevice) {
18: this .finalDevice = finalDevice;
19: }
20:
21: public String toString() {
22: return bufferDevice.toString();
23: }
24:
25: public boolean isSizePreserving() {
26: return bufferDevice.isSizePreserving();
27: }
28:
29: public void flush() throws IOException {
30: bufferDevice.flush();
31: }
32:
33: public void close() throws IOException {
34: bufferDevice.flush();
35: finalDevice.print(bufferDevice.toString());
36: bufferDevice.close();
37: }
38:
39: public void reset() {
40: bufferDevice.reset();
41: }
42:
43: public Device print(String s) {
44: return bufferDevice.print(s);
45: }
46:
47: public Device print(char c) {
48: return bufferDevice.print(c);
49: }
50:
51: public Device print(char[] c) throws IOException {
52: return bufferDevice.print(c);
53: }
54:
55: public Device print(char[] c, int start, int len)
56: throws IOException {
57: return bufferDevice.print(c, start, len);
58: }
59:
60: public Device print(int i) {
61: return bufferDevice.print(i);
62: }
63:
64: public Device print(Object o) {
65: return bufferDevice.print(o);
66: }
67:
68: public Device write(int c) throws IOException {
69: return bufferDevice.write(c);
70: }
71:
72: public Device write(byte[] b) throws IOException {
73: return bufferDevice.write(b);
74: }
75:
76: public Device write(byte[] b, int off, int len) throws IOException {
77: return bufferDevice.write(b, off, len);
78: }
79: }
|