/** * Creates a new byte array output stream, with a buffer capacity of the specified size, in * bytes. * * @param size * the initial size. * @exception IllegalArgumentException * if size is negative. */ public ByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException("Negative initial size: " + size); } needNewBuffer(size); }
/** * Creates a new byte array output stream, with a buffer capacity of the specified size, in * bytes. * * @param size * the initial size. * @exception IllegalArgumentException * if size is negative. */ public ByteArrayOutputStream(final int size) { if (size < 0) { throw new IllegalArgumentException("Negative initial size: " + size); } needNewBuffer(size); }
/** * Creates a new byte array output stream, with a buffer capacity of the specified size, in * bytes. * * @param size * the initial size. * @exception IllegalArgumentException * if size is negative. */ public ByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException("Negative initial size: " + size); } needNewBuffer(size); }
/** * @see java.io.OutputStream#write(byte[], int, int) */ 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(); } 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; }
if (remaining > 0) needNewBuffer(newcount); inBufferPos = 0;
if (remaining > 0) needNewBuffer(newcount); inBufferPos = 0;