Class PublicBAOS

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

    public class PublicBAOS
    extends java.io.ByteArrayOutputStream
    A subclass extending ByteArrayOutputStream. It's used to return the byte array directly. Note that the size of byte array is large than actual size of valid contents, thus it's used cooperating with size() or capacity = size
    • Field Summary

      • Fields inherited from class java.io.ByteArrayOutputStream

        buf, count
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getBuf()
      get current all bytes data
      void reset()
      It's not a thread-safe method.
      int size()
      The synchronized keyword in this function is intentionally removed.
      void truncate​(int size)  
      void writeTo​(java.io.OutputStream out)
      It's not a thread-safe method.
      • Methods inherited from class java.io.ByteArrayOutputStream

        close, toByteArray, toString, toString, toString, toString, write, write, writeBytes
      • Methods inherited from class java.io.OutputStream

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

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

      • PublicBAOS

        public PublicBAOS()
      • PublicBAOS

        public PublicBAOS​(int size)
    • Method Detail

      • getBuf

        public byte[] getBuf()
        get current all bytes data
        Returns:
        all bytes data
      • writeTo

        public void writeTo​(java.io.OutputStream out)
                     throws java.io.IOException
        It's not a thread-safe method. Override the super class's implementation. Remove the synchronized key word, to save the synchronization overhead.

        Writes the complete contents of this byte array output stream to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count).

        Overrides:
        writeTo in class java.io.ByteArrayOutputStream
        Parameters:
        out - the output stream to which to write the data.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • reset

        public void reset()
        It's not a thread-safe method. Override the super class's implementation. Remove the synchronized key word, to save the synchronization overhead.

        Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the output stream is discarded. The output stream can be used again, reusing the already allocated buffer space.

        Overrides:
        reset in class java.io.ByteArrayOutputStream
      • size

        public int size()
        The synchronized keyword in this function is intentionally removed. For details, see https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=173085039
        Overrides:
        size in class java.io.ByteArrayOutputStream
      • truncate

        public void truncate​(int size)