2362N/A * Copyright (c) 2000, 2006, 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 channel that can read bytes into a sequence of buffers. 0N/A * <p> A <i>scattering</i> read operation reads, in a single invocation, a 0N/A * sequence of bytes into one or more of a given sequence of buffers. 0N/A * Scattering reads are often useful when implementing network protocols or 0N/A * file formats that, for example, group data into segments consisting of one 0N/A * or more fixed-length headers followed by a variable-length body. Similar 0N/A * <i>gathering</i> write operations are defined in the {@link 0N/A * GatheringByteChannel} interface. </p> 0N/A * @author Mark Reinhold 0N/A * @author JSR-51 Expert Group 0N/A * Reads a sequence of bytes from this channel into a subsequence of the 0N/A * <p> An invocation of this method attempts to read up to <i>r</i> bytes 0N/A * from this channel, where <i>r</i> is the total number of bytes remaining 0N/A * the specified subsequence of the given buffer array, that is, 0N/A * dsts[offset].remaining() 0N/A * + dsts[offset+1].remaining() 0N/A * + ... + dsts[offset+length-1].remaining()</pre></blockquote> 0N/A * at the moment that this method is invoked. 0N/A * <p> Suppose that a byte sequence of length <i>n</i> is read, where 0N/A * <tt>0</tt> <tt><=</tt> <i>n</i> <tt><=</tt> <i>r</i>. 0N/A * Up to the first <tt>dsts[offset].remaining()</tt> bytes of this sequence 0N/A * are transferred into buffer <tt>dsts[offset]</tt>, up to the next 0N/A * <tt>dsts[offset+1].remaining()</tt> bytes are transferred into buffer 0N/A * <tt>dsts[offset+1]</tt>, and so forth, until the entire byte sequence 0N/A * is transferred into the given buffers. As many bytes as possible are 0N/A * transferred into each buffer, hence the final position of each updated 0N/A * buffer, except the last updated buffer, is guaranteed to be equal to 0N/A * that buffer's limit. 0N/A * <p> This method may be invoked at any time. If another thread has 0N/A * already initiated a read operation upon this channel, however, then an 0N/A * invocation of this method will block until the first operation is 0N/A * The buffers into which bytes are to be transferred 0N/A * The offset within the buffer array of the first buffer into 0N/A * which bytes are to be transferred; must be non-negative and no 0N/A * larger than <tt>dsts.length</tt> 0N/A * The maximum number of buffers to be accessed; must be 0N/A * non-negative and no larger than 0N/A * <tt>dsts.length</tt> - <tt>offset</tt> 0N/A * @return The number of bytes read, possibly zero, 0N/A * or <tt>-1</tt> if the channel has reached end-of-stream 0N/A * @throws IndexOutOfBoundsException 0N/A * If the preconditions on the <tt>offset</tt> and <tt>length</tt> 0N/A * parameters do not hold 0N/A * @throws NonReadableChannelException 0N/A * If this channel was not opened for reading 0N/A * @throws ClosedChannelException 0N/A * If this channel is closed 0N/A * @throws AsynchronousCloseException 0N/A * If another thread closes this channel 0N/A * while the read operation is in progress 0N/A * @throws ClosedByInterruptException 0N/A * If another thread interrupts the current thread 0N/A * while the read operation is in progress, thereby 0N/A * closing the channel and setting the current thread's 0N/A * @throws IOException 0N/A * If some other I/O error occurs 0N/A * Reads a sequence of bytes from this channel into the given buffers. 0N/A * <p> An invocation of this method of the form <tt>c.read(dsts)</tt> 0N/A * behaves in exactly the same manner as the invocation 0N/A * c.read(dsts, 0, dsts.length);</pre></blockquote> 0N/A * The buffers into which bytes are to be transferred 0N/A * @return The number of bytes read, possibly zero, 0N/A * or <tt>-1</tt> if the channel has reached end-of-stream 0N/A * @throws NonReadableChannelException 0N/A * If this channel was not opened for reading 0N/A * @throws ClosedChannelException 0N/A * If this channel is closed 0N/A * @throws AsynchronousCloseException 0N/A * If another thread closes this channel 0N/A * while the read operation is in progress 0N/A * @throws ClosedByInterruptException 0N/A * If another thread interrupts the current thread 0N/A * while the read operation is in progress, thereby 0N/A * closing the channel and setting the current thread's 0N/A * @throws IOException 0N/A * If some other I/O error occurs