MCPcopy Create free account
hub / github.com/davidgiven/luje / BufferedWriter

Class BufferedWriter

lib/java/io/BufferedWriter.java:39–319  ·  view source on GitHub ↗

Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is minimized, since most (smaller) requests can be satisfied by accessing the buffer alone. The drawback is that some extra space is required to hold the buffer and that copying takes p

Source from the content-addressed store, hash-verified

37 * @see BufferedReader
38 */
39public class BufferedWriter extends Writer {
40
41 private Writer out;
42
43 private char buf[];
44
45 private int pos;
46
47// private final String lineSeparator = AccessController
48// .doPrivileged(new PriviAction<String>("line.separator")); //$NON-NLS-1$
49 private final String lineSeparator = "\n";
50
51 /**
52 * Constructs a new {@code BufferedWriter} with {@code out} as the writer
53 * for which to buffer write operations. The buffer size is set to the
54 * default value of 8 KB.
55 *
56 * @param out
57 * the writer for which character writing is buffered.
58 */
59 public BufferedWriter(Writer out) {
60 super(out);
61 this.out = out;
62 buf = new char[8192];
63 }
64
65 /**
66 * Constructs a new {@code BufferedWriter} with {@code out} as the writer
67 * for which to buffer write operations. The buffer size is set to {@code
68 * size}.
69 *
70 * @param out
71 * the writer for which character writing is buffered.
72 * @param size
73 * the size of the buffer in bytes.
74 * @throws IllegalArgumentException
75 * if {@code size <= 0}.
76 */
77 public BufferedWriter(Writer out, int size) {
78 super(out);
79 if (size <= 0) {
80 throw new IllegalArgumentException(Messages.getString("luni.A3")); //$NON-NLS-1$
81 }
82 this.out = out;
83 this.buf = new char[size];
84 }
85
86 /**
87 * Closes this writer. The contents of the buffer are flushed, the target
88 * writer is closed, and the buffer is released. Only the first invocation
89 * of close has any effect.
90 *
91 * @throws IOException
92 * if an error occurs while closing this writer.
93 */
94 @Override
95 public void close() throws IOException {
96 synchronized (lock) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected