Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/io/DataOutput.java
41152 views
1
/*
2
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package java.io;
27
28
/**
29
* The {@code DataOutput} interface provides
30
* for converting data from any of the Java
31
* primitive types to a series of bytes and
32
* writing these bytes to a binary stream.
33
* There is also a facility for converting
34
* a {@code String} into
35
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
36
* format and writing the resulting series
37
* of bytes.
38
* <p>
39
* For all the methods in this interface that
40
* write bytes, it is generally true that if
41
* a byte cannot be written for any reason,
42
* an {@code IOException} is thrown.
43
*
44
* @author Frank Yellin
45
* @see java.io.DataInput
46
* @see java.io.DataOutputStream
47
* @since 1.0
48
*/
49
public interface DataOutput {
50
/**
51
* Writes to the output stream the eight
52
* low-order bits of the argument {@code b}.
53
* The 24 high-order bits of {@code b}
54
* are ignored.
55
*
56
* @param b the byte to be written.
57
* @throws IOException if an I/O error occurs.
58
*/
59
void write(int b) throws IOException;
60
61
/**
62
* Writes to the output stream all the bytes in array {@code b}.
63
* If {@code b} is {@code null},
64
* a {@code NullPointerException} is thrown.
65
* If {@code b.length} is zero, then
66
* no bytes are written. Otherwise, the byte
67
* {@code b[0]} is written first, then
68
* {@code b[1]}, and so on; the last byte
69
* written is {@code b[b.length-1]}.
70
*
71
* @param b the data.
72
* @throws IOException if an I/O error occurs.
73
*/
74
void write(byte b[]) throws IOException;
75
76
/**
77
* Writes {@code len} bytes from array
78
* {@code b}, in order, to
79
* the output stream. If {@code b}
80
* is {@code null}, a {@code NullPointerException}
81
* is thrown. If {@code off} is negative,
82
* or {@code len} is negative, or {@code off+len}
83
* is greater than the length of the array
84
* {@code b}, then an {@code IndexOutOfBoundsException}
85
* is thrown. If {@code len} is zero,
86
* then no bytes are written. Otherwise, the
87
* byte {@code b[off]} is written first,
88
* then {@code b[off+1]}, and so on; the
89
* last byte written is {@code b[off+len-1]}.
90
*
91
* @param b the data.
92
* @param off the start offset in the data.
93
* @param len the number of bytes to write.
94
* @throws IOException if an I/O error occurs.
95
*/
96
void write(byte b[], int off, int len) throws IOException;
97
98
/**
99
* Writes a {@code boolean} value to this output stream.
100
* If the argument {@code v}
101
* is {@code true}, the value {@code (byte)1}
102
* is written; if {@code v} is {@code false},
103
* the value {@code (byte)0} is written.
104
* The byte written by this method may
105
* be read by the {@code readBoolean}
106
* method of interface {@code DataInput},
107
* which will then return a {@code boolean}
108
* equal to {@code v}.
109
*
110
* @param v the boolean to be written.
111
* @throws IOException if an I/O error occurs.
112
*/
113
void writeBoolean(boolean v) throws IOException;
114
115
/**
116
* Writes to the output stream the eight low-order
117
* bits of the argument {@code v}.
118
* The 24 high-order bits of {@code v}
119
* are ignored. (This means that {@code writeByte}
120
* does exactly the same thing as {@code write}
121
* for an integer argument.) The byte written
122
* by this method may be read by the {@code readByte}
123
* method of interface {@code DataInput},
124
* which will then return a {@code byte}
125
* equal to {@code (byte)v}.
126
*
127
* @param v the byte value to be written.
128
* @throws IOException if an I/O error occurs.
129
*/
130
void writeByte(int v) throws IOException;
131
132
/**
133
* Writes two bytes to the output
134
* stream to represent the value of the argument.
135
* The byte values to be written, in the order
136
* shown, are:
137
* <pre>{@code
138
* (byte)(0xff & (v >> 8))
139
* (byte)(0xff & v)
140
* }</pre> <p>
141
* The bytes written by this method may be
142
* read by the {@code readShort} method
143
* of interface {@code DataInput}, which
144
* will then return a {@code short} equal
145
* to {@code (short)v}.
146
*
147
* @param v the {@code short} value to be written.
148
* @throws IOException if an I/O error occurs.
149
*/
150
void writeShort(int v) throws IOException;
151
152
/**
153
* Writes a {@code char} value, which
154
* is comprised of two bytes, to the
155
* output stream.
156
* The byte values to be written, in the order
157
* shown, are:
158
* <pre>{@code
159
* (byte)(0xff & (v >> 8))
160
* (byte)(0xff & v)
161
* }</pre><p>
162
* The bytes written by this method may be
163
* read by the {@code readChar} method
164
* of interface {@code DataInput}, which
165
* will then return a {@code char} equal
166
* to {@code (char)v}.
167
*
168
* @param v the {@code char} value to be written.
169
* @throws IOException if an I/O error occurs.
170
*/
171
void writeChar(int v) throws IOException;
172
173
/**
174
* Writes an {@code int} value, which is
175
* comprised of four bytes, to the output stream.
176
* The byte values to be written, in the order
177
* shown, are:
178
* <pre>{@code
179
* (byte)(0xff & (v >> 24))
180
* (byte)(0xff & (v >> 16))
181
* (byte)(0xff & (v >> 8))
182
* (byte)(0xff & v)
183
* }</pre><p>
184
* The bytes written by this method may be read
185
* by the {@code readInt} method of interface
186
* {@code DataInput}, which will then
187
* return an {@code int} equal to {@code v}.
188
*
189
* @param v the {@code int} value to be written.
190
* @throws IOException if an I/O error occurs.
191
*/
192
void writeInt(int v) throws IOException;
193
194
/**
195
* Writes a {@code long} value, which is
196
* comprised of eight bytes, to the output stream.
197
* The byte values to be written, in the order
198
* shown, are:
199
* <pre>{@code
200
* (byte)(0xff & (v >> 56))
201
* (byte)(0xff & (v >> 48))
202
* (byte)(0xff & (v >> 40))
203
* (byte)(0xff & (v >> 32))
204
* (byte)(0xff & (v >> 24))
205
* (byte)(0xff & (v >> 16))
206
* (byte)(0xff & (v >> 8))
207
* (byte)(0xff & v)
208
* }</pre><p>
209
* The bytes written by this method may be
210
* read by the {@code readLong} method
211
* of interface {@code DataInput}, which
212
* will then return a {@code long} equal
213
* to {@code v}.
214
*
215
* @param v the {@code long} value to be written.
216
* @throws IOException if an I/O error occurs.
217
*/
218
void writeLong(long v) throws IOException;
219
220
/**
221
* Writes a {@code float} value,
222
* which is comprised of four bytes, to the output stream.
223
* It does this as if it first converts this
224
* {@code float} value to an {@code int}
225
* in exactly the manner of the {@code Float.floatToIntBits}
226
* method and then writes the {@code int}
227
* value in exactly the manner of the {@code writeInt}
228
* method. The bytes written by this method
229
* may be read by the {@code readFloat}
230
* method of interface {@code DataInput},
231
* which will then return a {@code float}
232
* equal to {@code v}.
233
*
234
* @param v the {@code float} value to be written.
235
* @throws IOException if an I/O error occurs.
236
*/
237
void writeFloat(float v) throws IOException;
238
239
/**
240
* Writes a {@code double} value,
241
* which is comprised of eight bytes, to the output stream.
242
* It does this as if it first converts this
243
* {@code double} value to a {@code long}
244
* in exactly the manner of the {@code Double.doubleToLongBits}
245
* method and then writes the {@code long}
246
* value in exactly the manner of the {@code writeLong}
247
* method. The bytes written by this method
248
* may be read by the {@code readDouble}
249
* method of interface {@code DataInput},
250
* which will then return a {@code double}
251
* equal to {@code v}.
252
*
253
* @param v the {@code double} value to be written.
254
* @throws IOException if an I/O error occurs.
255
*/
256
void writeDouble(double v) throws IOException;
257
258
/**
259
* Writes a string to the output stream.
260
* For every character in the string
261
* {@code s}, taken in order, one byte
262
* is written to the output stream. If
263
* {@code s} is {@code null}, a {@code NullPointerException}
264
* is thrown.<p> If {@code s.length}
265
* is zero, then no bytes are written. Otherwise,
266
* the character {@code s[0]} is written
267
* first, then {@code s[1]}, and so on;
268
* the last character written is {@code s[s.length-1]}.
269
* For each character, one byte is written,
270
* the low-order byte, in exactly the manner
271
* of the {@code writeByte} method . The
272
* high-order eight bits of each character
273
* in the string are ignored.
274
*
275
* @param s the string of bytes to be written.
276
* @throws IOException if an I/O error occurs.
277
*/
278
void writeBytes(String s) throws IOException;
279
280
/**
281
* Writes every character in the string {@code s},
282
* to the output stream, in order,
283
* two bytes per character. If {@code s}
284
* is {@code null}, a {@code NullPointerException}
285
* is thrown. If {@code s.length}
286
* is zero, then no characters are written.
287
* Otherwise, the character {@code s[0]}
288
* is written first, then {@code s[1]},
289
* and so on; the last character written is
290
* {@code s[s.length-1]}. For each character,
291
* two bytes are actually written, high-order
292
* byte first, in exactly the manner of the
293
* {@code writeChar} method.
294
*
295
* @param s the string value to be written.
296
* @throws IOException if an I/O error occurs.
297
*/
298
void writeChars(String s) throws IOException;
299
300
/**
301
* Writes two bytes of length information
302
* to the output stream, followed
303
* by the
304
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
305
* representation
306
* of every character in the string {@code s}.
307
* If {@code s} is {@code null},
308
* a {@code NullPointerException} is thrown.
309
* Each character in the string {@code s}
310
* is converted to a group of one, two, or
311
* three bytes, depending on the value of the
312
* character.<p>
313
* If a character {@code c}
314
* is in the range <code>&#92;u0001</code> through
315
* <code>&#92;u007f</code>, it is represented
316
* by one byte:
317
* <pre>(byte)c </pre> <p>
318
* If a character {@code c} is <code>&#92;u0000</code>
319
* or is in the range <code>&#92;u0080</code>
320
* through <code>&#92;u07ff</code>, then it is
321
* represented by two bytes, to be written
322
* in the order shown: <pre>{@code
323
* (byte)(0xc0 | (0x1f & (c >> 6)))
324
* (byte)(0x80 | (0x3f & c))
325
* }</pre> <p> If a character
326
* {@code c} is in the range <code>&#92;u0800</code>
327
* through {@code uffff}, then it is
328
* represented by three bytes, to be written
329
* in the order shown: <pre>{@code
330
* (byte)(0xe0 | (0x0f & (c >> 12)))
331
* (byte)(0x80 | (0x3f & (c >> 6)))
332
* (byte)(0x80 | (0x3f & c))
333
* }</pre> <p> First,
334
* the total number of bytes needed to represent
335
* all the characters of {@code s} is
336
* calculated. If this number is larger than
337
* {@code 65535}, then a {@code UTFDataFormatException}
338
* is thrown. Otherwise, this length is written
339
* to the output stream in exactly the manner
340
* of the {@code writeShort} method;
341
* after this, the one-, two-, or three-byte
342
* representation of each character in the
343
* string {@code s} is written.<p> The
344
* bytes written by this method may be read
345
* by the {@code readUTF} method of interface
346
* {@code DataInput}, which will then
347
* return a {@code String} equal to {@code s}.
348
*
349
* @param s the string value to be written.
350
* @throws IOException if an I/O error occurs.
351
*/
352
void writeUTF(String s) throws IOException;
353
}
354
355