Class TransactionAwareBufferedWriter
java.lang.Object
java.io.Writer
org.springframework.batch.support.transaction.TransactionAwareBufferedWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Wrapper for a
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.- Author:
- Dave Syer, Michael Minella, Niels Ferguson, Mahmoud Ben Hassine
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTransactionAwareBufferedWriter
(FileChannel channel, Runnable closeCallback) Create a new instance with the underlying file channel provided, and a callback to execute on close. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
long
Convenience method for clients to determine if there is any unflushed data.void
setEncoding
(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) void
-
Constructor Details
-
TransactionAwareBufferedWriter
Create a new instance with the underlying file channel provided, and a callback to execute on close. The callback should clean up related resources like output streams or channels.- Parameters:
channel
- channel used to do the actual file IOcloseCallback
- callback to execute on close
-
-
Method Details
-
setEncoding
-
setForceSync
public void setForceSync(boolean forceSync) Flag to indicate that changes should be force-synced to disk on flush. Defaults to false, which means that even with a local disk changes could be lost if the OS crashes in between a write and a cache flush. Setting to true may result in slower performance for usage patterns involving many frequent writes.- Parameters:
forceSync
- the flag value to set
-
getBufferSize
public long getBufferSize()Convenience method for clients to determine if there is any unflushed data.- Returns:
- the current size (in bytes) of unflushed buffered data
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-