• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 package java.io;
19 
20 /**
21  * Defines an interface for classes that allow reading serialized objects.
22  *
23  * @see ObjectInputStream
24  * @see ObjectOutput
25  */
26 public interface ObjectInput extends DataInput, AutoCloseable {
27     /**
28      * Indicates the number of bytes of primitive data that can be read without
29      * blocking.
30      *
31      * @return the number of bytes available.
32      * @throws IOException
33      *             if an I/O error occurs.
34      */
available()35     public int available() throws IOException;
36 
37     /**
38      * Closes this stream. Implementations of this method should free any
39      * resources used by the stream.
40      *
41      * @throws IOException
42      *             if an I/O error occurs while closing the input stream.
43      */
close()44     public void close() throws IOException;
45 
46     /**
47      * Reads a single byte from this stream and returns it as an integer in the
48      * range from 0 to 255. Returns -1 if the end of this stream has been
49      * reached. Blocks if no input is available.
50      *
51      * @return the byte read or -1 if the end of this stream has been reached.
52      * @throws IOException
53      *             if this stream is closed or another I/O error occurs.
54      */
read()55     public int read() throws IOException;
56 
57     /**
58      * Reads bytes from this stream into the byte array {@code buffer}. Blocks
59      * while waiting for input.
60      *
61      * @param buffer
62      *            the array in which to store the bytes read.
63      * @return the number of bytes read or -1 if the end of this stream has been
64      *         reached.
65      * @throws IOException
66      *             if this stream is closed or another I/O error occurs.
67      */
read(byte[] buffer)68     public int read(byte[] buffer) throws IOException;
69 
70     /**
71      * Reads at most {@code count} bytes from this stream and stores them in
72      * byte array {@code buffer} starting at offset {@code count}. Blocks while
73      * waiting for input.
74      *
75      * @param buffer
76      *            the array in which to store the bytes read.
77      * @param offset
78      *            the initial position in {@code buffer} to store the bytes read
79      *            from this stream.
80      * @param count
81      *            the maximum number of bytes to store in {@code buffer}.
82      * @return the number of bytes read or -1 if the end of this stream has been
83      *         reached.
84      * @throws IOException
85      *             if this stream is closed or another I/O error occurs.
86      */
read(byte[] buffer, int offset, int count)87     public int read(byte[] buffer, int offset, int count) throws IOException;
88 
89     /**
90      * Reads the next object from this stream.
91      *
92      * @return the object read.
93      *
94      * @throws ClassNotFoundException
95      *             if the object's class cannot be found.
96      * @throws IOException
97      *             if this stream is closed or another I/O error occurs.
98      */
readObject()99     public Object readObject() throws ClassNotFoundException, IOException;
100 
101     /**
102      * Skips {@code byteCount} bytes on this stream. Less than {@code byteCount} byte are
103      * skipped if the end of this stream is reached before the operation
104      * completes.
105      *
106      * @return the number of bytes actually skipped.
107      * @throws IOException
108      *             if this stream is closed or another I/O error occurs.
109      */
skip(long byteCount)110     public long skip(long byteCount) throws IOException;
111 }
112