Class FileManager

All Implemented Interfaces:
AutoCloseable, ByteBufferDestination
Direct Known Subclasses:

public class FileManager extends OutputStreamManager
Manages actual File I/O for File Appenders.
  • Constructor Details

  • Method Details

    • getFileManager

      public static FileManager getFileManager(String fileName, boolean append, boolean locking, boolean bufferedIo, boolean createOnDemand, String advertiseUri, Layout<? extends Serializable> layout, int bufferSize, String filePermissions, String fileOwner, String fileGroup, Configuration configuration)
      Returns the FileManager.
      fileName - The name of the file to manage.
      append - true if the file should be appended to, false if it should be overwritten.
      locking - true if the file should be locked while writing, false otherwise.
      bufferedIo - true if the contents should be buffered as they are written.
      createOnDemand - true if you want to lazy-create the file (a.k.a. on-demand.)
      advertiseUri - the URI to use when advertising the file
      layout - The layout
      bufferSize - buffer size for buffered IO
      filePermissions - File permissions
      fileOwner - File owner
      fileGroup - File group
      configuration - The configuration.
      A FileManager for the File.
    • createOutputStream

      protected OutputStream createOutputStream() throws IOException
      createOutputStream in class OutputStreamManager
    • createParentDir

      protected void createParentDir(File file)
    • defineAttributeView

      protected void defineAttributeView(Path path)
    • write

      protected void write(byte[] bytes, int offset, int length, boolean immediateFlush)
      Description copied from class: OutputStreamManager
      Some output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.
      write in class OutputStreamManager
      bytes - The serialized Log event.
      offset - The offset into the byte array.
      length - The number of bytes to write.
      immediateFlush - flushes immediately after writing.
    • writeToDestination

      protected void writeToDestination(byte[] bytes, int offset, int length)
      Overrides OutputStreamManager.writeToDestination(byte[], int, int) to add support for file locking.
      writeToDestination in class OutputStreamManager
      bytes - the array containing data
      offset - from where to write
      length - how many bytes to write
    • getFileName

      public String getFileName()
      Returns the name of the File being managed.
      The name of the File being managed.
    • isAppend

      public boolean isAppend()
      Returns the append status.
      true if the file will be appended to, false if it is overwritten.
    • isCreateOnDemand

      public boolean isCreateOnDemand()
      Returns the lazy-create.
      true if the file will be lazy-created.
    • isLocking

      public boolean isLocking()
      Returns the lock status.
      true if the file will be locked when writing, false otherwise.
    • getBufferSize

      public int getBufferSize()
      Returns the buffer size to use if the appender was configured with BufferedIO=true, otherwise returns a negative number.
      the buffer size, or a negative number if the output stream is not buffered
    • getFilePermissions

      public Set<PosixFilePermission> getFilePermissions()
      Returns POSIX file permissions if defined and the OS supports POSIX file attribute, null otherwise.
      File POSIX permissions
      See Also:
    • getFileOwner

      public String getFileOwner()
      Returns file owner if defined and the OS supports owner file attribute view, null otherwise.
      File owner
      See Also:
    • getFileGroup

      public String getFileGroup()
      Returns file group if defined and the OS supports POSIX/group file attribute view, null otherwise.
      File group
      See Also:
    • isAttributeViewEnabled

      public boolean isAttributeViewEnabled()
      Returns true if file attribute view enabled for this file manager.
      True if POSIX or owner supported and defined false otherwise.
    • getContentFormat

      public Map<String,String> getContentFormat()
      FileManager's content format is specified by: Key: "fileURI" Value: provided "advertiseURI" param.
      getContentFormat in class AbstractManager
      Map of content format keys supporting FileManager