src/share/classes/java/io/BufferedWriter.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  43  * character or byte stream.  Unless prompt output is required, it is advisable
  44  * to wrap a BufferedWriter around any Writer whose write() operations may be
  45  * costly, such as FileWriters and OutputStreamWriters.  For example,
  46  *
  47  * <pre>
  48  * PrintWriter out
  49  *   = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
  50  * </pre>
  51  *
  52  * will buffer the PrintWriter's output to the file.  Without buffering, each
  53  * invocation of a print() method would cause characters to be converted into
  54  * bytes that would then be written immediately to the file, which can be very
  55  * inefficient.
  56  *
  57  * @see PrintWriter
  58  * @see FileWriter
  59  * @see OutputStreamWriter
  60  * @see java.nio.file.Files#newBufferedWriter
  61  *
  62  * @author      Mark Reinhold
  63  * @since       JDK1.1
  64  */
  65 
  66 public class BufferedWriter extends Writer {
  67 
  68     private Writer out;
  69 
  70     private char cb[];
  71     private int nChars, nextChar;
  72 
  73     private static int defaultCharBufferSize = 8192;
  74 
  75     /**
  76      * Line separator string.  This is the value of the line.separator
  77      * property at the moment that the stream was created.
  78      */
  79     private String lineSeparator;
  80 
  81     /**
  82      * Creates a buffered character-output stream that uses a default-sized
  83      * output buffer.




  43  * character or byte stream.  Unless prompt output is required, it is advisable
  44  * to wrap a BufferedWriter around any Writer whose write() operations may be
  45  * costly, such as FileWriters and OutputStreamWriters.  For example,
  46  *
  47  * <pre>
  48  * PrintWriter out
  49  *   = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
  50  * </pre>
  51  *
  52  * will buffer the PrintWriter's output to the file.  Without buffering, each
  53  * invocation of a print() method would cause characters to be converted into
  54  * bytes that would then be written immediately to the file, which can be very
  55  * inefficient.
  56  *
  57  * @see PrintWriter
  58  * @see FileWriter
  59  * @see OutputStreamWriter
  60  * @see java.nio.file.Files#newBufferedWriter
  61  *
  62  * @author      Mark Reinhold
  63  * @since       1.1
  64  */
  65 
  66 public class BufferedWriter extends Writer {
  67 
  68     private Writer out;
  69 
  70     private char cb[];
  71     private int nChars, nextChar;
  72 
  73     private static int defaultCharBufferSize = 8192;
  74 
  75     /**
  76      * Line separator string.  This is the value of the line.separator
  77      * property at the moment that the stream was created.
  78      */
  79     private String lineSeparator;
  80 
  81     /**
  82      * Creates a buffered character-output stream that uses a default-sized
  83      * output buffer.