3261N/A * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A <code>ByteArrayInputStream</code> contains 0N/A * an internal buffer that contains bytes that 0N/A * may be read from the stream. An internal 0N/A * counter keeps track of the next byte to 0N/A * be supplied by the <code>read</code> method. 0N/A * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in 0N/A * this class can be called after the stream has been closed without 0N/A * generating an <tt>IOException</tt>. 0N/A * @author Arthur van Hoff 0N/A * @see java.io.StringBufferInputStream 0N/A * An array of bytes that was provided 0N/A * by the creator of the stream. Elements <code>buf[0]</code> 0N/A * through <code>buf[count-1]</code> are the 0N/A * only bytes that can ever be read from the 0N/A * stream; element <code>buf[pos]</code> is 0N/A * the next byte to be read. 0N/A * The index of the next character to read from the input stream buffer. 0N/A * This value should always be nonnegative 0N/A * and not larger than the value of <code>count</code>. 0N/A * The next byte to be read from the input stream buffer 0N/A * will be <code>buf[pos]</code>. 0N/A * The currently marked position in the stream. 0N/A * ByteArrayInputStream objects are marked at position zero by 0N/A * default when constructed. They may be marked at another 0N/A * position within the buffer by the <code>mark()</code> method. 0N/A * The current buffer position is set to this point by the 0N/A * <code>reset()</code> method. 0N/A * If no mark has been set, then the value of mark is the offset 0N/A * passed to the constructor (or 0 if the offset was not supplied). 0N/A * The index one greater than the last valid character in the input 0N/A * This value should always be nonnegative 0N/A * and not larger than the length of <code>buf</code>. 0N/A * It is one greater than the position of 0N/A * the last byte within <code>buf</code> that 0N/A * can ever be read from the input stream buffer. 0N/A * Creates a <code>ByteArrayInputStream</code> 0N/A * so that it uses <code>buf</code> as its 0N/A * The buffer array is not copied. 0N/A * The initial value of <code>pos</code> 0N/A * is <code>0</code> and the initial value 0N/A * of <code>count</code> is the length of 0N/A * @param buf the input buffer. 0N/A * Creates <code>ByteArrayInputStream</code> 0N/A * that uses <code>buf</code> as its 0N/A * buffer array. The initial value of <code>pos</code> 0N/A * is <code>offset</code> and the initial value 0N/A * of <code>count</code> is the minimum of <code>offset+length</code> 0N/A * and <code>buf.length</code>. 0N/A * The buffer array is not copied. The buffer's mark is 0N/A * set to the specified offset. 0N/A * @param buf the input buffer. 0N/A * @param offset the offset in the buffer of the first byte to read. 0N/A * @param length the maximum number of bytes to read from the buffer. 0N/A * Reads the next byte of data from this input stream. The value 0N/A * byte is returned as an <code>int</code> in the range 0N/A * <code>0</code> to <code>255</code>. If no byte is available 0N/A * because the end of the stream has been reached, the value 0N/A * <code>-1</code> is returned. 0N/A * This <code>read</code> method 0N/A * @return the next byte of data, or <code>-1</code> if the end of the 0N/A * stream has been reached. 0N/A * Reads up to <code>len</code> bytes of data into an array of bytes 0N/A * from this input stream. 0N/A * If <code>pos</code> equals <code>count</code>, 0N/A * then <code>-1</code> is returned to indicate 0N/A * end of file. Otherwise, the number <code>k</code> 0N/A * of bytes read is equal to the smaller of 0N/A * <code>len</code> and <code>count-pos</code>. 0N/A * If <code>k</code> is positive, then bytes 0N/A * <code>buf[pos]</code> through <code>buf[pos+k-1]</code> 0N/A * are copied into <code>b[off]</code> through 0N/A * <code>b[off+k-1]</code> in the manner performed 0N/A * by <code>System.arraycopy</code>. The 0N/A * value <code>k</code> is added into <code>pos</code> 0N/A * and <code>k</code> is returned. 0N/A * This <code>read</code> method cannot block. 0N/A * @param b the buffer into which the data is read. 0N/A * @param off the start offset in the destination array <code>b</code> 0N/A * @param len the maximum number of bytes read. 0N/A * @return the total number of bytes read into the buffer, or 0N/A * <code>-1</code> if there is no more data because the end of 0N/A * the stream has been reached. 0N/A * @exception NullPointerException If <code>b</code> is <code>null</code>. 0N/A * @exception IndexOutOfBoundsException If <code>off</code> is negative, 0N/A * <code>len</code> is negative, or <code>len</code> is greater than 0N/A * <code>b.length - off</code> 0N/A * Skips <code>n</code> bytes of input from this input stream. Fewer 0N/A * bytes might be skipped if the end of the input stream is reached. 0N/A * The actual number <code>k</code> 0N/A * of bytes to be skipped is equal to the smaller 0N/A * of <code>n</code> and <code>count-pos</code>. 0N/A * The value <code>k</code> is added into <code>pos</code> 0N/A * and <code>k</code> is returned. 0N/A * @param n the number of bytes to be skipped. 0N/A * @return the actual number of bytes skipped. 0N/A public synchronized long skip(
long n) {
0N/A * Returns the number of remaining bytes that can be read (or skipped over) 0N/A * from this input stream. 0N/A * The value returned is <code>count - pos</code>, 0N/A * which is the number of bytes remaining to be read from the input buffer. 0N/A * @return the number of remaining bytes that can be read (or skipped 0N/A * over) from this input stream without blocking. 0N/A * Tests if this <code>InputStream</code> supports mark/reset. The 0N/A * <code>markSupported</code> method of <code>ByteArrayInputStream</code> 0N/A * always returns <code>true</code>. 0N/A * Set the current marked position in the stream. 0N/A * ByteArrayInputStream objects are marked at position zero by 0N/A * default when constructed. They may be marked at another 0N/A * position within the buffer by this method. 0N/A * If no mark has been set, then the value of the mark is the 0N/A * offset passed to the constructor (or 0 if the offset was not 0N/A * <p> Note: The <code>readAheadLimit</code> for this class 0N/A * Resets the buffer to the marked position. The marked position 0N/A * is 0 unless another position was marked or an offset was specified 0N/A * in the constructor. 0N/A * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in 0N/A * this class can be called after the stream has been closed without 0N/A * generating an <tt>IOException</tt>.