/** * Writes the specified section of the specified byte array to the stream. * * @param bytes the array containing data * @param offset from where to write * @param length how many bytes to write * @since 2.6 */ protected synchronized void writeToDestination(final byte[] bytes, final int offset, final int length) { try { getOutputStream().write(bytes, offset, length); } catch (final IOException ex) { throw new AppenderLoggingException("Error writing to stream " + getName(), ex); } }
/** * @since 2.6 * @deprecated */ @Deprecated protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout, final boolean writeHeader, final ByteBuffer byteBuffer) { super(null, streamName); this.outputStream = os; this.layout = layout; if (writeHeader && layout != null) { final byte[] header = layout.getHeader(); if (header != null) { try { getOutputStream().write(header, 0, header.length); } catch (final IOException e) { logError("Unable to write header", e); } } } this.byteBuffer = Objects.requireNonNull(byteBuffer, "byteBuffer"); }
/** * @since 2.7 */ protected OutputStreamManager(final LoggerContext loggerContext, final OutputStream os, final String streamName, final boolean createOnDemand, final Layout<? extends Serializable> layout, final boolean writeHeader, final ByteBuffer byteBuffer) { super(loggerContext, streamName); if (createOnDemand && os != null) { LOGGER.error( "Invalid OutputStreamManager configuration for '{}': You cannot both set the OutputStream and request on-demand.", streamName); } this.layout = layout; this.byteBuffer = Objects.requireNonNull(byteBuffer, "byteBuffer"); this.outputStream = os; if (writeHeader && layout != null) { final byte[] header = layout.getHeader(); if (header != null) { try { getOutputStream().write(header, 0, header.length); } catch (final IOException e) { logError("Unable to write header for " + streamName, e); } } } }