Class PublicBAOS

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public class PublicBAOS
    extends 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
    • 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​(OutputStream out)
                     throws 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 ByteArrayOutputStream
        Parameters:
        out - the output stream to which to write the data.
        Throws:
        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 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 ByteArrayOutputStream
      • truncate

        public void truncate​(int size)