Class Snippet.Buffer.SnippetWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable, Buffered
    Enclosing class:
    Snippet.Buffer

    class Snippet.Buffer.SnippetWriter
    extends Snippet.PassthroughWriter
    implements Buffered
    Specialized Writer with three internal states: Writing, Completed, Truncated. When there is still space left for more json, the state will be Writing If the last write brought is exactly to the end of the max length, the state will be Completed. If the last write brought us over the max length, the state will be Truncated.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ByteArrayOutputStream buffer  
      private int max  
      private Snippet.PassthroughWriter mode  
      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      SnippetWriter​(int max)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int bufferSize()
      The buffer size used by this stream while reading input or before writing output to the underlying stream.
      void close()  
      void flush()  
      java.lang.String get()  
      boolean isTruncated()  
      boolean terminate()
      Calling this method implies the need to continue writing and a question on if that is ok.
      void write​(char[] cbuf, int off, int len)  
      • Methods inherited from class java.io.Writer

        nullWriter, write
      • Methods inherited from class java.lang.Object

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

      • buffer

        private final java.io.ByteArrayOutputStream buffer
      • max

        private final int max
    • Constructor Detail

      • SnippetWriter

        public SnippetWriter​(int max)
    • Method Detail

      • get

        public java.lang.String get()
      • bufferSize

        public int bufferSize()
        Description copied from interface: Buffered
        The buffer size used by this stream while reading input or before writing output to the underlying stream.
        Specified by:
        bufferSize in interface Buffered
        Returns:
        the size of the buffer
      • terminate

        public boolean terminate()
        Calling this method implies the need to continue writing and a question on if that is ok. It impacts internal state in the same way as calling a write method.
        Returns:
        true if no more writes are possible
      • isTruncated

        public boolean isTruncated()
      • write

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

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class Snippet.PassthroughWriter
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Snippet.PassthroughWriter
        Throws:
        java.io.IOException