1 // BufferedWriter.java - Filtered character output stream.
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date September 25, 1998
18 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
19 * "The Java Language Specification", ISBN 0-201-63451-1
20 * Status: Complete to version 1.1.
23 // Why not extend FilterWriter?
24 public class BufferedWriter extends Writer
26 public BufferedWriter (Writer out)
31 public BufferedWriter (Writer ox, int size)
35 buffer = new char[size];
39 public void close () throws IOException
45 public void flush () throws IOException
51 public void newLine () throws IOException
53 write (System.getProperty("line.separator"));
56 public void write (int oneChar) throws IOException
60 buffer[count++] = (char) oneChar;
61 if (count == buffer.length)
66 public void write (char[] buf, int offset, int len) throws IOException
68 if (offset < 0 || len < 0 || offset + len > buf.length)
69 throw new ArrayIndexOutOfBoundsException ();
73 // Bypass buffering if there is too much incoming data.
74 if (count + len > buffer.length)
77 out.write(buf, offset, len);
81 System.arraycopy(buf, offset, buffer, count, len);
83 if (count == buffer.length)
89 public void write (String str, int offset, int len) throws IOException
91 if (offset < 0 || len < 0 || offset + len < str.length())
92 throw new ArrayIndexOutOfBoundsException ();
96 if (count + len > buffer.length)
99 out.write(str, offset, len);
103 str.getChars(offset, offset + len, buffer, count);
105 if (count == buffer.length)
111 private final void localFlush () throws IOException
117 out.write(buffer, 0, count);
123 // The downstream writer.
125 // The character buffer.
127 // Number of valid chars in buffer.