325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * It works in a way similar to {@link ByteArrayOutputStream} but 325N/A * this class works better in the following ways: 325N/A * <li>no synchronization 325N/A * <li>offers a {@link #newInputStream()} that creates a new {@link InputStream} 325N/A * that won't cause buffer reallocation. 325N/A * <li>less parameter correctness checking 325N/A * <li>offers a {@link #write(InputStream)} method that reads the entirety of the 325N/A * given {@link InputStream} without using a temporary buffer. 325N/A * @author Kohsuke Kawaguchi 325N/A * The buffer where data is stored. 325N/A * The number of valid bytes in the buffer. 325N/A * Creates a new byte array output stream. The buffer capacity is 325N/A * initially 32 bytes, though its size increases if necessary. 325N/A * Creates a new byte array output stream, with a buffer capacity of 325N/A * the specified size, in bytes. 325N/A * @param size the initial size. 325N/A * @throws IllegalArgumentException if size is negative. 325N/A * Reads all the data of the given {@link InputStream} and appends them 325N/A * if the read operation fails with an {@link IOException}. 325N/A // Instead of writing out.write(buf, 0, count) 325N/A // Writing it in chunks that would help larger payloads 325N/A // Also if out is System.out on windows, it doesn't show on the console 325N/A * Gets the <b>copy</b> of exact-size byte[] that represents the written data. 325N/A * Since this method needs to allocate a new byte[], this method will be costly. 325N/A * this method causes a buffer reallocation. Use it only when 325N/A * Gets the underlying buffer that this {@link ByteArrayBuffer} uses. 325N/A * It's never small than its {@link #size()}. 325N/A * Creates a new {@link InputStream} that reads from this buffer. 325N/A * Creates a new {@link InputStream} that reads a part of this bfufer. 325N/A * Decodes the contents of this buffer by the default encoding 325N/A * and returns it as a string. 325N/A * Meant to aid debugging, but no more.