|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| package nu.xom; |
|
22 |
| |
|
23 |
| import java.io.IOException; |
|
24 |
| import java.io.Writer; |
|
25 |
| |
|
26 |
| final class UnsynchronizedBufferedWriter extends Writer { |
|
27 |
| |
|
28 |
| private final static int CAPACITY = 8192; |
|
29 |
| private char[] buffer = new char[CAPACITY]; |
|
30 |
| private int position = 0; |
|
31 |
| private Writer out; |
|
32 |
| |
|
33 |
| |
|
34 |
19228
| public UnsynchronizedBufferedWriter(Writer out) {
|
|
35 |
19228
| this.out = out;
|
|
36 |
| } |
|
37 |
| |
|
38 |
| |
|
39 |
0
| public void write(char[] buffer, int offset, int length) throws IOException {
|
|
40 |
0
| throw new UnsupportedOperationException("XOM bug: this statement shouldn't be reachable.");
|
|
41 |
| } |
|
42 |
| |
|
43 |
| |
|
44 |
2803384
| public void write(String s) throws IOException {
|
|
45 |
2803384
| write(s, 0, s.length());
|
|
46 |
| } |
|
47 |
| |
|
48 |
| |
|
49 |
2803384
| public void write(String s, int offset, int length) throws IOException {
|
|
50 |
| |
|
51 |
2803384
| while (length > 0) {
|
|
52 |
2767044
| int n = Math.min(CAPACITY - position, length);
|
|
53 |
2767044
| s.getChars(offset, offset + n, buffer, position);
|
|
54 |
2767044
| position += n;
|
|
55 |
2767044
| offset += n;
|
|
56 |
2767044
| length -= n;
|
|
57 |
1854
| if (position >= CAPACITY) flushInternal();
|
|
58 |
| } |
|
59 |
| |
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
30625142
| public void write(int c) throws IOException {
|
|
64 |
3203
| if (position >= CAPACITY) flushInternal();
|
|
65 |
30625142
| buffer[position] = (char) c;
|
|
66 |
30625142
| position++;
|
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
37703
| public void flush() throws IOException {
|
|
71 |
37703
| flushInternal();
|
|
72 |
37703
| out.flush();
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
42760
| private void flushInternal() throws IOException {
|
|
77 |
42760
| if (position != 0) {
|
|
78 |
24267
| out.write(buffer, 0, position);
|
|
79 |
24267
| position = 0;
|
|
80 |
| } |
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
0
| public void close() throws IOException {
|
|
85 |
0
| throw new UnsupportedOperationException("How;d we get here?");
|
|
86 |
| } |
|
87 |
| |
|
88 |
| } |