Class OutputStreamManager

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected OutputStreamManager​(java.io.OutputStream os, java.lang.String streamName, Layout<?> layout, boolean writeHeader)  
      protected OutputStreamManager​(java.io.OutputStream os, java.lang.String streamName, Layout<?> layout, boolean writeHeader, int bufferSize)  
      protected OutputStreamManager​(java.io.OutputStream os, java.lang.String streamName, Layout<?> layout, boolean writeHeader, java.nio.ByteBuffer byteBuffer)
      Deprecated. 
      protected OutputStreamManager​(LoggerContext loggerContext, java.io.OutputStream os, java.lang.String streamName, boolean createOnDemand, Layout<? extends java.io.Serializable> layout, boolean writeHeader, java.nio.ByteBuffer byteBuffer)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean closeOutputStream()  
      protected java.io.OutputStream createOutputStream()  
      java.nio.ByteBuffer drain​(java.nio.ByteBuffer buf)
      Drains the ByteBufferDestination's buffer into the destination.
      void flush()
      Flushes any buffers.
      protected void flushBuffer​(java.nio.ByteBuffer buf)
      Drains the ByteBufferDestination's buffer into the destination.
      protected void flushDestination()
      Calls flush() on the underlying output stream.
      java.nio.ByteBuffer getByteBuffer()
      Returns this ByteBufferDestination's buffer.
      static <T> OutputStreamManager getManager​(java.lang.String name, T data, ManagerFactory<? extends OutputStreamManager,​T> factory)
      Creates a Manager.
      protected java.io.OutputStream getOutputStream()  
      boolean hasOutputStream()  
      boolean isOpen()
      Returns the status of the stream.
      boolean releaseSub​(long timeout, java.util.concurrent.TimeUnit timeUnit)
      Default hook to write footer during close.
      protected void setOutputStream​(java.io.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​(java.nio.ByteBuffer data)
      Writes the given data to this ByteBufferDestination entirely.
      protected void writeFooter()
      Writes the footer.
      protected void writeHeader​(java.io.OutputStream os)  
      protected void writeToDestination​(byte[] bytes, int offset, int length)
      Writes the specified section of the specified byte array to the stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • layout

        protected final Layout<?> layout
      • byteBuffer

        protected java.nio.ByteBuffer byteBuffer
      • outputStream

        private volatile java.io.OutputStream outputStream
      • skipFooter

        private boolean skipFooter
    • Constructor Detail

      • OutputStreamManager

        protected OutputStreamManager​(java.io.OutputStream os,
                                      java.lang.String streamName,
                                      Layout<?> layout,
                                      boolean writeHeader)
      • OutputStreamManager

        protected OutputStreamManager​(java.io.OutputStream os,
                                      java.lang.String streamName,
                                      Layout<?> layout,
                                      boolean writeHeader,
                                      int bufferSize)
      • OutputStreamManager

        @Deprecated
        protected OutputStreamManager​(java.io.OutputStream os,
                                      java.lang.String streamName,
                                      Layout<?> layout,
                                      boolean writeHeader,
                                      java.nio.ByteBuffer byteBuffer)
        Deprecated.
        Since:
        2.6
      • OutputStreamManager

        protected OutputStreamManager​(LoggerContext loggerContext,
                                      java.io.OutputStream os,
                                      java.lang.String streamName,
                                      boolean createOnDemand,
                                      Layout<? extends java.io.Serializable> layout,
                                      boolean writeHeader,
                                      java.nio.ByteBuffer byteBuffer)
        Since:
        2.7
    • Method Detail

      • getManager

        public static <T> OutputStreamManager getManager​(java.lang.String name,
                                                         T data,
                                                         ManagerFactory<? extends OutputStreamManager,​T> factory)
        Creates a Manager.
        Type Parameters:
        T - The type of the OutputStreamManager.
        Parameters:
        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.
        Returns:
        An OutputStreamManager.
      • createOutputStream

        protected java.io.OutputStream createOutputStream()
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • skipFooter

        public void skipFooter​(boolean skipFooter)
        Indicate whether the footer should be skipped or not.
        Parameters:
        skipFooter - true if the footer should be skipped.
      • releaseSub

        public boolean releaseSub​(long timeout,
                                  java.util.concurrent.TimeUnit timeUnit)
        Default hook to write footer during close.
        Overrides:
        releaseSub in class AbstractManager
        Parameters:
        timeout - timeout
        timeUnit - timeout time unit
        Returns:
        true if all resources were closed normally, false otherwise.
      • writeHeader

        protected void writeHeader​(java.io.OutputStream os)
      • writeFooter

        protected void writeFooter()
        Writes the footer.
      • isOpen

        public boolean isOpen()
        Returns the status of the stream.
        Returns:
        true if the stream is open, false if it is not.
      • hasOutputStream

        public boolean hasOutputStream()
      • getOutputStream

        protected java.io.OutputStream getOutputStream()
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • setOutputStream

        protected void setOutputStream​(java.io.OutputStream os)
      • write

        protected void write​(byte[] bytes)
        Some output streams synchronize writes while others do not.
        Parameters:
        bytes - The serialized Log event.
        Throws:
        AppenderLoggingException - if an error occurs.
      • write

        protected void write​(byte[] bytes,
                             boolean immediateFlush)
        Some output streams synchronize writes while others do not.
        Parameters:
        bytes - The serialized Log event.
        immediateFlush - If true, flushes after writing.
        Throws:
        AppenderLoggingException - if an error occurs.
      • writeBytes

        public void writeBytes​(byte[] data,
                               int offset,
                               int length)
        Description copied from interface: ByteBufferDestination
        Writes the given data to this ByteBufferDestination. Call of this method should *not* be protected with synchronized on this ByteBufferDestination instance. ByteBufferDestination implementations should synchronize themselves inside this method, if needed.

        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.

        Specified by:
        writeBytes in interface ByteBufferDestination
      • write

        protected void write​(byte[] bytes,
                             int offset,
                             int length)
        Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.
        Parameters:
        bytes - The serialized Log event.
        offset - The offset into the byte array.
        length - The number of bytes to write.
        Throws:
        AppenderLoggingException - if an error occurs.
      • write

        protected void write​(byte[] bytes,
                             int offset,
                             int length,
                             boolean immediateFlush)
        Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.
        Parameters:
        bytes - The serialized Log event.
        offset - The offset into the byte array.
        length - The number of bytes to write.
        immediateFlush - flushes immediately after writing.
        Throws:
        AppenderLoggingException - if an error occurs.
      • writeToDestination

        protected void writeToDestination​(byte[] bytes,
                                          int offset,
                                          int length)
        Writes the specified section of the specified byte array to the stream.
        Parameters:
        bytes - the array containing data
        offset - from where to write
        length - how many bytes to write
        Since:
        2.6
      • flushDestination

        protected void flushDestination()
        Calls flush() on the underlying output stream.
        Since:
        2.6
      • flushBuffer

        protected void flushBuffer​(java.nio.ByteBuffer buf)
        Drains the ByteBufferDestination's buffer into the destination. By default this calls write(byte[], int, int, boolean) with the buffer contents. The underlying stream is not flushed.
        Since:
        2.6
        See Also:
        flushDestination()
      • flush

        public void flush()
        Flushes any buffers.
      • closeOutputStream

        protected boolean closeOutputStream()
      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer()
        Returns this ByteBufferDestination's buffer.
        Specified by:
        getByteBuffer in interface ByteBufferDestination
        Returns:
        the buffer
        Since:
        2.6
      • drain

        public java.nio.ByteBuffer drain​(java.nio.ByteBuffer buf)
        Drains the ByteBufferDestination's buffer into the destination. By default this calls 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.

        Specified by:
        drain in interface ByteBufferDestination
        Parameters:
        buf - the buffer whose contents to write the the destination
        Returns:
        the specified buffer
        Since:
        2.6
      • writeBytes

        public void writeBytes​(java.nio.ByteBuffer data)
        Description copied from interface: ByteBufferDestination
        Writes the given data to this ByteBufferDestination entirely. Call of this method should *not* be protected with synchronized on this ByteBufferDestination instance. ByteBufferDestination implementations should synchronize themselves inside this method, if needed.
        Specified by:
        writeBytes in interface ByteBufferDestination