01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package java.nio.channels;
18:
19: import java.io.IOException;
20: import java.nio.ByteBuffer;
21:
22: /**
23: * A ReadableByteChannel is a type of Channel that can read bytes.
24: * <p>
25: * Reads are synchronous on a ReadableByteChannel, that is, if a read is already
26: * in progress on the channel then subsequent reads will block until the first
27: * read completes. It is undefined whether non-read operations will block.
28: */
29: public interface ReadableByteChannel extends Channel {
30:
31: /**
32: * Reads bytes from the channel into the given buffer.
33: * <p>
34: * The maximum number of bytes that will be read is the
35: * <code>remaining()</code> number of bytes in the buffer when the method
36: * invoked. The bytes will be read into the buffer starting at the buffer's
37: * <code>position</code>.
38: * </p>
39: * <p>
40: * The call may block if other threads are also attempting to read on the
41: * same channel.
42: * </p>
43: * <p>
44: * Upon completion, the buffer's <code>position()</code> is updated to the
45: * end of the bytes that were read. The buffer's <code>limit()</code> is
46: * unmodified.
47: * </p>
48: *
49: * @param buffer
50: * the byte buffer to receive the bytes.
51: * @return the number of bytes actually read.
52: * @throws NonReadableChannelException
53: * if the channel was not opened for reading.
54: * @throws ClosedChannelException
55: * if the channel was already closed.
56: * @throws AsynchronousCloseException
57: * if another thread closes the channel during the read.
58: * @throws ClosedByInterruptException
59: * if another thread interrupt the calling thread during the
60: * read.
61: * @throws IOException
62: * another IO exception occurs, details are in the message.
63: */
64: public int read(ByteBuffer buffer) throws IOException;
65: }
|