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 18package java.io; 19 20/** 21 * Defines an interface for classes that allow reading serialized objects. 22 * 23 * @see ObjectInputStream 24 * @see ObjectOutput 25 */ 26public 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 */ 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 */ 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 */ 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. Returns the number of bytes read, 60 * or -1 if the end of this stream has been reached. 61 * 62 * @throws IOException 63 * if this stream is closed or another I/O error occurs. 64 */ 65 public int read(byte[] buffer) throws IOException; 66 67 /** 68 * Reads up to {@code byteCount} bytes from this stream and stores them in 69 * byte array {@code buffer} starting at offset {@code byteOffset}. Blocks while 70 * waiting for input. Returns the number of bytes read or -1 if the end of this stream has been 71 * reached. 72 * 73 * @throws IOException 74 * if this stream is closed or another I/O error occurs. 75 */ 76 public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException; 77 78 /** 79 * Reads the next object from this stream. 80 * 81 * @return the object read. 82 * 83 * @throws ClassNotFoundException 84 * if the object's class cannot be found. 85 * @throws IOException 86 * if this stream is closed or another I/O error occurs. 87 */ 88 public Object readObject() throws ClassNotFoundException, IOException; 89 90 /** 91 * Skips {@code byteCount} bytes on this stream. Less than {@code byteCount} byte are 92 * skipped if the end of this stream is reached before the operation 93 * completes. 94 * 95 * @return the number of bytes actually skipped. 96 * @throws IOException 97 * if this stream is closed or another I/O error occurs. 98 */ 99 public long skip(long byteCount) throws IOException; 100} 101