/** * Flushes any buffers. */ public synchronized void flush() { flushBuffer(byteBuffer); flushDestination(); }
/** * Some output streams synchronize writes while others do not. Synchronizing here insures that * log events won't be intertwined. * @param bytes The serialized Log event. * @param offset The offset into the byte array. * @param length The number of bytes to write. * @param immediateFlush flushes immediately after writing. * @throws AppenderLoggingException if an error occurs. */ protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) { if (immediateFlush && byteBuffer.position() == 0) { writeToDestination(bytes, offset, length); flushDestination(); return; } if (length >= byteBuffer.capacity()) { // if request length exceeds buffer capacity, flush the buffer and write the data directly flush(); writeToDestination(bytes, offset, length); } else { if (length > byteBuffer.remaining()) { flush(); } byteBuffer.put(bytes, offset, length); } if (immediateFlush) { flush(); } }