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: * DataOutput is an interface which declares methods for writing typed data to a
022: * Stream. Typically, this stream can be read in by a class which implements
023: * DataInput. Types that can be written include byte, 16-bit short, 32-bit int,
024: * 32-bit float, 64-bit long, 64-bit double, byte strings, and UTF Strings.
025: *
026: * @see DataOutputStream
027: * @see RandomAccessFile
028: */
029: public interface DataOutput {
030:
031: /**
032: * Writes the entire contents of the byte array <code>buffer</code> to the
033: * OutputStream.
034: *
035: * @param buffer
036: * the buffer to be written
037: *
038: * @throws IOException
039: * If an error occurs attempting to write to this stream.
040: *
041: * @see DataInput#readFully(byte[])
042: * @see DataInput#readFully(byte[], int, int)
043: */
044: public abstract void write(byte buffer[]) throws IOException;
045:
046: /**
047: * Writes <code>count</code> <code>bytes</code> from the byte array
048: * <code>buffer</code> starting at offset <code>index</code> to the
049: * OutputStream.
050: *
051: * @param buffer
052: * the buffer to be written
053: * @param offset
054: * offset in buffer to get bytes
055: * @param count
056: * number of bytes in buffer to write
057: *
058: * @throws IOException
059: * If an error occurs attempting to write to this stream.
060: *
061: * @see DataInput#readFully(byte[])
062: * @see DataInput#readFully(byte[], int, int)
063: */
064: public abstract void write(byte buffer[], int offset, int count)
065: throws IOException;
066:
067: /**
068: * Writes the specified <code>byte</code> to the OutputStream.
069: *
070: * @param oneByte
071: * the byte to be written
072: *
073: * @throws IOException
074: * If an error occurs attempting to write to this stream.
075: *
076: * @see DataInput#readByte()
077: */
078: public abstract void write(int oneByte) throws IOException;
079:
080: /**
081: * Writes a boolean to this output stream.
082: *
083: * @param val
084: * the boolean value to write to the OutputStream
085: *
086: * @throws IOException
087: * If an error occurs attempting to write to this stream.
088: *
089: * @see DataInput#readBoolean()
090: */
091: public abstract void writeBoolean(boolean val) throws IOException;
092:
093: /**
094: * Writes a 8-bit byte to this output stream.
095: *
096: * @param val
097: * the byte value to write to the OutputStream
098: *
099: * @throws IOException
100: * If an error occurs attempting to write to this stream.
101: *
102: * @see DataInput#readByte()
103: * @see DataInput#readUnsignedByte()
104: */
105: public abstract void writeByte(int val) throws IOException;
106:
107: /**
108: * Writes the low order 8-bit bytes from a String to this output stream.
109: *
110: * @param str
111: * the String containing the bytes to write to the OutputStream
112: *
113: * @throws IOException
114: * If an error occurs attempting to write to this stream.
115: *
116: * @see DataInput#readFully(byte[])
117: * @see DataInput#readFully(byte[],int,int)
118: */
119: public abstract void writeBytes(String str) throws IOException;
120:
121: /**
122: * Writes the specified 16-bit character to the OutputStream. Only the lower
123: * 2 bytes are written with the higher of the 2 bytes written first. This
124: * represents the Unicode value of val.
125: *
126: * @param oneByte
127: * the character to be written
128: *
129: * @throws IOException
130: * If an error occurs attempting to write to this stream.
131: *
132: * @see DataInput#readChar()
133: */
134: public abstract void writeChar(int oneByte) throws IOException;
135:
136: /**
137: * Writes the specified 16-bit characters contained in str to the
138: * OutputStream. Only the lower 2 bytes of each character are written with
139: * the higher of the 2 bytes written first. This represents the Unicode
140: * value of each character in str.
141: *
142: * @param str
143: * the String whose characters are to be written.
144: *
145: * @throws IOException
146: * If an error occurs attempting to write to this stream.
147: *
148: * @see DataInput#readChar()
149: */
150: public abstract void writeChars(String str) throws IOException;
151:
152: /**
153: * Writes a 64-bit double to this output stream. The resulting output is the
154: * 8 bytes resulting from calling Double.doubleToLongBits().
155: *
156: * @param val
157: * the double to be written.
158: *
159: * @throws IOException
160: * If an error occurs attempting to write to this stream.
161: *
162: * @see DataInput#readDouble()
163: */
164: public abstract void writeDouble(double val) throws IOException;
165:
166: /**
167: * Writes a 32-bit float to this output stream. The resulting output is the
168: * 4 bytes resulting from calling Float.floatToIntBits().
169: *
170: * @param val
171: * the float to be written.
172: *
173: * @throws IOException
174: * If an error occurs attempting to write to this stream.
175: *
176: * @see DataInput#readFloat()
177: */
178: public abstract void writeFloat(float val) throws IOException;
179:
180: /**
181: * Writes a 32-bit int to this output stream. The resulting output is the 4
182: * bytes, highest order first, of val.
183: *
184: * @param val
185: * the int to be written.
186: *
187: * @throws IOException
188: * If an error occurs attempting to write to this stream.
189: *
190: * @see DataInput#readInt()
191: */
192: public abstract void writeInt(int val) throws IOException;
193:
194: /**
195: * Writes a 64-bit long to this output stream. The resulting output is the 8
196: * bytes, highest order first, of val.
197: *
198: * @param val
199: * the long to be written.
200: *
201: * @throws IOException
202: * If an error occurs attempting to write to this stream.
203: *
204: * @see DataInput#readLong()
205: */
206: public abstract void writeLong(long val) throws IOException;
207:
208: /**
209: * Writes the specified 16-bit short to the OutputStream. Only the lower 2
210: * bytes are written with the higher of the 2 bytes written first.
211: *
212: * @param val
213: * the short to be written
214: *
215: * @throws IOException
216: * If an error occurs attempting to write to this stream.
217: *
218: * @see DataInput#readShort()
219: * @see DataInput#readUnsignedShort()
220: */
221: public abstract void writeShort(int val) throws IOException;
222:
223: /**
224: * Writes the specified String out in UTF format.
225: *
226: * @param str
227: * the String to be written in UTF format.
228: *
229: * @throws IOException
230: * If an error occurs attempting to write to this stream.
231: *
232: * @see DataInput#readUTF()
233: */
234: public abstract void writeUTF(String str) throws IOException;
235: }
|