public class RolloverFileOutputStream extends OutputStream
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 and Description |
|---|
RolloverFileOutputStream(String filename) |
RolloverFileOutputStream(String filename,
boolean append) |
RolloverFileOutputStream(String filename,
boolean append,
int retainDays) |
RolloverFileOutputStream(String filename,
boolean append,
int retainDays,
TimeZone zone) |
RolloverFileOutputStream(String filename,
boolean append,
int retainDays,
TimeZone zone,
String dateFormat,
String backupFormat) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
String |
getDatedFilename() |
String |
getFilename() |
int |
getRetainDays() |
protected void |
rollover(File oldFile,
File backupFile,
File newFile)
This method is called whenever a log file is rolled over
|
static ZonedDateTime |
toMidnight(ZonedDateTime now)
Get the "start of day" for the provided DateTime at the zone specified.
|
void |
write(byte[] buf) |
void |
write(byte[] buf,
int off,
int len) |
void |
write(int b) |
public RolloverFileOutputStream(String filename) throws IOException
filename - The filename must include the string "yyyy_mm_dd",
which is replaced with the actual date when creating and rolling over the file.IOException - if unable to create outputpublic RolloverFileOutputStream(String filename, boolean append) throws IOException
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.IOException - if unable to create outputpublic RolloverFileOutputStream(String filename, boolean append, int retainDays) throws IOException
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.IOException - if unable to create outputpublic RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException
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 outputIOException - if unable to create outputpublic RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat) throws IOException
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".IOException - if unable to create outputpublic static ZonedDateTime toMidnight(ZonedDateTime now)
now - the date time to calculate frompublic String getFilename()
public String getDatedFilename()
public int getRetainDays()
protected void rollover(File oldFile, File backupFile, File newFile)
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 loggingpublic void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] buf)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] buf,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionCopyright © 1995–2018 Webtide. All rights reserved.