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(LoggerContext loggerContext,
OutputStream os,
String streamName,
boolean createOnDemand,
Layout<? extends Serializable> layout,
boolean writeHeader,
ByteBuffer byteBuffer) |
protected |
OutputStreamManager(OutputStream os,
String streamName,
Layout<?> layout,
boolean writeHeader) |
protected |
OutputStreamManager(OutputStream os,
String streamName,
Layout<?> layout,
boolean writeHeader,
ByteBuffer byteBuffer)
Deprecated.
|
protected |
OutputStreamManager(OutputStream os,
String streamName,
Layout<?> layout,
boolean writeHeader,
int bufferSize) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
closeOutputStream() |
protected OutputStream |
createOutputStream() |
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 |
hasOutputStream() |
boolean |
isOpen()
Returns the status of the stream.
|
boolean |
releaseSub(long timeout,
TimeUnit timeUnit)
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.
|
void |
writeBytes(byte[] data,
int offset,
int length)
Writes the given data to this ByteBufferDestination.
|
void |
writeBytes(ByteBuffer data)
Writes the given data to this ByteBufferDestination entirely.
|
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.
|
close, getContentFormat, getCount, getLoggerContext, getName, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop, updateData
protected ByteBuffer byteBuffer
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader)
protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, int bufferSize)
@Deprecated protected OutputStreamManager(OutputStream os, String streamName, Layout<?> layout, boolean writeHeader, ByteBuffer byteBuffer)
protected OutputStreamManager(LoggerContext loggerContext, OutputStream os, String streamName, boolean createOnDemand, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer 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.protected OutputStream createOutputStream() throws IOException
IOException
public void skipFooter(boolean skipFooter)
skipFooter
- true if the footer should be skipped.public boolean releaseSub(long timeout, TimeUnit timeUnit)
releaseSub
in class AbstractManager
timeout
- timeouttimeUnit
- timeout time unitprotected void writeFooter()
public boolean isOpen()
public boolean hasOutputStream()
protected OutputStream getOutputStream() throws IOException
IOException
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.public void writeBytes(byte[] data, int offset, int length)
ByteBufferDestination
This method should behave identically to writeBytes(ByteBuffer.wrap(data, offset, length)
.
It is provided to allow callers not to generate extra garbage.
This method is called writeBytes() to avoid clashing with write(byte[], int, int)
,
which might be overridden in user-defined subclasses as protected, hence adding it to interface and requiring
the method to be public breaks source compatibility.
writeBytes
in interface ByteBufferDestination
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 boolean closeOutputStream()
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 destinationpublic void writeBytes(ByteBuffer data)
ByteBufferDestination
writeBytes
in interface ByteBufferDestination
Copyright © 1999-2021 The 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.