/** {@inheritDoc} Setting a writer will replace any target output stream. */ public void setWriter(final Writer writer) { synchronized (outputLock) { super.setWriter(writer); final OutputStream oldStream = this.outputStream; outputStream = null; safeFlush(oldStream); safeClose(oldStream); } }
/** * Close this logger. * * @throws SecurityException if the caller does not have sufficient permission */ public void close() throws SecurityException { checkAccess(this); setWriter(null); super.close(); }
/** * Set the target encoding. * * @param encoding the new encoding * @throws SecurityException if you do not have sufficient permission to invoke this operation * @throws java.io.UnsupportedEncodingException if the specified encoding is not supported */ public void setEncoding(final String encoding) throws SecurityException, UnsupportedEncodingException { // superclass checks access synchronized (outputLock) { charset = encoding == null ? null : Charset.forName(encoding); super.setEncoding(encoding); // we only want to change the writer, not the output stream final OutputStream outputStream = this.outputStream; if (outputStream != null) { super.setWriter(getNewWriter(outputStream)); } } }
try { this.outputStream = outputStream; super.setWriter(writer); } finally { safeFlush(oldStream);