Class LengthCounter

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

    class LengthCounter
    extends java.io.OutputStream
    Count the number of bytes written to the stream. Also, save a copy of small messages to avoid having to process the data again.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buf  
      private int maxsize  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      LengthCounter​(int maxsize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getBytes()  
      int getSize()  
      void write​(byte[] b)  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • size

        private int size
      • buf

        private byte[] buf
      • maxsize

        private int maxsize
    • Constructor Detail

      • LengthCounter

        public LengthCounter​(int maxsize)
    • Method Detail

      • write

        public void write​(int b)
        Specified by:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
        Overrides:
        write in class java.io.OutputStream
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • getSize

        public int getSize()
      • getBytes

        public byte[] getBytes()