类 FastByteArrayOutputStream

    • 构造器详细资料

      • FastByteArrayOutputStream

        public FastByteArrayOutputStream()
        Create a new FastByteArrayOutputStream with the default initial capacity of 256 bytes.
      • FastByteArrayOutputStream

        public FastByteArrayOutputStream​(int initialBlockSize)
        Create a new FastByteArrayOutputStream with the specified initial capacity.
        参数:
        initialBlockSize - the initial buffer size in bytes
    • 方法详细资料

      • toString

        public String toString()
        Convert the buffer's contents into a string decoding bytes using the platform's default character set. The length of the new String is a function of the character set, and hence may not be equal to the size of the buffer.

        This method always replaces malformed-input and unmappable-character sequences with the default replacement string for the platform's default character set. The CharsetDecoder class should be used when more control over the decoding process is required.

        覆盖:
        toString 在类中 Object
        返回:
        a String decoded from the buffer's contents
      • size

        public int size()
        Return the number of bytes stored in this FastByteArrayOutputStream.
      • toByteArrayUnsafe

        public byte[] toByteArrayUnsafe()
        Convert the stream's data to a byte array and return the byte array.

        Also replaces the internal structures with the byte array to conserve memory: if the byte array is being made anyways, mind as well as use it. This approach also means that if this method is called twice without any writes in between, the second call is a no-op.

        This method is "unsafe" as it returns the internal buffer. Callers should not modify the returned buffer.

        返回:
        the current contents of this output stream, as a byte array.
        另请参阅:
        size(), toByteArray()
      • toByteArray

        public byte[] toByteArray()
        Creates a newly allocated byte array.

        Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.

        返回:
        the current contents of this output stream, as a byte array.
        另请参阅:
        size(), toByteArrayUnsafe()
      • reset

        public void reset()
        Reset the contents of this FastByteArrayOutputStream.

        All currently accumulated output in the output stream is discarded. The output stream can be used again.

      • resize

        public void resize​(int targetCapacity)
        Resize the internal buffer size to a specified capacity.
        参数:
        targetCapacity - the desired size of the buffer
        抛出:
        IllegalArgumentException - if the given capacity is smaller than the actual size of the content stored in the buffer already
        另请参阅:
        size()