1
/* Copyright 2002-2005 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
23
import java.io.IOException;
24
import java.io.Writer;
26
final class UnsynchronizedBufferedWriter extends Writer {
28
private final static int CAPACITY = 8192;
29
private char[] buffer = new char[CAPACITY];
30
private int position = 0;
34
public UnsynchronizedBufferedWriter(Writer out) {
39
public void write(char[] buffer, int offset, int length) throws IOException {
40
throw new UnsupportedOperationException("XOM bug: this statement shouldn't be reachable.");
44
public void write(String s) throws IOException {
45
write(s, 0, s.length());
49
public void write(String s, int offset, int length) throws IOException {
52
int n = Math.min(CAPACITY - position, length);
53
s.getChars(offset, offset + n, buffer, position);
57
if (position >= CAPACITY) flushInternal();
63
public void write(int c) throws IOException {
64
if (position >= CAPACITY) flushInternal();
65
buffer[position] = (char) c;
70
public void flush() throws IOException {
76
private void flushInternal() throws IOException {
78
out.write(buffer, 0, position);
84
public void close() throws IOException {
85
throw new UnsupportedOperationException("How;d we get here?");