Top Description Fields Constructors Methods
org.eclipse.jetty.util

public Class RolloverFileOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.File, .FileOutputStream, .IOException, .OutputStream, java.nio.file.Files, java.text.SimpleDateFormat, java.time.ZonedDateTime, java.time.temporal.ChronoUnit, java.util.Date, .Locale, .TimeZone, java.util.concurrent.Executors, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, org.eclipse.jetty.util.thread.AutoLock

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.

Field Summary

Modifier and TypeField and Description
private static final ScheduledExecutorService
private final boolean
private File
private final SimpleDateFormat
private final SimpleDateFormat
private String
private final AutoLock
private OutputStream
private final int
private ScheduledFuture<?>
pack-priv static final String
pack-priv static final String
pack-priv static final int
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public
RolloverFileOutputStream(String
The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
filename
)

public
RolloverFileOutputStream(String
The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
filename
,
boolean
If true, existing files will be appended to.
append
)

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

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

public
RolloverFileOutputStream(String
The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
filename
,
boolean
If true, existing files will be appended to.
append
,
int
The number of days to retain files before deleting them. 0 to retain forever.
retainDays
,
TimeZone
the timezone for the output
zone
,
String
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.
dateFormat
,
String
The format for the file extension of backup files. The default is "HHmmssSSS".
backupFormat
)

pack-priv
RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat, ZonedDateTime now)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

public String
public String
public int
pack-priv void
private void
renameFile(File src, File dest)

protected void
rollover(File
The original filename or null if this is the first creation
oldFile
,
File
The backup filename or null if the filename is dated.
backupFile
,
File
The new filename that is now being used for logging
newFile
)

This method is called whenever a log file is rolled over

private void
private void
pack-priv void
public static ZonedDateTime

Returns:

start of the day of the date provided
toMidnight
(ZonedDateTime
the date time to calculate from
now
)

Get the "start of day" for the provided DateTime at the zone specified.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
buf
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

public void
write(byte[]
the data.
buf
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
nullOutputStream

Field Detail

__schedulerback to summary
private static final ScheduledExecutorService __scheduler
_appendback to summary
private final boolean _append
_fileback to summary
private File _file
_fileBackupFormatback to summary
private final SimpleDateFormat _fileBackupFormat
_fileDateFormatback to summary
private final SimpleDateFormat _fileDateFormat
_filenameback to summary
private String _filename
_lockback to summary
private final AutoLock _lock
_outback to summary
private OutputStream _out
_retainDaysback to summary
private final int _retainDays
_rollTaskback to summary
private ScheduledFuture<?> _rollTask
ROLLOVER_FILE_BACKUP_FORMATback to summary
pack-priv static final String ROLLOVER_FILE_BACKUP_FORMAT
ROLLOVER_FILE_DATE_FORMATback to summary
pack-priv static final String ROLLOVER_FILE_DATE_FORMAT
ROLLOVER_FILE_RETAIN_DAYSback to summary
pack-priv static final int ROLLOVER_FILE_RETAIN_DAYS
YYYY_MM_DDback to summary
pack-priv static final String YYYY_MM_DD

Constructor Detail

RolloverFileOutputStreamback to summary
public RolloverFileOutputStream(String filename) throws IOException
Parameters
filename:String

The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

Exceptions
IOException:
if unable to create output
RolloverFileOutputStreamback to summary
public RolloverFileOutputStream(String filename, boolean append) throws IOException
Parameters
filename:String

The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

append:boolean

If true, existing files will be appended to.

Exceptions
IOException:
if unable to create output
RolloverFileOutputStreamback to summary
public RolloverFileOutputStream(String filename, boolean append, int retainDays) throws IOException
Parameters
filename:String

The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

append:boolean

If true, existing files will be appended to.

retainDays:int

The number of days to retain files before deleting them. 0 to retain forever.

Exceptions
IOException:
if unable to create output
RolloverFileOutputStreamback to summary
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException
Parameters
filename:String

The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

append:boolean

If true, existing files will be appended to.

retainDays:int

The number of days to retain files before deleting them. 0 to retain forever.

zone:TimeZone

the timezone for the output

Exceptions
IOException:
if unable to create output
RolloverFileOutputStreamback to summary
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat) throws IOException
Parameters
filename:String

The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.

append:boolean

If true, existing files will be appended to.

retainDays:int

The number of days to retain files before deleting them. 0 to retain forever.

zone:TimeZone

the timezone for the output

dateFormat:String

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:String

The format for the file extension of backup files. The default is "HHmmssSSS".

Exceptions
IOException:
if unable to create output
RolloverFileOutputStreamback to summary
pack-priv RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat, ZonedDateTime now) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getDatedFilenameback to summary
public String getDatedFilename()
getFilenameback to summary
public String getFilename()
getRetainDaysback to summary
public int getRetainDays()
removeOldFilesback to summary
pack-priv void removeOldFiles(ZonedDateTime now)
renameFileback to summary
private void renameFile(File src, File dest) throws IOException
rolloverback to summary
protected void rollover(File oldFile, File backupFile, File newFile)

This method is called whenever a log file is rolled over

Parameters
oldFile:File

The original filename or null if this is the first creation

backupFile:File

The backup filename or null if the filename is dated.

newFile:File

The new filename that is now being used for logging

rollOverback to summary
private void rollOver()
scheduleNextRolloverback to summary
private void scheduleNextRollover(ZonedDateTime now)
setFileback to summary
pack-priv void setFile(ZonedDateTime now) throws IOException
toMidnightback to summary
public static ZonedDateTime toMidnight(ZonedDateTime now)

Get the "start of day" for the provided DateTime at the zone specified.

Parameters
now:ZonedDateTime

the date time to calculate from

Returns:ZonedDateTime

start of the day of the date provided

writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] buf) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
buf:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] buf, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
buf:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.