类 TransactionAwareBufferedWriter

  • 所有已实现的接口:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class TransactionAwareBufferedWriter
    extends java.io.Writer
    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.
    作者:
    Dave Syer, Michael Minella
    • 字段概要

      • 从类继承的字段 java.io.Writer

        lock
    • 构造器概要

      构造器 
      构造器说明
      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.
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidclose() 
      voidflush() 
      longgetBufferSize()
      Convenience method for clients to determine if there is any unflushed data.
      voidsetEncoding​(java.lang.String encoding) 
      voidsetForceSync​(boolean forceSync)
      Flag to indicate that changes should be force-synced to disk on flush.
      voidwrite​(char[] cbuf, int off, int len) 
      • 从类继承的方法 java.io.Writer

        append, append, append, nullWriter, write, write, write, write
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • TransactionAwareBufferedWriter

        public 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. The callback should clean up related resources like output streams or channels.
        参数:
        channel - channel used to do the actual file IO
        closeCallback - callback to execute on close
    • 方法详细资料

      • setEncoding

        public void setEncoding​(java.lang.String encoding)
      • 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.
        参数:
        forceSync - the flag value to set
      • getBufferSize

        public long getBufferSize()
        Convenience method for clients to determine if there is any unflushed data.
        返回:
        the current size (in bytes) of unflushed buffered data
      • close

        public void close()
                   throws java.io.IOException
        指定者:
        close 在接口中 java.lang.AutoCloseable
        指定者:
        close 在接口中 java.io.Closeable
        指定者:
        close 在类中 java.io.Writer
        抛出:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        指定者:
        flush 在接口中 java.io.Flushable
        指定者:
        flush 在类中 java.io.Writer
        抛出:
        java.io.IOException
      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
                   throws java.io.IOException
        指定者:
        write 在类中 java.io.Writer
        抛出:
        java.io.IOException