/** * Constructs a new {@code BufferedWriter} with {@code outj} as the writer * for which to buffer write operations. The buffer size is set to {@code * size}. * * @param outj * the writer for which character writing is buffered. * @param size * the size of the buffer in bytes. * @throws IllegalArgumentException * if {@code size <= 0}. */ public BufferedWriter(Writer outj, int size) : base(outj) { if (size <= 0) { throw new java.lang.IllegalArgumentException("size must be > 0"); //$NON-NLS-1$ } this.outj = outj; this.buf = new char[size]; }
/** * Closes this print writer. Flushes this writer and then closes the target. * If an I/O error occurs, this writer's error flag is set to {@code true}. */ public override void close() { lock (lockJ) { if (outJ != null) { try { outJ.close(); } catch (IOException e) { setError(); } outJ = null; } } }
/** * Constructs a new {@code PrintWriter} with {@code out} as its target * writer. The parameter {@code autoflush} determines if the print writer * automatically flushes its contents to the target writer when a newline is * encountered. * * @param wr * the target writer. * @param autoflush * indicates whether to flush contents upon encountering a * newline sequence. * @throws NullPointerException * if {@code out} is {@code null}. */ public PrintWriter(Writer wr, bool autoflush) : base(wr) { this.autoflush = autoflush; outJ = wr; }
/** * Constructs a new {@code PrintWriter} with {@code wr} as its target * writer. By default, the new print writer does not automatically flush its * contents to the target writer when a newline is encountered. * * @param wr * the target writer. * @throws NullPointerException * if {@code wr} is {@code null}. */ public PrintWriter(Writer wr) : this(wr, false) { }
/** * Constructs a new {@code BufferedWriter} with {@code outj} as the writer * for which to buffer write operations. The buffer size is set to the * default value of 8 KB. * * @param outj * the writer for which character writing is buffered. */ public BufferedWriter(Writer outj) : base(outj) { this.outj = outj; buf = new char[8192]; }
/** * Closes this writer. The contents of the buffer are flushed, the target * writer is closed, and the buffer is released. Only the first invocation * of close has any effect. * * @throws IOException * if an error occurs while closing this writer. */ public override void close() { //throws IOException { lock (lockJ) { if (isClosed()) { return; } java.lang.Throwable thrown = null; try { flushInternal(); } catch (java.lang.Throwable e) { thrown = e; } buf = null; try { outj.close(); } catch (java.lang.Throwable e) { if (thrown == null) { thrown = e; } } outj = null; if (thrown != null) { throw thrown; } } }