Methods Summary |
---|
public void | close()Closing a ByteArrayOutputStream has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException.
//nop
|
private byte[] | getBuffer(int index)
return (byte[]) buffers.get(index);
|
private void | needNewBuffer(int newcount)
if (currentBufferIndex < buffers.size() - 1) {
//Recycling old buffer
filledBufferSum += currentBuffer.length;
currentBufferIndex++;
currentBuffer = getBuffer(currentBufferIndex);
} else {
//Creating new buffer
int newBufferSize;
if (currentBuffer == null) {
newBufferSize = newcount;
filledBufferSum = 0;
} else {
newBufferSize = Math.max(currentBuffer.length << 1,
newcount - filledBufferSum);
filledBufferSum += currentBuffer.length;
}
currentBufferIndex++;
currentBuffer = new byte[newBufferSize];
buffers.add(currentBuffer);
}
|
public synchronized void | reset()
count = 0;
filledBufferSum = 0;
currentBufferIndex = 0;
currentBuffer = getBuffer(currentBufferIndex);
|
public int | size()
return count;
|
public synchronized byte[] | toByteArray()
int remaining = count;
int pos = 0;
byte[] newbuf = new byte[count];
for (int i = 0; i < buffers.size(); i++) {
byte[] buf = getBuffer(i);
int c = Math.min(buf.length, remaining);
System.arraycopy(buf, 0, newbuf, pos, c);
pos += c;
remaining -= c;
if (remaining == 0) {
break;
}
}
return newbuf;
|
public java.lang.String | toString()
return new String(toByteArray());
|
public java.lang.String | toString(java.lang.String enc)
return new String(toByteArray(), enc);
|
public synchronized void | write(byte[] b, int off, int len)
if ((off < 0)
|| (off > b.length)
|| (len < 0)
|| ((off + len) > b.length)
|| ((off + len) < 0)) {
throw new IndexOutOfBoundsException(
Messages.getMessage("indexOutOfBoundsException00"));
} else if (len == 0) {
return;
}
int newcount = count + len;
int remaining = len;
int inBufferPos = count - filledBufferSum;
while (remaining > 0) {
int part = Math.min(remaining, currentBuffer.length - inBufferPos);
System.arraycopy(b, off + len - remaining, currentBuffer,
inBufferPos, part);
remaining -= part;
if (remaining > 0) {
needNewBuffer(newcount);
inBufferPos = 0;
}
}
count = newcount;
|
public synchronized void | write(int b)Calls the write(byte[]) method.
write(new byte[]{(byte) b}, 0, 1);
|
public synchronized void | writeTo(java.io.OutputStream out)
int remaining = count;
for (int i = 0; i < buffers.size(); i++) {
byte[] buf = getBuffer(i);
int c = Math.min(buf.length, remaining);
out.write(buf, 0, c);
remaining -= c;
if (remaining == 0) {
break;
}
}
|