Source for java.io.ObjectInput

   1: /* ObjectInput.java -- Read object data from a stream
   2:    Copyright (C) 1998,2003 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.io;
  40: 
  41: /**
  42:   * This interface extends the <code>DataInput</code> interface to provide a
  43:   * facility to read objects as well as primitive types from a stream.  It
  44:   * also has methods that allow input to be done in a manner similar to
  45:   * <code>InputStream</code>
  46:   *
  47:   * @author Aaron M. Renn (arenn@urbanophile.com)
  48:   *
  49:   * @see DataInput
  50:   */
  51: public interface ObjectInput
  52:   extends DataInput, AutoCloseable
  53: {
  54:   /**
  55:     * This method returns the number of bytes that can be read without
  56:     * blocking.
  57:     *
  58:     * @return The number of bytes available before blocking
  59:     *
  60:     * @exception IOException If an error occurs
  61:     */
  62:   int available() throws IOException;
  63: 
  64:   /**
  65:     * This method reading a byte of data from a stream.  It returns that byte
  66:     * as an <code>int</code>.  This method blocks if no data is available
  67:     * to be read.
  68:     *
  69:     * @return The byte of data read
  70:     *
  71:     * @exception IOException If an error occurs
  72:     */
  73:   int read() throws IOException;
  74: 
  75:   /**
  76:     * This method reads raw bytes and stores them them a byte array buffer.
  77:     * Note that this method will block if no data is available.  However,
  78:     * it will not necessarily block until it fills the entire buffer.  That is,
  79:     * a "short count" is possible.
  80:     *
  81:     * @param buf The byte array to receive the data read
  82:     *
  83:     * @return The actual number of bytes read or -1 if end of stream
  84:     *
  85:     * @exception IOException If an error occurs
  86:     */
  87:   int read(byte[] buf) throws IOException;
  88: 
  89:   /**
  90:     * This method reads raw bytes and stores them in a byte array buffer
  91:     * <code>buf</code> starting at position <code>offset</code> into the
  92:     * buffer.  A
  93:     * maximum of <code>len</code> bytes will be read.  Note that this method
  94:     * blocks if no data is available, but will not necessarily block until
  95:     * it can read <code>len</code> bytes of data.  That is, a "short count" is
  96:     * possible.
  97:     *
  98:     * @param buf The byte array to receive the data read
  99:     * @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: }