Methods Summary |
---|
public void | close()Closes this stream. This releases system resources used for this stream.
/**
* Although the spec claims "A closed stream cannot perform output
* operations and cannot be reopened.", this implementation must do
* nothing.
*/
super.close();
|
private void | expand(int i)
/* Can the buffer handle @i more bytes, if not expand it */
if (count + i <= buf.length) {
return;
}
byte[] newbuf = new byte[(count + i) * 2];
System.arraycopy(buf, 0, newbuf, 0, count);
buf = newbuf;
|
public synchronized 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.
count = 0;
|
public int | size()Returns the total number of bytes written to this stream so far.
return count;
|
public synchronized 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.
byte[] newArray = new byte[count];
System.arraycopy(buf, 0, newArray, 0, count);
return newArray;
|
public java.lang.String | toString(java.lang.String enc)Returns the contents of this ByteArrayOutputStream as a string converted
according to the encoding declared in {@code enc}.
return new String(buf, 0, count, enc);
|
public java.lang.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.
return new String(buf, 0, count);
|
public java.lang.String | toString(int hibyte)Returns the contents of this ByteArrayOutputStream as a string. Each byte
{@code b} in this stream is converted to a character {@code c} using the
following function:
{@code c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))}. This method is
deprecated and either {@link #toString()} or {@link #toString(String)}
should be used.
char[] newBuf = new char[size()];
for (int i = 0; i < newBuf.length; i++) {
newBuf[i] = (char) (((hibyte & 0xff) << 8) | (buf[i] & 0xff));
}
return new String(newBuf);
|
public synchronized void | write(byte[] buffer, int offset, int len)Writes {@code count} bytes from the byte array {@code buffer} starting at
offset {@code index} to this stream.
// avoid int overflow
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, made implicit null check explicit,
// used (offset | len) < 0 instead of (offset < 0) || (len < 0)
// to safe one operation
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
if ((offset | len) < 0 || len > buffer.length - offset) {
throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
if (len == 0) {
return;
}
/* Expand if necessary */
expand(len);
System.arraycopy(buffer, offset, buf, this.count, len);
this.count += len;
|
public synchronized void | write(int oneByte)Writes the specified byte {@code oneByte} to the OutputStream. Only the
low order byte of {@code oneByte} is written.
if (count == buf.length) {
expand(1);
}
buf[count++] = (byte)oneByte;
|
public synchronized void | writeTo(java.io.OutputStream out)Takes the contents of this stream and writes it to the output stream
{@code out}.
out.write(buf, 0, count);
|