public class RotatableWriter extends Object implements TextWriter, RotatableObject
RotatableWriter
that supports file rotation and retention.Modifier and Type | Class and Description |
---|---|
static interface |
RotatableWriter.RolloverLifecycleHook
Callback hooks to allow custom action to be taken before and after the checks for rotation and
retention is performed.
|
TextWriter.Stream
Modifier and Type | Field and Description |
---|---|
static RotatableWriter.RolloverLifecycleHook |
NOOP_ROLLOVER_LIFECYCLE_HOOK
A RotationRetentionCheckHook that does nothing.
|
Constructor and Description |
---|
RotatableWriter(File file,
FileBasedEventHandlerConfiguration configuration,
boolean append)
Constructs a
RotatableWriter given an initial file to manage rotation/retention, and
a FileBasedEventHandlerConfiguration . |
RotatableWriter(File file,
FileBasedEventHandlerConfiguration configuration,
boolean append,
RotatableWriter.RolloverLifecycleHook rolloverLifecycleHook)
Constructs a
RotatableWriter given an initial file to manage rotation/retention, a
a FileBasedEventHandlerConfiguration and a RotatableWriter.RolloverLifecycleHook . |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the rotatable file.
|
void |
flush()
Flushes any buffered contents of the output stream.
|
boolean |
forceRotation()
Forces a rotation of the writer.
|
long |
getBytesWritten()
Retrieves the number of bytes written by this writer.
|
org.joda.time.DateTime |
getLastRotationTime()
Retrieves the last time the file was rotated.
|
void |
registerRotationHooks(RotationHooks rotationHooks)
Registers hooks into the rotation process.
|
void |
rotateIfNeeded()
Rotate the log file if any of the configured rotation policies determine that rotation is required.
|
void |
shutdown()
Releases any resources held by the writer.
|
void |
write(String str)
Writes some text to the output stream.
|
public static final RotatableWriter.RolloverLifecycleHook NOOP_ROLLOVER_LIFECYCLE_HOOK
public RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append) throws IOException
RotatableWriter
given an initial file to manage rotation/retention, and
a FileBasedEventHandlerConfiguration
.file
- The initial file to manage rotation/retention.configuration
- The configuration of the rotation and retention policies.append
- Whether to append to the rotatable file or not.IOException
- If a problem occurs.public RotatableWriter(File file, FileBasedEventHandlerConfiguration configuration, boolean append, RotatableWriter.RolloverLifecycleHook rolloverLifecycleHook) throws IOException
RotatableWriter
given an initial file to manage rotation/retention, a
a FileBasedEventHandlerConfiguration
and a RotatableWriter.RolloverLifecycleHook
.file
- The initial file to manage rotation/retention.configuration
- The configuration of the rotation and retention policies.append
- Whether to append to the rotatable file or not.rolloverLifecycleHook
- Hook to use before and after rotation/retention checks.IOException
- If a problem occurs.public void rotateIfNeeded() throws IOException
rotateIfNeeded
in interface RotatableObject
IOException
- If unable to rotate the log file.public long getBytesWritten()
getBytesWritten
in interface TextWriter
getBytesWritten
in interface RotatableObject
public org.joda.time.DateTime getLastRotationTime()
getLastRotationTime
in interface RotatableObject
public void close() throws IOException
close
in interface RotatableObject
IOException
- If an exception occurs while closing.public void shutdown()
TextWriter
shutdown
in interface TextWriter
public void registerRotationHooks(RotationHooks rotationHooks)
registerRotationHooks
in interface RotatableObject
rotationHooks
- The RotationHooks
into the rotation process.public void write(String str) throws IOException
TextWriter
write
in interface TextWriter
str
- The text to writeIOException
- If a problem occurs.public boolean forceRotation() throws IOException
true
if rotation was done, false
otherwise.IOException
- If an error occurspublic void flush() throws IOException
TextWriter
flush
in interface TextWriter
IOException
- If a problem occurs.Copyright © 2025 Open Identity Platform Community. All rights reserved.