01: /*
02: * Copyright 2003 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package velosurf.util;
18:
19: /**
20: * Bufferize chars written on the wrapped writer into lines.
21: *
22: * @author <a href=mailto:claude.brisson@gmail.com>Claude Brisson</a>
23: *
24: */
25:
26: import java.io.IOException;
27: import java.io.OutputStream;
28: import java.io.Writer;
29:
30: public class LineWriterOutputStream extends OutputStream {
31:
32: /** writer */
33: private Writer writer = null;
34: /** buffer */
35: private StringBuffer buffer = new StringBuffer(200);
36:
37: /**
38: * Construct a new LineWriterOutputStream, bound to the specified writer.
39: *
40: * @param w the writer
41: */
42: public LineWriterOutputStream(Writer w) {
43: writer = w;
44: }
45:
46: /**
47: * Write a byte to this output stream.
48: * @param c byte
49: * @exception IOException may be thrown
50: */
51: public void write(int c) throws IOException {
52: if (c == '\n') {
53: writer.write(buffer.toString());
54: buffer.delete(0, buffer.length());
55: } else
56: buffer.append((char) c);
57: }
58: }
|