Class Utf8RecodingDeferredFileOutputStream


  • final class Utf8RecodingDeferredFileOutputStream
    extends java.lang.Object
    A deferred file output stream decorator that encodes the string from the VM to UTF-8.
    The deferred file is temporary file, and it is created at the first write. The reads can be called anytime. It is highly recommended to commit the cache which would close the file stream and subsequent reads may continue. The free() method would commit and delete the deferred file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer cache  
      static int CACHE_SIZE  
      private java.lang.String channel  
      private boolean closed  
      private java.nio.file.Path file  
      private boolean isDirty  
      private java.lang.ref.SoftReference<byte[]> largeCache  
      private static byte[] NL_BYTES  
      private java.io.RandomAccessFile storage  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void commit()  
      void free()  
      long getByteCount()  
      private byte[] getLargeCache​(int minLength)  
      private void sync()  
      void write​(java.lang.String output, boolean newLine)  
      void writeTo​(java.io.OutputStream out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NL_BYTES

        private static final byte[] NL_BYTES
      • channel

        private final java.lang.String channel
      • file

        private java.nio.file.Path file
      • storage

        private java.io.RandomAccessFile storage
      • closed

        private boolean closed
      • largeCache

        private java.lang.ref.SoftReference<byte[]> largeCache
      • cache

        private java.nio.ByteBuffer cache
      • isDirty

        private boolean isDirty
    • Constructor Detail

      • Utf8RecodingDeferredFileOutputStream

        Utf8RecodingDeferredFileOutputStream​(java.lang.String channel)
    • Method Detail

      • write

        public void write​(java.lang.String output,
                          boolean newLine)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getByteCount

        public long getByteCount()
      • writeTo

        public void writeTo​(java.io.OutputStream out)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • commit

        public void commit()
      • free

        public void free()
      • sync

        private void sync()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getLargeCache

        private byte[] getLargeCache​(int minLength)