BufferedWriter.java revision 2362
2362N/A * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Writes text to a character-output stream, buffering characters so as to 0N/A * provide for the efficient writing of single characters, arrays, and strings. 0N/A * <p> The buffer size may be specified, or the default size may be accepted. 0N/A * The default is large enough for most purposes. 0N/A * <p> A newLine() method is provided, which uses the platform's own notion of 0N/A * line separator as defined by the system property <tt>line.separator</tt>. 0N/A * Not all platforms use the newline character ('\n') to terminate lines. 0N/A * Calling this method to terminate each output line is therefore preferred to 0N/A * writing a newline character directly. 0N/A * <p> In general, a Writer sends its output immediately to the underlying 0N/A * character or byte stream. Unless prompt output is required, it is advisable 0N/A * to wrap a BufferedWriter around any Writer whose write() operations may be 0N/A * costly, such as FileWriters and OutputStreamWriters. For example, 0N/A * = new PrintWriter(new BufferedWriter(new FileWriter("foo.out"))); 0N/A * will buffer the PrintWriter's output to the file. Without buffering, each 0N/A * invocation of a print() method would cause characters to be converted into 0N/A * bytes that would then be written immediately to the file, which can be very 0N/A * @see OutputStreamWriter 0N/A * @author Mark Reinhold 0N/A * Line separator string. This is the value of the line.separator 0N/A * property at the moment that the stream was created. 0N/A * Creates a buffered character-output stream that uses a default-sized 0N/A * @param out A Writer 0N/A * Creates a new buffered character-output stream that uses an output 0N/A * buffer of the given size. 0N/A * @param out A Writer 0N/A * @param sz Output-buffer size, a positive integer 0N/A * @exception IllegalArgumentException If sz is <= 0 0N/A /** Checks to make sure that the stream has not been closed */ 0N/A * Flushes the output buffer to the underlying character stream, without 0N/A * flushing the stream itself. This method is non-private only so that it 0N/A * may be invoked by PrintStream. 0N/A * Writes a single character. 0N/A * @exception IOException If an I/O error occurs 0N/A * Our own little min method, to avoid loading java.lang.Math if we've run 0N/A * out of file descriptors and we're trying to print a stack trace. 0N/A private int min(
int a,
int b) {
0N/A if (a < b)
return a;
0N/A * Writes a portion of an array of characters. 0N/A * <p> Ordinarily this method stores characters from the given array into 0N/A * this stream's buffer, flushing the buffer to the underlying stream as 0N/A * needed. If the requested length is at least as large as the buffer, 0N/A * however, then this method will flush the buffer and write the characters 0N/A * directly to the underlying stream. Thus redundant 0N/A * <code>BufferedWriter</code>s will not copy data unnecessarily. 0N/A * @param cbuf A character array 0N/A * @param off Offset from which to start reading characters 0N/A * @param len Number of characters to write 0N/A * @exception IOException If an I/O error occurs 0N/A /* If the request length exceeds the size of the output buffer, 0N/A flush the buffer and then write the data directly. In this 0N/A way buffered streams will cascade harmlessly. */ 0N/A * Writes a portion of a String. 0N/A * <p> If the value of the <tt>len</tt> parameter is negative then no 0N/A * characters are written. This is contrary to the specification of this 0N/A * method in the {@linkplain java.io.Writer#write(java.lang.String,int,int) 0N/A * superclass}, which requires that an {@link IndexOutOfBoundsException} be 0N/A * @param s String to be written 0N/A * @param off Offset from which to start reading characters 0N/A * @param len Number of characters to be written 0N/A * @exception IOException If an I/O error occurs 0N/A * Writes a line separator. The line separator string is defined by the 0N/A * system property <tt>line.separator</tt>, and is not necessarily a single 0N/A * newline ('\n') character. 0N/A * @exception IOException If an I/O error occurs 0N/A * Flushes the stream. 0N/A * @exception IOException If an I/O error occurs