/** * @see java.io.ByteArrayOutputStream#reset() */ public synchronized void reset() { count = 0; filledBufferSum = 0; currentBufferIndex = 0; currentBuffer = getBuffer(currentBufferIndex); }
/** * @see java.io.ByteArrayOutputStream#reset() */ public synchronized void reset() { count = 0; filledBufferSum = 0; currentBufferIndex = 0; currentBuffer = getBuffer(currentBufferIndex); }
/** * @see java.io.ByteArrayOutputStream#reset() */ public synchronized void reset() { count = 0; filledBufferSum = 0; currentBufferIndex = 0; currentBuffer = getBuffer(currentBufferIndex); }
/** * Write to the given output stream. * * @param out * the output stream to write to * @throws IOException * @see java.io.ByteArrayOutputStream#writeTo(OutputStream) */ public synchronized void writeTo(OutputStream out) throws IOException { 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; } } }
/** * Write to the given output stream. * * @param out * the output stream to write to * @throws IOException * @see java.io.ByteArrayOutputStream#writeTo(OutputStream) */ public synchronized void writeTo(final OutputStream out) throws IOException { 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; } } }
private void needNewBuffer(final 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); } }
/** * Write to the given output stream. * * @param out * the output stream to write to * @throws IOException * @see java.io.ByteArrayOutputStream#writeTo(OutputStream) */ public synchronized void writeTo(OutputStream out) throws IOException { 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; } } }
/** * Writes to a byte array. * * @return this is a byte array */ 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; }
/** * Writes to a byte array. * * @return this is a byte array */ 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; }
/** * Writes to a byte array. * * @return this is a byte array */ 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; }
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); } }
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); } }