001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.io;
019:
020: /**
021: * Streams to be used with serialization to read objects must implement this
022: * interface. ObjectInputStream is one example.
023: *
024: * @see ObjectInputStream
025: * @see ObjectOutput
026: */
027: public interface ObjectInput extends DataInput {
028: /**
029: * Answers a int representing then number of bytes of primitive data that
030: * are available.
031: *
032: * @return int the number of primitive bytes available.
033: *
034: * @throws IOException
035: * If an error occurs in this ObjectInput.
036: */
037: public int available() throws IOException;
038:
039: /**
040: * Close this ObjectInput. Concrete implementations of this class should
041: * free any resources during close.
042: *
043: * @throws IOException
044: * If an error occurs attempting to close this ObjectInput.
045: */
046: public void close() throws IOException;
047:
048: /**
049: * Reads a single byte from this ObjectInput and returns the result as an
050: * int. The low-order byte is returned or -1 of the end of stream was
051: * encountered.
052: *
053: * @return int The byte read or -1 if end of ObjectInput.
054: *
055: * @throws IOException
056: * If the ObjectInput is already closed or another IOException
057: * occurs.
058: */
059: public int read() throws IOException;
060:
061: /**
062: * Reads bytes from the <code>ObjectInput</code> and stores them in byte
063: * array <code>buffer</code>. Blocks while waiting for input.
064: *
065: * @param buffer
066: * the array in which to store the read bytes.
067: * @return how many bytes were read or <code>-1</code> if encountered end
068: * of <code>ObjectInput</code>.
069: *
070: * @throws IOException
071: * If the <code>ObjectInput</code> is already closed or
072: * another IOException occurs.
073: */
074: public int read(byte[] buffer) throws IOException;
075:
076: /**
077: * Reads at most <code>count</code> bytes from the ObjectInput and stores
078: * them in byte array <code>buffer</code> starting at offset
079: * <code>count</code>. Answer the number of bytes actually read or -1 if
080: * no bytes were read and end of ObjectInput was encountered.
081: *
082: * @param buffer
083: * the byte array in which to store the read bytes.
084: * @param offset
085: * the offset in <code>buffer</code> to store the read bytes.
086: * @param count
087: * the maximum number of bytes to store in <code>buffer</code>.
088: * @return the number of bytes actually read or -1 if end of ObjectInput.
089: *
090: * @throws IOException
091: * If the ObjectInput is already closed or another IOException
092: * occurs.
093: */
094: public int read(byte[] buffer, int offset, int count)
095: throws IOException;
096:
097: /**
098: * Reads the next object from this ObjectInput.
099: *
100: * @return the next object read from this ObjectInput
101: *
102: * @throws IOException
103: * If an error occurs attempting to read from this ObjectInput.
104: * @throws ClassNotFoundException
105: * If the object's class cannot be found
106: */
107: public Object readObject() throws ClassNotFoundException,
108: IOException;
109:
110: /**
111: * Skips <code>toSkip</code> number of bytes in this ObjectInput.
112: * Subsequent <code>read()</code>'s will not return these bytes.
113: *
114: * @param toSkip
115: * the number of bytes to skip.
116: * @return the number of bytes actually skipped.
117: *
118: * @throws IOException
119: * If the ObjectInput is already closed or another IOException
120: * occurs.
121: */
122: public long skip(long toSkip) throws IOException;
123: }
|