Class PooledSpecializedStringWriter

  • All Implemented Interfaces:
    SpecializedWriter, java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class PooledSpecializedStringWriter
    extends java.io.Writer
    implements SpecializedWriter
    A $SpecializedWriter that's pooled in a $ThreadLocal. It's backed by a $StringBuilder so it's not threadsafe but doesn't involve synchronization. Beware that it has some limitations:
    • As it's backed by a $ThreadLocal, it might leak in environments where ClassLoaders are rebooted at runtime
    • It doesn't take any security measure against very large payloads that would cause underlying buffers to eat memory
    • Constructor Detail

      • PooledSpecializedStringWriter

        private PooledSpecializedStringWriter()
    • Method Detail

      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
        Specified by:
        write in class java.io.Writer
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
      • toString

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