001/* ObjectInput.java -- Read object data from a stream 002 Copyright (C) 1998,2003 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.io; 040 041/** 042 * This interface extends the <code>DataInput</code> interface to provide a 043 * facility to read objects as well as primitive types from a stream. It 044 * also has methods that allow input to be done in a manner similar to 045 * <code>InputStream</code> 046 * 047 * @author Aaron M. Renn (arenn@urbanophile.com) 048 * 049 * @see DataInput 050 */ 051public interface ObjectInput 052 extends DataInput, AutoCloseable 053{ 054 /** 055 * This method returns the number of bytes that can be read without 056 * blocking. 057 * 058 * @return The number of bytes available before blocking 059 * 060 * @exception IOException If an error occurs 061 */ 062 int available() throws IOException; 063 064 /** 065 * This method reading a byte of data from a stream. It returns that byte 066 * as an <code>int</code>. This method blocks if no data is available 067 * to be read. 068 * 069 * @return The byte of data read 070 * 071 * @exception IOException If an error occurs 072 */ 073 int read() throws IOException; 074 075 /** 076 * This method reads raw bytes and stores them them a byte array buffer. 077 * Note that this method will block if no data is available. However, 078 * it will not necessarily block until it fills the entire buffer. That is, 079 * a "short count" is possible. 080 * 081 * @param buf The byte array to receive the data read 082 * 083 * @return The actual number of bytes read or -1 if end of stream 084 * 085 * @exception IOException If an error occurs 086 */ 087 int read(byte[] buf) throws IOException; 088 089 /** 090 * This method reads raw bytes and stores them in a byte array buffer 091 * <code>buf</code> starting at position <code>offset</code> into the 092 * buffer. A 093 * maximum of <code>len</code> bytes will be read. Note that this method 094 * blocks if no data is available, but will not necessarily block until 095 * it can read <code>len</code> bytes of data. That is, a "short count" is 096 * possible. 097 * 098 * @param buf The byte array to receive the data read 099 * @param offset The offset into <code>buf</code> to start storing data 100 * @param len The maximum number of bytes to read 101 * 102 * @return The actual number of bytes read or -1 if end of stream 103 * 104 * @exception IOException If an error occurs 105 */ 106 int read(byte[] buf, int offset, int len) throws IOException; 107 108 /** 109 * Reads an object instance and returns it. If the class for the object 110 * being read cannot be found, then a <code>ClassNotFoundException</code> 111 * will be thrown. 112 * 113 * @return The object instance that was read 114 * 115 * @exception ClassNotFoundException If a class for the object cannot be 116 * found 117 * @exception IOException If any other error occurs 118 */ 119 Object readObject() 120 throws ClassNotFoundException, IOException; 121 122 /** 123 * This method causes the specified number of bytes to be read and 124 * discarded. It is possible that fewer than the requested number of bytes 125 * will actually be skipped. 126 * 127 * @param numBytes The number of bytes to skip 128 * 129 * @return The actual number of bytes skipped 130 * 131 * @exception IOException If an error occurs 132 */ 133 long skip(long numBytes) throws IOException; 134 135 /** 136 * This method closes the input source 137 * 138 * @exception IOException If an error occurs 139 */ 140 void close() throws IOException; 141}