java.io

Class BufferedWriter

Implemented Interfaces:
Appendable, Closeable, Flushable

public class BufferedWriter
extends Writer

This class accumulates chars written in a buffer instead of immediately writing the data to the underlying output sink. The chars are instead as one large block when the buffer is filled, or when the stream is closed or explicitly flushed. This mode operation can provide a more efficient mechanism for writing versus doing numerous small unbuffered writes.

Field Summary

Fields inherited from class java.io.Writer

lock

Constructor Summary

BufferedWriter(Writer out)
This method initializes a new BufferedWriter instance that will write to the specified subordinate Writer and which will use a default buffer size of 8192 chars.
BufferedWriter(Writer out, int size)
This method initializes a new BufferedWriter instance that will write to the specified subordinate Writer and which will use the specified buffer size

Method Summary

void
close()
This method flushes any remaining buffered chars then closes the underlying output stream.
void
flush()
This method causes any currently buffered chars to be immediately written to the underlying output stream.
void
newLine()
This method writes out a system depedent line separator sequence.
void
write(char[] buf, int offset, int len)
This method writes len chars from the char array buf starting at position offset in the buffer.
void
write(int oneChar)
This method writes a single char of data.
void
write(String str, int offset, int len)
This method writes len chars from the String str starting at position offset in the string.

Methods inherited from class java.io.Writer

append, append, append, close, flush, write, write, write, write, write

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BufferedWriter

public BufferedWriter(Writer out)
This method initializes a new BufferedWriter instance that will write to the specified subordinate Writer and which will use a default buffer size of 8192 chars.
Parameters:
out - The underlying Writer to write data to

BufferedWriter

public BufferedWriter(Writer out,
                      int size)
This method initializes a new BufferedWriter instance that will write to the specified subordinate Writer and which will use the specified buffer size
Parameters:
out - The underlying Writer to write data to
size - The size of the internal buffer

Method Details

close

public void close()
            throws IOException
This method flushes any remaining buffered chars then closes the underlying output stream. Any further attempts to write to this stream may throw an exception
Specified by:
close in interface Closeable
Overrides:
close in interface Writer
Throws:
IOException - If an error occurs.

flush

public void flush()
            throws IOException
This method causes any currently buffered chars to be immediately written to the underlying output stream.
Specified by:
flush in interface Flushable
Overrides:
flush in interface Writer
Throws:
IOException - If an error occurs

newLine

public void newLine()
            throws IOException
This method writes out a system depedent line separator sequence. The actual value written is detemined from the line.separator system property.
Throws:
IOException - If an error occurs

write

public void write(char[] buf,
                  int offset,
                  int len)
            throws IOException
This method writes len chars from the char array buf starting at position offset in the buffer. These chars will be written to the internal buffer. However, if this write operation fills the buffer, the buffer will be flushed to the underlying output stream.
Overrides:
write in interface Writer
Parameters:
buf - The array of chars to write.
offset - The index into the char array to start writing from.
len - The number of chars to write.
Throws:
IOException - If an error occurs

write

public void write(int oneChar)
            throws IOException
This method writes a single char of data. This will be written to the buffer instead of the underlying data source. However, if the buffer is filled as a result of this write request, it will be flushed to the underlying output stream.
Overrides:
write in interface Writer
Parameters:
oneChar - The char of data to be written, passed as an int
Throws:
IOException - If an error occurs

write

public void write(String str,
                  int offset,
                  int len)
            throws IOException
This method writes len chars from the String str starting at position offset in the string. These chars will be written to the internal buffer. However, if this write operation fills the buffer, the buffer will be flushed to the underlying output stream.
Overrides:
write in interface Writer
Parameters:
str - The String to write.
offset - The index into the string to start writing from.
len - The number of chars to write.
Throws:
IOException - If an error occurs

BufferedWriter.java -- Buffer output into large blocks before writing Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.