IT. Expert System.

Android Reference

ByteArrayOutputStream


java.io

Class ByteArrayOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable


    public class ByteArrayOutputStream
    extends OutputStream
    A specialized OutputStream for class for writing content to an (internal) byte array. As bytes are written to this stream, the byte array may be expanded to hold more bytes. When the writing is considered to be finished, a copy of the byte array can be requested from the class.
    See Also:
    ByteArrayInputStream
    • Field Summary

      Fields
      Modifier and Type Field and Description
      protected byte[] buf
      The byte array containing the bytes written.
      protected int count
      The number of bytes written.
    • Constructor Summary

      Constructors
      Constructor and Description
      ByteArrayOutputStream()
      Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
      ByteArrayOutputStream(int size)
      Constructs a new ByteArrayOutputStream with a default size of size bytes.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      void close()
      Closes this stream.
      void reset()
      Resets this stream to the beginning of the underlying byte array.
      int size()
      Returns the total number of bytes written to this stream so far.
      byte[] toByteArray()
      Returns the contents of this ByteArrayOutputStream as a byte array.
      String toString()
      Returns the contents of this ByteArrayOutputStream as a string.
      String toString(int hibyte)
      Deprecated.
      String toString(String charsetName)
      Returns the contents of this ByteArrayOutputStream as a string converted according to the encoding declared in charsetName.
      void write(byte[] buffer, int offset, int len)
      Writes count bytes from the byte array buffer starting at offset index to this stream.
      void write(int oneByte)
      Writes the specified byte oneByte to the OutputStream.
      void writeTo(OutputStream out)
      Takes the contents of this stream and writes it to the output stream out.
    • Field Detail

      • buf

        protected byte[] buf
        The byte array containing the bytes written.
      • count

        protected int count
        The number of bytes written.
    • Constructor Detail

      • ByteArrayOutputStream

        public ByteArrayOutputStream()
        Constructs a new ByteArrayOutputStream with a default size of 32 bytes. If more than 32 bytes are written to this instance, the underlying byte array will expand.
      • ByteArrayOutputStream

        public ByteArrayOutputStream(int size)
        Constructs a new ByteArrayOutputStream with a default size of size bytes. If more than size bytes are written to this instance, the underlying byte array will expand.
        Parameters:
        size - initial size for the underlying byte array, must be non-negative.
        Throws:
        IllegalArgumentException - if size < 0.
    • Method Detail

      • reset

        public void reset()
        Resets this stream to the beginning of the underlying byte array. All subsequent writes will overwrite any bytes previously stored in this stream.
      • size

        public int size()
        Returns the total number of bytes written to this stream so far.
        Returns:
        the number of bytes written to this stream.
      • toByteArray

        public byte[] toByteArray()
        Returns the contents of this ByteArrayOutputStream as a byte array. Any changes made to the receiver after returning will not be reflected in the byte array returned to the caller.
        Returns:
        this stream's current contents as a byte array.
      • toString

        public String toString()
        Returns the contents of this ByteArrayOutputStream as a string. Any changes made to the receiver after returning will not be reflected in the string returned to the caller.
        Overrides:
        toString in class Object
        Returns:
        this stream's current contents as a string.
      • toString

        @Deprecated
        public String toString(int hibyte)
        Deprecated. Use toString().
        Returns the contents of this ByteArrayOutputStream as a string. Each byte b in this stream is converted to a character c using the following function: c == (char)(((hibyte & 0xff) << 8) | (b & 0xff)). This method is deprecated and either toString() or toString(String) should be used.
        Parameters:
        hibyte - the high byte of each resulting Unicode character.
        Returns:
        this stream's current contents as a string with the high byte set to hibyte.
      • toString

        public String toString(String charsetName)
                        throws UnsupportedEncodingException
        Returns the contents of this ByteArrayOutputStream as a string converted according to the encoding declared in charsetName.
        Parameters:
        charsetName - a string representing the encoding to use when translating this stream to a string.
        Returns:
        this stream's current contents as an encoded string.
        Throws:
        UnsupportedEncodingException - if the provided encoding is not supported.
      • write

        public void write(byte[] buffer,
                 int offset,
                 int len)
        Writes count bytes from the byte array buffer starting at offset index to this stream.
        Overrides:
        write in class OutputStream
        Parameters:
        buffer - the buffer to be written.
        offset - the initial position in buffer to retrieve bytes.
        len - the number of bytes of buffer to write.
        Throws:
        NullPointerException - if buffer is null.
        IndexOutOfBoundsException - if offset < 0 or len < 0, or if offset + len is greater than the length of buffer.
      • write

        public void write(int oneByte)
        Writes the specified byte oneByte to the OutputStream. Only the low order byte of oneByte is written.
        Specified by:
        write in class OutputStream
        Parameters:
        oneByte - the byte to be written.
      • writeTo

        public void writeTo(OutputStream out)
                     throws IOException
        Takes the contents of this stream and writes it to the output stream out.
        Parameters:
        out - an OutputStream on which to write the contents of this stream.
        Throws:
        IOException - if an error occurs while writing to out.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1056 / . Delta: 0.02118 с