Class RolloverFileOutputStream

java.lang.Object
java.io.OutputStream
org.eclipse.jetty.util.RolloverFileOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class RolloverFileOutputStream extends OutputStream
RolloverFileOutputStream.

This output stream puts content in a file that is rolled over every 24 hours. The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

Old files are retained for a number of days before being deleted.

  • Constructor Details

    • RolloverFileOutputStream

      public RolloverFileOutputStream(String filename) throws IOException
      Parameters:
      filename - The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
      Throws:
      IOException - if unable to create output
    • RolloverFileOutputStream

      public RolloverFileOutputStream(String filename, boolean append) throws IOException
      Parameters:
      filename - The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
      append - If true, existing files will be appended to.
      Throws:
      IOException - if unable to create output
    • RolloverFileOutputStream

      public RolloverFileOutputStream(String filename, boolean append, int retainDays) throws IOException
      Parameters:
      filename - The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
      append - If true, existing files will be appended to.
      retainDays - The number of days to retain files before deleting them. 0 to retain forever.
      Throws:
      IOException - if unable to create output
    • RolloverFileOutputStream

      public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException
      Parameters:
      filename - The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
      append - If true, existing files will be appended to.
      retainDays - The number of days to retain files before deleting them. 0 to retain forever.
      zone - the timezone for the output
      Throws:
      IOException - if unable to create output
    • RolloverFileOutputStream

      public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat) throws IOException
      Parameters:
      filename - The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
      append - If true, existing files will be appended to.
      retainDays - The number of days to retain files before deleting them. 0 to retain forever.
      zone - the timezone for the output
      dateFormat - The format for the date file substitution. The default is "yyyy_MM_dd". If set to the empty string, the file is rolledover to the same filename, with the current file being renamed to the backup filename.
      backupFormat - The format for the file extension of backup files. The default is "HHmmssSSS".
      Throws:
      IOException - if unable to create output
  • Method Details

    • toMidnight

      public static ZonedDateTime toMidnight(ZonedDateTime now)
      Get the "start of day" for the provided DateTime at the zone specified.
      Parameters:
      now - the date time to calculate from
      Returns:
      start of the day of the date provided
    • getFilename

      public String getFilename()
    • getDatedFilename

      public String getDatedFilename()
    • getRetainDays

      public int getRetainDays()
    • rollover

      protected void rollover(File oldFile, File backupFile, File newFile)
      This method is called whenever a log file is rolled over
      Parameters:
      oldFile - The original filename or null if this is the first creation
      backupFile - The backup filename or null if the filename is dated.
      newFile - The new filename that is now being used for logging
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] buf) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] buf, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException