< prev index next >
src/java.base/share/classes/java/io/ByteArrayOutputStream.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -67,11 +67,11 @@
/**
* 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.
+ * @throws IllegalArgumentException if size is negative.
*/
public ByteArrayOutputStream(int size) {
if (size < 0) {
throw new IllegalArgumentException("Negative initial size: "
+ size);
@@ -144,25 +144,45 @@
* 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.
+ * @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 byte array output stream.
+ *
+ * <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 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.
+ * @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);
}
@@ -245,11 +265,11 @@
*
*
* @param charsetName the name of a supported
* {@link java.nio.charset.Charset charset}
* @return String decoded from the buffer's contents.
- * @exception UnsupportedEncodingException
+ * @throws UnsupportedEncodingException
* If the named charset is not supported
* @since 1.1
*/
public synchronized String toString(String charsetName)
throws UnsupportedEncodingException
< prev index next >