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