< prev index next >

src/java.base/share/classes/java/io/ByteArrayOutputStream.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 55,77 **** * The number of valid bytes in the buffer. */ protected int count; /** ! * Creates a new byte array output stream. The buffer capacity is * initially 32 bytes, though its size increases if necessary. */ public ByteArrayOutputStream() { this(32); } /** ! * 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); --- 55,77 ---- * The number of valid bytes in the buffer. */ protected int count; /** ! * Creates a new {@code ByteArrayOutputStream}. The buffer capacity is * initially 32 bytes, though its size increases if necessary. */ public ByteArrayOutputStream() { this(32); } /** ! * Creates a new {@code ByteArrayOutputStream}, with a buffer capacity of * the specified size, in bytes. * * @param size the initial size. ! * @throws IllegalArgumentException if size is negative. */ public ByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException("Negative initial size: " + size);
*** 127,137 **** Integer.MAX_VALUE : MAX_ARRAY_SIZE; } /** ! * Writes the specified byte to this byte array output stream. * * @param b the byte to be written. */ public synchronized void write(int b) { ensureCapacity(count + 1); --- 127,137 ---- Integer.MAX_VALUE : MAX_ARRAY_SIZE; } /** ! * Writes the specified byte to this {@code ByteArrayOutputStream}. * * @param b the byte to be written. */ public synchronized void write(int b) { ensureCapacity(count + 1);
*** 139,176 **** count += 1; } /** * Writes {@code len} bytes from the specified byte array ! * starting at offset {@code off} to this byte array output stream. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. */ public synchronized void write(byte b[], int off, int len) { Objects.checkFromIndexSize(off, len, b.length); ensureCapacity(count + len); System.arraycopy(b, off, buf, count, len); count += len; } /** ! * Writes the complete contents of this byte array output stream to * the specified output stream argument, as if by calling the output * stream's write method using {@code out.write(buf, 0, count)}. * * @param out the output stream to which to write the data. ! * @exception IOException if an I/O error occurs. */ public synchronized void writeTo(OutputStream out) throws IOException { out.write(buf, 0, count); } /** ! * Resets the {@code count} field of this byte array output ! * stream to zero, so that all currently accumulated output in the * output stream is discarded. The output stream can be used again, * reusing the already allocated buffer space. * * @see java.io.ByteArrayInputStream#count */ --- 139,196 ---- count += 1; } /** * Writes {@code len} bytes from the specified byte array ! * starting at offset {@code off} to this {@code ByteArrayOutputStream}. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. + * @throws NullPointerException if {@code b} is {@code null}. + * @throws IndexOutOfBoundsException if {@code off} is negative, + * {@code len} is negative, or {@code len} is greater than + * {@code b.length - off} */ public synchronized void write(byte b[], int off, int len) { Objects.checkFromIndexSize(off, len, b.length); ensureCapacity(count + len); System.arraycopy(b, off, buf, count, len); count += len; } /** ! * Writes the complete contents of the specified byte array ! * to this {@code ByteArrayOutputStream}. ! * ! * <p> This method is equivalent to {@link #write(byte[],int,int) ! * write(b ,0, b.length)}. ! * ! * @param b the data. ! * @throws NullPointerException if {@code b} is {@code null}. ! * @since 11 ! */ ! public void writeBytes(byte b[]) { ! write(b, 0, b.length); ! } ! ! /** ! * Writes the complete contents of this {@code ByteArrayOutputStream} to * the specified output stream argument, as if by calling the output * stream's write method using {@code out.write(buf, 0, count)}. * * @param out the output stream to which to write the data. ! * @throws NullPointerException if {@code out} is {@code null}. ! * @throws IOException if an I/O error occurs. */ public synchronized void writeTo(OutputStream out) throws IOException { out.write(buf, 0, count); } /** ! * Resets the {@code count} field of this {@code ByteArrayOutputStream} ! * to zero, so that all currently accumulated output in the * output stream is discarded. The output stream can be used again, * reusing the already allocated buffer space. * * @see java.io.ByteArrayInputStream#count */
*** 245,255 **** * * * @param charsetName the name of a supported * {@link java.nio.charset.Charset charset} * @return String decoded from the buffer's contents. ! * @exception UnsupportedEncodingException * If the named charset is not supported * @since 1.1 */ public synchronized String toString(String charsetName) throws UnsupportedEncodingException --- 265,275 ---- * * * @param charsetName the name of a supported * {@link java.nio.charset.Charset charset} * @return String decoded from the buffer's contents. ! * @throws UnsupportedEncodingException * If the named charset is not supported * @since 1.1 */ public synchronized String toString(String charsetName) throws UnsupportedEncodingException
< prev index next >