com.lmax.api.io
Class RollingFileWriter
java.lang.Object
java.io.Writer
com.lmax.api.io.RollingFileWriter
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable, java.lang.Appendable
public class RollingFileWriter
- extends java.io.Writer
Writer that will roll files as they exceed a certain size.
Fields inherited from class java.io.Writer |
lock |
Constructor Summary |
RollingFileWriter(java.io.File directory,
java.lang.String pattern,
int maxSize)
Create a Rolling file writer with a specified directory, filename pattern and max size. |
Method Summary |
void |
close()
Closes the stream, flushing it first. |
void |
flush()
Doesn't flush the underlying stream, but will check if the file sufficiently
large that it needs to be rolled over to the next file. |
void |
write(char[] cbuf,
int off,
int len)
Writes a portion of an array of characters. |
Methods inherited from class java.io.Writer |
append, append, append, write, write, write, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RollingFileWriter
public RollingFileWriter(java.io.File directory,
java.lang.String pattern,
int maxSize)
- Create a Rolling file writer with a specified directory, filename pattern and max size.
- Parameters:
directory
- The directory to store the files.pattern
- The pattern used to create the file name, must contain a '%s' as it is used in a string format call.maxSize
- The maximum size for the individual file in bytes.
write
public void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
- Writes a portion of an array of characters.
- Specified by:
write
in class java.io.Writer
- Parameters:
cbuf
- Array of charactersoff
- Offset from which to start writing characterslen
- Number of characters to write
- Throws:
java.io.IOException
- If an I/O error occurs
flush
public void flush()
throws java.io.IOException
- Doesn't flush the underlying stream, but will check if the file sufficiently
large that it needs to be rolled over to the next file.
- Specified by:
flush
in interface java.io.Flushable
- Specified by:
flush
in class java.io.Writer
- Throws:
java.io.IOException
- If an I/O error occurs
close
public void close()
throws java.io.IOException
- Closes the stream, flushing it first. Once the stream has been closed,
further write() or flush() invocations will cause an IOException to be
thrown. Closing a previously closed stream has no effect.
- Specified by:
close
in interface java.io.Closeable
- Specified by:
close
in class java.io.Writer
- Throws:
java.io.IOException
- If an I/O error occurs