public class TransactionAwareBufferedWriter
extends java.io.Writer
FileChannel
that delays actually writing to or closing the
buffer if a transaction is active. If a transaction is detected on the call
to Writer.write(String)
the parameter is buffered and passed on to the
underlying writer only when the transaction is committed.Constructor and Description |
---|
TransactionAwareBufferedWriter(java.nio.channels.FileChannel channel,
java.lang.Runnable closeCallback)
Create a new instance with the underlying file channel provided, and a callback
to execute on close.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
long |
getBufferSize()
Convenience method for clients to determine if there is any unflushed
data.
|
void |
setEncoding(java.lang.String encoding) |
void |
setForceSync(boolean forceSync)
Flag to indicate that changes should be force-synced to disk on flush.
|
void |
write(char[] cbuf,
int off,
int len) |
public TransactionAwareBufferedWriter(java.nio.channels.FileChannel channel, java.lang.Runnable closeCallback)
channel
- channel used to do the actual file IOcloseCallback
- callback to execute on closepublic void setEncoding(java.lang.String encoding)
public void setForceSync(boolean forceSync)
forceSync
- the flag value to setpublic long getBufferSize()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.Writer
java.io.IOException
public void write(char[] cbuf, int off, int len) throws java.io.IOException
write
in class java.io.Writer
java.io.IOException