Path: blob/master/src/java.base/share/classes/java/io/ObjectInput.java
41152 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.io;2627/**28* ObjectInput extends the DataInput interface to include the reading of29* objects. DataInput includes methods for the input of primitive types,30* ObjectInput extends that interface to include objects, arrays, and Strings.31*32* @see java.io.InputStream33* @see java.io.ObjectOutputStream34* @see java.io.ObjectInputStream35* @since 1.136*/37public interface ObjectInput extends DataInput, AutoCloseable {38/**39* Read and return an object. The class that implements this interface40* defines where the object is "read" from.41*42* @return the object read from the stream43* @throws java.lang.ClassNotFoundException If the class of a serialized44* object cannot be found.45* @throws IOException If any of the usual Input/Output46* related exceptions occur.47*/48public Object readObject()49throws ClassNotFoundException, IOException;5051/**52* Reads a byte of data. This method will block if no input is53* available.54* @return the byte read, or -1 if the end of the55* stream is reached.56* @throws IOException If an I/O error has occurred.57*/58public int read() throws IOException;5960/**61* Reads into an array of bytes. This method will62* block until some input is available.63* @param b the buffer into which the data is read64* @return the actual number of bytes read, -1 is65* returned when the end of the stream is reached.66* @throws IOException If an I/O error has occurred.67*/68public int read(byte b[]) throws IOException;6970/**71* Reads into an array of bytes. This method will72* block until some input is available.73* @param b the buffer into which the data is read74* @param off the start offset of the data75* @param len the maximum number of bytes read76* @return the actual number of bytes read, -1 is77* returned when the end of the stream is reached.78* @throws IOException If an I/O error has occurred.79*/80public int read(byte b[], int off, int len) throws IOException;8182/**83* Skips n bytes of input.84* @param n the number of bytes to be skipped85* @return the actual number of bytes skipped.86* @throws IOException If an I/O error has occurred.87*/88public long skip(long n) throws IOException;8990/**91* Returns the number of bytes that can be read92* without blocking.93* @return the number of available bytes.94* @throws IOException If an I/O error has occurred.95*/96public int available() throws IOException;9798/**99* Closes the input stream. Must be called100* to release any resources associated with101* the stream.102* @throws IOException If an I/O error has occurred.103*/104public void close() throws IOException;105}106107108