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: * DataInput is an interface which declares methods for reading in typed data
022: * from a Stream. Typically, this stream has been written by a class which
023: * implements DataOutput. Types that can be read include byte, 16-bit short,
024: * 32-bit int, 32-bit float, 64-bit long, 64-bit double, byte strings, and UTF
025: * Strings.
026: *
027: * @see DataInputStream
028: * @see RandomAccessFile
029: */
030: public interface DataInput {
031: /**
032: * Reads a boolean from this stream.
033: *
034: * @return the next boolean value from the source stream.
035: *
036: * @throws IOException
037: * If a problem occurs reading from this stream.
038: *
039: * @see DataOutput#writeBoolean(boolean)
040: */
041: public abstract boolean readBoolean() throws IOException;
042:
043: /**
044: * Reads an 8-bit byte value from this stream.
045: *
046: * @return the next byte value from the source stream.
047: *
048: * @throws IOException
049: * If a problem occurs reading from this stream.
050: *
051: * @see DataOutput#writeByte(int)
052: */
053: public abstract byte readByte() throws IOException;
054:
055: /**
056: * Reads a 16-bit character value from this stream.
057: *
058: * @return the next <code>char</code> value from the source stream.
059: *
060: * @throws IOException
061: * If a problem occurs reading from this stream.
062: *
063: * @see DataOutput#writeChar(int)
064: */
065: public abstract char readChar() throws IOException;
066:
067: /**
068: * Reads a 64-bit <code>double</code> value from this stream.
069: *
070: * @return the next <code>double</code> value from the source stream.
071: *
072: * @throws IOException
073: * If a problem occurs reading from this stream.
074: *
075: * @see DataOutput#writeDouble(double)
076: */
077: public abstract double readDouble() throws IOException;
078:
079: /**
080: * Reads a 32-bit <code>float</code> value from this stream.
081: *
082: * @return the next <code>float</code> value from the source stream.
083: *
084: * @throws IOException
085: * If a problem occurs reading from this stream.
086: *
087: * @see DataOutput#writeFloat(float)
088: */
089: public abstract float readFloat() throws IOException;
090:
091: /**
092: * Reads bytes from this stream into the byte array <code>buffer</code>.
093: * This method will block until <code>buffer.length</code> number of bytes
094: * have been read.
095: *
096: * @param buffer
097: * the buffer to read bytes into
098: *
099: * @throws IOException
100: * If a problem occurs reading from this stream.
101: *
102: * @see DataOutput#write(byte[])
103: * @see DataOutput#write(byte[], int, int)
104: */
105: public abstract void readFully(byte[] buffer) throws IOException;
106:
107: /**
108: * Read bytes from this stream and stores them in byte array
109: * <code>buffer</code> starting at offset <code>offset</code>. This
110: * method blocks until <code>count</code> number of bytes have been read.
111: *
112: * @param buffer
113: * the byte array in which to store the read bytes.
114: * @param offset
115: * the offset in <code>buffer</code> to store the read bytes.
116: * @param count
117: * the maximum number of bytes to store in <code>buffer</code>.
118: *
119: * @throws IOException
120: * If a problem occurs reading from this stream.
121: *
122: * @see DataOutput#write(byte[])
123: * @see DataOutput#write(byte[], int, int)
124: */
125: public abstract void readFully(byte[] buffer, int offset, int count)
126: throws IOException;
127:
128: /**
129: * Reads a 32-bit integer value from this stream.
130: *
131: * @return the next <code>int</code> value from the source stream.
132: *
133: * @throws IOException
134: * If a problem occurs reading from this stream.
135: *
136: * @see DataOutput#writeInt(int)
137: */
138: public abstract int readInt() throws IOException;
139:
140: /**
141: * Answers a <code>String</code> representing the next line of text
142: * available in this BufferedReader. A line is represented by 0 or more
143: * characters followed by <code>'\n'</code>, <code>'\r'</code>,
144: * <code>"\n\r"</code> or end of stream. The <code>String</code> does
145: * not include the newline sequence.
146: *
147: * @return the contents of the line or null if no characters were read
148: * before end of stream.
149: *
150: * @throws IOException
151: * If a problem occurs reading from this stream.
152: */
153: public abstract String readLine() throws IOException;
154:
155: /**
156: * Reads a 64-bit <code>long</code> value from this stream.
157: *
158: * @return the next <code>long</code> value from the source stream.
159: *
160: * @throws IOException
161: * If a problem occurs reading from this stream.
162: *
163: * @see DataOutput#writeLong(long)
164: */
165: public abstract long readLong() throws IOException;
166:
167: /**
168: * Reads a 16-bit <code>short</code> value from this stream.
169: *
170: * @return the next <code>short</code> value from the source stream.
171: *
172: * @throws IOException
173: * If a problem occurs reading from this stream.
174: *
175: * @see DataOutput#writeShort(int)
176: */
177: public abstract short readShort() throws IOException;
178:
179: /**
180: * Reads an unsigned 8-bit <code>byte</code> value from this stream and
181: * returns it as an int.
182: *
183: * @return the next unsigned byte value from the source stream.
184: *
185: * @throws IOException
186: * If a problem occurs reading from this stream.
187: *
188: * @see DataOutput#writeByte(int)
189: */
190: public abstract int readUnsignedByte() throws IOException;
191:
192: /**
193: * Reads a 16-bit unsigned <code>short</code> value from this stream and
194: * returns it as an int.
195: *
196: * @return the next unsigned <code>short</code> value from the source
197: * stream.
198: *
199: * @throws IOException
200: * If a problem occurs reading from this stream.
201: *
202: * @see DataOutput#writeShort(int)
203: */
204: public abstract int readUnsignedShort() throws IOException;
205:
206: /**
207: * Reads a UTF format String from this Stream.
208: *
209: * @return the next UTF String from the source stream.
210: *
211: * @throws IOException
212: * If a problem occurs reading from this stream.
213: *
214: * @see DataOutput#writeUTF(java.lang.String)
215: */
216: public abstract String readUTF() throws IOException;
217:
218: /**
219: * Skips <code>count</code> number of bytes in this stream. Subsequent
220: * <code>read()</code>'s will not return these bytes unless
221: * <code>reset()</code> is used.
222: *
223: * @param count
224: * the number of bytes to skip.
225: * @return the number of bytes actually skipped.
226: *
227: * @throws IOException
228: * If a problem occurs reading from this stream.
229: */
230: public abstract int skipBytes(int count) throws IOException;
231: }
|