toByteArray()
and
toString()
.
Closing a ByteArrayOutputStream
has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException
.
Modifier and Type | Field and Description |
---|---|
protected byte[] | buf
The buffer where data is stored. |
protected int | count
The number of valid bytes in the buffer. |
Access | Constructor and Description |
---|---|
public | |
public | ByteArrayOutputStream(int
the initial size. size)Creates a new |
Modifier and Type | Method and Description |
---|---|
public void | close()
Overrides java. Implements java. Closing a |
private void | ensureCapacity(int
the desired minimum capacity. minCapacity)Increases the capacity if necessary to ensure that it can hold at least the number of elements specified by the minimum capacity argument. |
public synchronized void | reset()
Resets the |
public synchronized int | Returns: the value of thecount field, which is the number
of valid bytes in this output stream.Returns the current size of the buffer. |
public synchronized byte[] | Returns: the current contents of this output stream, as a byte array.Creates a newly allocated byte array. |
public synchronized String | Returns: String decoded from the buffer's contents.Overrides java. Converts the buffer's contents into a string decoding bytes using the default charset. |
public synchronized String | |
public synchronized String | |
public synchronized String | Returns: the current contents of the output stream, as a string.the high byte of each resulting Unicode character. hibyte)
Deprecated
This method does not properly convert bytes into characters.
Creates a newly allocated string. |
public synchronized void | write(int
the byte to be written. b)Implements abstract java. Writes the specified byte to this |
public synchronized void | write(byte[]
the data. b, int the start offset in the data. off, int the number of bytes to write. len)Overrides java. Writes |
public void | writeBytes(byte[]
the data. b)Writes the complete contents of the specified byte array
to this |
public synchronized void | writeTo(OutputStream
the output stream to which to write the data. out)Writes the complete contents of this |
buf | back to summary |
---|---|
protected byte[] buf The buffer where data is stored. |
count | back to summary |
---|---|
protected int count The number of valid bytes in the buffer. |
ByteArrayOutputStream | back to summary |
---|---|
public ByteArrayOutputStream() Creates a new |
ByteArrayOutputStream | back to summary |
---|---|
public ByteArrayOutputStream(int size) Creates a new
|
close | back to summary |
---|---|
public void close() throws IOException Overrides java. Implements java. Closing a
|
ensureCapacity | back to summary |
---|---|
private void ensureCapacity(int minCapacity) Increases the capacity if necessary to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
|
reset | back to summary |
---|---|
public synchronized void reset() Resets the
|
size | back to summary |
---|---|
public synchronized int size() Returns the current size of the buffer.
|
toByteArray | back to summary |
---|---|
public synchronized 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.
|
toString | back to summary |
---|---|
public synchronized String toString() Overrides java. Converts the buffer's contents into a string decoding bytes using the
default charset. The length of the new This method always replaces malformed-input and unmappable-character sequences with the default replacement string for the default charset. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.
|
toString | back to summary |
---|---|
public synchronized String toString(String charsetName) throws UnsupportedEncodingException Converts the buffer's contents into a string by decoding the bytes using
the named This method is equivalent to An invocation of this method of the form ByteArrayOutputStream b; b.toString("UTF-8") ByteArrayOutputStream b; b.toString(StandardCharsets.UTF_8)
|
toString | back to summary |
---|---|
public synchronized String toString(Charset charset) Converts the buffer's contents into a string by decoding the bytes using
the specified This method always replaces malformed-input and unmappable-character
sequences with the charset's default replacement string. The |
toString | back to summary |
---|---|
public synchronized String toString(int hibyte)
Deprecated This method does not properly convert bytes into characters.
As of JDK 1.1, the preferred way to do this is via the
Creates a newly allocated string. Its size is the current size of the output stream and the valid contents of the buffer have been copied into it. Each character c in the resulting string is constructed from the corresponding element b in the byte array such that: c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
|
write | back to summary |
---|---|
public synchronized void write(int b) Implements abstract java. Writes the specified byte to this
|
write | back to summary |
---|---|
public synchronized void write(byte[] b, int off, int len) Overrides java. Writes
|
writeBytes | back to summary |
---|---|
public void writeBytes(byte[] b) Writes the complete contents of the specified byte array
to this API Note This method is equivalent to
|
writeTo | back to summary |
---|---|
public synchronized void writeTo(OutputStream out) throws IOException Writes the complete contents of this
|