Package org.eclipse.jetty.util
Class RolloverFileOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.eclipse.jetty.util.RolloverFileOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class RolloverFileOutputStream extends java.io.OutputStreamRolloverFileOutputStream.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classRolloverFileOutputStream.RollTask
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Timer__rolloverprivate boolean_appendprivate java.io.File_fileprivate java.text.SimpleDateFormat_fileBackupFormatprivate java.text.SimpleDateFormat_fileDateFormatprivate java.lang.String_filenameprivate java.io.OutputStream_outprivate int_retainDaysprivate RolloverFileOutputStream.RollTask_rollTask(package private) static java.lang.StringROLLOVER_FILE_BACKUP_FORMAT(package private) static java.lang.StringROLLOVER_FILE_DATE_FORMAT(package private) static intROLLOVER_FILE_RETAIN_DAYS(package private) static java.lang.StringYYYY_MM_DD
-
Constructor Summary
Constructors Constructor Description RolloverFileOutputStream(java.lang.String filename)RolloverFileOutputStream(java.lang.String filename, boolean append)RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays)RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone)RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone, java.lang.String dateFormat, java.lang.String backupFormat)RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone, java.lang.String dateFormat, java.lang.String backupFormat, java.time.ZonedDateTime now)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()java.lang.StringgetDatedFilename()java.lang.StringgetFilename()intgetRetainDays()(package private) voidremoveOldFiles(java.time.ZonedDateTime now)private voidrenameFile(java.io.File src, java.io.File dest)protected voidrollover(java.io.File oldFile, java.io.File backupFile, java.io.File newFile)This method is called whenever a log file is rolled overprivate voidscheduleNextRollover(java.time.ZonedDateTime now)(package private) voidsetFile(java.time.ZonedDateTime now)static java.time.ZonedDateTimetoMidnight(java.time.ZonedDateTime now)Get the "start of day" for the provided DateTime at the zone specified.voidwrite(byte[] buf)voidwrite(byte[] buf, int off, int len)voidwrite(int b)
-
-
-
Field Detail
-
__rollover
private static java.util.Timer __rollover
-
YYYY_MM_DD
static final java.lang.String YYYY_MM_DD
- See Also:
- Constant Field Values
-
ROLLOVER_FILE_DATE_FORMAT
static final java.lang.String ROLLOVER_FILE_DATE_FORMAT
- See Also:
- Constant Field Values
-
ROLLOVER_FILE_BACKUP_FORMAT
static final java.lang.String ROLLOVER_FILE_BACKUP_FORMAT
- See Also:
- Constant Field Values
-
ROLLOVER_FILE_RETAIN_DAYS
static final int ROLLOVER_FILE_RETAIN_DAYS
- See Also:
- Constant Field Values
-
_out
private java.io.OutputStream _out
-
_rollTask
private RolloverFileOutputStream.RollTask _rollTask
-
_fileBackupFormat
private java.text.SimpleDateFormat _fileBackupFormat
-
_fileDateFormat
private java.text.SimpleDateFormat _fileDateFormat
-
_filename
private java.lang.String _filename
-
_file
private java.io.File _file
-
_append
private boolean _append
-
_retainDays
private int _retainDays
-
-
Constructor Detail
-
RolloverFileOutputStream
public RolloverFileOutputStream(java.lang.String filename) throws java.io.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:
java.io.IOException- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(java.lang.String filename, boolean append) throws java.io.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:
java.io.IOException- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays) throws java.io.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:
java.io.IOException- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone) throws java.io.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:
java.io.IOException- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone, java.lang.String dateFormat, java.lang.String backupFormat) throws java.io.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 outputdateFormat- 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:
java.io.IOException- if unable to create output
-
RolloverFileOutputStream
RolloverFileOutputStream(java.lang.String filename, boolean append, int retainDays, java.util.TimeZone zone, java.lang.String dateFormat, java.lang.String backupFormat, java.time.ZonedDateTime now) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
toMidnight
public static java.time.ZonedDateTime toMidnight(java.time.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
-
scheduleNextRollover
private void scheduleNextRollover(java.time.ZonedDateTime now)
-
getFilename
public java.lang.String getFilename()
-
getDatedFilename
public java.lang.String getDatedFilename()
-
getRetainDays
public int getRetainDays()
-
setFile
void setFile(java.time.ZonedDateTime now) throws java.io.IOException- Throws:
java.io.IOException
-
renameFile
private void renameFile(java.io.File src, java.io.File dest) throws java.io.IOException- Throws:
java.io.IOException
-
rollover
protected void rollover(java.io.File oldFile, java.io.File backupFile, java.io.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 creationbackupFile- The backup filename or null if the filename is dated.newFile- The new filename that is now being used for logging
-
removeOldFiles
void removeOldFiles(java.time.ZonedDateTime now)
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] buf) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] buf, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
-