Class FileStringBuffer

  • All Implemented Interfaces:
    IBuffer

    public class FileStringBuffer
    extends java.lang.Object
    implements IBuffer
    A string buffer that flushes its content to a temporary file whenever the internal string buffer becomes larger than MAX. If the buffer never reaches that size, no file is ever created and everything happens in memory, so the overhead compared to StringBuffer/StringBuilder is minimal. Note: calling toString() will force the entire string to be loaded in memory, use toWriter() if you need to avoid this. This class is not multi thread safe.
    Since:
    Nov 9, 2012
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File m_file  
      private int m_maxCharacters  
      private java.lang.StringBuilder m_sb  
      private static int MAX  
      private static boolean VERBOSE  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      FileStringBuffer append​(java.lang.CharSequence s)  
      private static void copy​(java.io.Reader input, java.io.Writer output)  
      private void flushToFile()  
      static void main​(java.lang.String[] args)  
      private static void p​(java.lang.String s)  
      java.lang.String toString()  
      void toWriter​(java.io.Writer fw)  
      • Methods inherited from class java.lang.Object

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

      • MAX

        private static int MAX
      • VERBOSE

        private static final boolean VERBOSE
      • m_file

        private java.io.File m_file
      • m_sb

        private java.lang.StringBuilder m_sb
      • m_maxCharacters

        private final int m_maxCharacters
    • Constructor Detail

      • FileStringBuffer

        public FileStringBuffer()
      • FileStringBuffer

        public FileStringBuffer​(int maxCharacters)
    • Method Detail

      • toWriter

        public void toWriter​(java.io.Writer fw)
        Specified by:
        toWriter in interface IBuffer
      • copy

        private static void copy​(java.io.Reader input,
                                 java.io.Writer output)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • flushToFile

        private void flushToFile()
      • p

        private static void p​(java.lang.String s)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Throws:
        java.io.IOException