public class OutputStreamManager extends AbstractManager implements ByteBufferDestination
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
byteBuffer |
protected Layout<?> |
layout |
count, LOGGER
Modifier | Constructor and Description |
---|---|
protected |
OutputStreamManager(OutputStream os,
String streamName,
Layout<?> layout,
boolean writeHeader) |
protected |
OutputStreamManager(OutputStream os,
String streamName,
Layout<?> layout,
boolean writeHeader,
ByteBuffer byteBuffer) |
Modifier and Type | Method and Description |
---|---|
protected void |
close() |
ByteBuffer |
drain(ByteBuffer buf)
Drains the ByteBufferDestination's buffer into the destination.
|
void |
flush()
Flushes any buffers.
|
protected void |
flushBuffer(ByteBuffer buf)
Drains the ByteBufferDestination's buffer into the destination.
|
protected void |
flushDestination()
Calls
flush() on the underlying output stream. |
ByteBuffer |
getByteBuffer()
Returns this
ByteBufferDestination 's buffer. |
static <T> OutputStreamManager |
getManager(String name,
T data,
ManagerFactory<? extends OutputStreamManager,T> factory)
Creates a Manager.
|
protected OutputStream |
getOutputStream() |
boolean |
isOpen()
Returns the status of the stream.
|
void |
releaseSub()
Default hook to write footer during close.
|
protected void |
setOutputStream(OutputStream os) |
void |
skipFooter(boolean skipFooter)
Indicate whether the footer should be skipped or not.
|
protected void |
write(byte[] bytes)
Some output streams synchronize writes while others do not.
|
protected void |
write(byte[] bytes,
boolean immediateFlush)
Some output streams synchronize writes while others do not.
|
protected void |
write(byte[] bytes,
int offset,
int length)
Some output streams synchronize writes while others do not.
|
protected void |
write(byte[] bytes,
int offset,
int length,
boolean immediateFlush)
Some output streams synchronize writes while others do not.
|
protected void |
writeFooter()
Writes the footer.
|
protected void |
writeToDestination(byte[] bytes,
int offset,
int length)
Writes the specified section of the specified byte array to the stream.
|
getContentFormat, getCount, getName, hasManager, log, logDebug, logError, logWarn, release, updateData
protected final Layout<?> layout
protected ByteBuffer byteBuffer
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader)
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, ByteBuffer byteBuffer)
os
- streamName
- layout
- writeHeader
- byteBuffer
- public static <T> OutputStreamManager getManager(String name, T data, ManagerFactory<? extends OutputStreamManager,T> factory)
T
- The type of the OutputStreamManager.name
- The name of the stream to manage.data
- The data to pass to the Manager.factory
- The factory to use to create the Manager.public void skipFooter(boolean skipFooter)
skipFooter
- true if the footer should be skipped.public void releaseSub()
releaseSub
in class AbstractManager
protected void writeFooter()
public boolean isOpen()
protected OutputStream getOutputStream()
protected void setOutputStream(OutputStream os)
protected void write(byte[] bytes)
bytes
- The serialized Log event.AppenderLoggingException
- if an error occurs.protected void write(byte[] bytes, boolean immediateFlush)
bytes
- The serialized Log event.immediateFlush
- If true, flushes after writing.AppenderLoggingException
- if an error occurs.protected void write(byte[] bytes, int offset, int length)
bytes
- The serialized Log event.offset
- The offset into the byte array.length
- The number of bytes to write.AppenderLoggingException
- if an error occurs.protected void write(byte[] bytes, int offset, int length, boolean immediateFlush)
bytes
- The serialized Log event.offset
- The offset into the byte array.length
- The number of bytes to write.immediateFlush
- flushes immediately after writing.AppenderLoggingException
- if an error occurs.protected void writeToDestination(byte[] bytes, int offset, int length)
bytes
- the array containing dataoffset
- from where to writelength
- how many bytes to writeprotected void flushDestination()
flush()
on the underlying output stream.protected void flushBuffer(ByteBuffer buf)
write(byte[], int, int, boolean)
with the buffer contents.
The underlying stream is not flushed.flushDestination()
public void flush()
protected void close()
public ByteBuffer getByteBuffer()
ByteBufferDestination
's buffer.getByteBuffer
in interface ByteBufferDestination
public ByteBuffer drain(ByteBuffer buf)
flushBuffer(ByteBuffer)
with the specified buffer. Subclasses may override.
Do not call this method lightly! For some subclasses this is a very expensive operation. For example,
MemoryMappedFileManager
will assume this method was called because the end of the mapped region
was reached during a text encoding operation and will remap its
buffer.
To just flush the buffered contents to the underlying stream, call
flushBuffer(ByteBuffer)
directly instead.
drain
in interface ByteBufferDestination
buf
- the buffer whose contents to write the the destinationCopyright © 1999-2016 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.