0N/A/*
2362N/A * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
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
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.nio.channels;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.nio.ByteBuffer;
0N/A
0N/A
0N/A/**
0N/A * A channel that can read bytes.
0N/A *
0N/A * <p> Only one read operation upon a readable channel may be in progress at
0N/A * any given time. If one thread initiates a read operation upon a channel
0N/A * then any other thread that attempts to initiate another read operation will
0N/A * block until the first operation is complete. Whether or not other kinds of
0N/A * I/O operations may proceed concurrently with a read operation depends upon
0N/A * the type of the channel. </p>
0N/A *
0N/A *
0N/A * @author Mark Reinhold
0N/A * @author JSR-51 Expert Group
0N/A * @since 1.4
0N/A */
0N/A
0N/Apublic interface ReadableByteChannel extends Channel {
0N/A
0N/A /**
0N/A * Reads a sequence of bytes from this channel into the given buffer.
0N/A *
0N/A * <p> An attempt is made to read up to <i>r</i> bytes from the channel,
0N/A * where <i>r</i> is the number of bytes remaining in the buffer, that is,
0N/A * <tt>dst.remaining()</tt>, at the moment this method is invoked.
0N/A *
0N/A * <p> Suppose that a byte sequence of length <i>n</i> is read, where
0N/A * <tt>0</tt>&nbsp;<tt>&lt;=</tt>&nbsp;<i>n</i>&nbsp;<tt>&lt;=</tt>&nbsp;<i>r</i>.
0N/A * This byte sequence will be transferred into the buffer so that the first
0N/A * byte in the sequence is at index <i>p</i> and the last byte is at index
0N/A * <i>p</i>&nbsp;<tt>+</tt>&nbsp;<i>n</i>&nbsp;<tt>-</tt>&nbsp;<tt>1</tt>,
0N/A * where <i>p</i> is the buffer's position at the moment this method is
0N/A * invoked. Upon return the buffer's position will be equal to
0N/A * <i>p</i>&nbsp;<tt>+</tt>&nbsp;<i>n</i>; its limit will not have changed.
0N/A *
0N/A * <p> A read operation might not fill the buffer, and in fact it might not
0N/A * read any bytes at all. Whether or not it does so depends upon the
0N/A * nature and state of the channel. A socket channel in non-blocking mode,
0N/A * for example, cannot read any more bytes than are immediately available
0N/A * from the socket's input buffer; similarly, a file channel cannot read
0N/A * any more bytes than remain in the file. It is guaranteed, however, that
0N/A * if a channel is in blocking mode and there is at least one byte
0N/A * remaining in the buffer then this method will block until at least one
0N/A * byte is read.
0N/A *
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 * complete. </p>
0N/A *
0N/A * @param dst
0N/A * The buffer into which bytes are to be transferred
0N/A *
0N/A * @return The number of bytes read, possibly zero, or <tt>-1</tt> if the
0N/A * channel has reached end-of-stream
0N/A *
0N/A * @throws NonReadableChannelException
0N/A * If this channel was not opened for reading
0N/A *
0N/A * @throws ClosedChannelException
0N/A * If this channel is closed
0N/A *
0N/A * @throws AsynchronousCloseException
0N/A * If another thread closes this channel
0N/A * while the read operation is in progress
0N/A *
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 * interrupt status
0N/A *
0N/A * @throws IOException
0N/A * If some other I/O error occurs
0N/A */
0N/A public int read(ByteBuffer dst) throws IOException;
0N/A
0N/A}