1 /*
2  * Hunt - A refined core library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.stream.DataOutput;
13 
14 public
15 interface DataOutput {
16     /**
17      * Writes to the output stream the eight
18      * low-order bits of the argument <code>b</code>.
19      * The 24 high-order  bits of <code>b</code>
20      * are ignored.
21      *
22      * @param      b   the byte to be written.
23      * @throws     IOException  if an I/O error occurs.
24      */
25     void write(int b) ;
26 
27     /**
28      * Writes to the output stream all the bytes in array <code>b</code>.
29      * If <code>b</code> is <code>null</code>,
30      * a <code>NullPointerException</code> is thrown.
31      * If <code>b.length</code> is zero, then
32      * no bytes are written. Otherwise, the byte
33      * <code>b[0]</code> is written first, then
34      * <code>b[1]</code>, and so on; the last byte
35      * written is <code>b[b.length-1]</code>.
36      *
37      * @param      b   the data.
38      * @throws     IOException  if an I/O error occurs.
39      */
40     void write(byte[] b) ;
41 
42     /**
43      * Writes <code>len</code> bytes from array
44      * <code>b</code>, in order,  to
45      * the output stream.  If <code>b</code>
46      * is <code>null</code>, a <code>NullPointerException</code>
47      * is thrown.  If <code>off</code> is negative,
48      * or <code>len</code> is negative, or <code>off+len</code>
49      * is greater than the length of the array
50      * <code>b</code>, then an <code>IndexOutOfBoundsException</code>
51      * is thrown.  If <code>len</code> is zero,
52      * then no bytes are written. Otherwise, the
53      * byte <code>b[off]</code> is written first,
54      * then <code>b[off+1]</code>, and so on; the
55      * last byte written is <code>b[off+len-1]</code>.
56      *
57      * @param      b     the data.
58      * @param      off   the start offset in the data.
59      * @param      len   the number of bytes to write.
60      * @throws     IOException  if an I/O error occurs.
61      */
62     void write(byte[] b, int off, int len) ;
63 
64     /**
65      * Writes a <code>bool</code> value to this output stream.
66      * If the argument <code>v</code>
67      * is <code>true</code>, the value <code>(byte)1</code>
68      * is written; if <code>v</code> is <code>false</code>,
69      * the  value <code>(byte)0</code> is written.
70      * The byte written by this method may
71      * be read by the <code>readBoolean</code>
72      * method of interface <code>DataInput</code>,
73      * which will then return a <code>bool</code>
74      * equal to <code>v</code>.
75      *
76      * @param      v   the bool to be written.
77      * @throws     IOException  if an I/O error occurs.
78      */
79     void writeBoolean(bool v) ;
80 
81     /**
82      * Writes to the output stream the eight low-
83      * order bits of the argument <code>v</code>.
84      * The 24 high-order bits of <code>v</code>
85      * are ignored. (This means  that <code>writeByte</code>
86      * does exactly the same thing as <code>write</code>
87      * for an integer argument.) The byte written
88      * by this method may be read by the <code>readByte</code>
89      * method of interface <code>DataInput</code>,
90      * which will then return a <code>byte</code>
91      * equal to <code>(byte)v</code>.
92      *
93      * @param      v   the byte value to be written.
94      * @throws     IOException  if an I/O error occurs.
95      */
96     void writeByte(int v) ;
97 
98     /**
99      * Writes two bytes to the output
100      * stream to represent the value of the argument.
101      * The byte values to be written, in the  order
102      * shown, are:
103      * <pre>{@code
104      * (byte)(0xff & (v >> 8))
105      * (byte)(0xff & v)
106      * }</pre> <p>
107      * The bytes written by this method may be
108      * read by the <code>readShort</code> method
109      * of interface <code>DataInput</code> , which
110      * will then return a <code>short</code> equal
111      * to <code>(short)v</code>.
112      *
113      * @param      v   the <code>short</code> value to be written.
114      * @throws     IOException  if an I/O error occurs.
115      */
116     void writeShort(int v) ;
117 
118     /**
119      * Writes a <code>char</code> value, which
120      * is comprised of two bytes, to the
121      * output stream.
122      * The byte values to be written, in the  order
123      * shown, are:
124      * <pre>{@code
125      * (byte)(0xff & (v >> 8))
126      * (byte)(0xff & v)
127      * }</pre><p>
128      * The bytes written by this method may be
129      * read by the <code>readChar</code> method
130      * of interface <code>DataInput</code> , which
131      * will then return a <code>char</code> equal
132      * to <code>(char)v</code>.
133      *
134      * @param      v   the <code>char</code> value to be written.
135      * @throws     IOException  if an I/O error occurs.
136      */
137     void writeChar(int v) ;
138 
139     /**
140      * Writes an <code>int</code> value, which is
141      * comprised of four bytes, to the output stream.
142      * The byte values to be written, in the  order
143      * shown, are:
144      * <pre>{@code
145      * (byte)(0xff & (v >> 24))
146      * (byte)(0xff & (v >> 16))
147      * (byte)(0xff & (v >>  8))
148      * (byte)(0xff & v)
149      * }</pre><p>
150      * The bytes written by this method may be read
151      * by the <code>readInt</code> method of interface
152      * <code>DataInput</code> , which will then
153      * return an <code>int</code> equal to <code>v</code>.
154      *
155      * @param      v   the <code>int</code> value to be written.
156      * @throws     IOException  if an I/O error occurs.
157      */
158     void writeInt(int v) ;
159 
160     /**
161      * Writes a <code>long</code> value, which is
162      * comprised of eight bytes, to the output stream.
163      * The byte values to be written, in the  order
164      * shown, are:
165      * <pre>{@code
166      * (byte)(0xff & (v >> 56))
167      * (byte)(0xff & (v >> 48))
168      * (byte)(0xff & (v >> 40))
169      * (byte)(0xff & (v >> 32))
170      * (byte)(0xff & (v >> 24))
171      * (byte)(0xff & (v >> 16))
172      * (byte)(0xff & (v >>  8))
173      * (byte)(0xff & v)
174      * }</pre><p>
175      * The bytes written by this method may be
176      * read by the <code>readLong</code> method
177      * of interface <code>DataInput</code> , which
178      * will then return a <code>long</code> equal
179      * to <code>v</code>.
180      *
181      * @param      v   the <code>long</code> value to be written.
182      * @throws     IOException  if an I/O error occurs.
183      */
184     void writeLong(long v) ;
185 
186     /**
187      * Writes a <code>float</code> value,
188      * which is comprised of four bytes, to the output stream.
189      * It does this as if it first converts this
190      * <code>float</code> value to an <code>int</code>
191      * in exactly the manner of the <code>Float.floatToIntBits</code>
192      * method  and then writes the <code>int</code>
193      * value in exactly the manner of the  <code>writeInt</code>
194      * method.  The bytes written by this method
195      * may be read by the <code>readFloat</code>
196      * method of interface <code>DataInput</code>,
197      * which will then return a <code>float</code>
198      * equal to <code>v</code>.
199      *
200      * @param      v   the <code>float</code> value to be written.
201      * @throws     IOException  if an I/O error occurs.
202      */
203     void writeFloat(float v) ;
204 
205     /**
206      * Writes a <code>double</code> value,
207      * which is comprised of eight bytes, to the output stream.
208      * It does this as if it first converts this
209      * <code>double</code> value to a <code>long</code>
210      * in exactly the manner of the <code>Double.doubleToLongBits</code>
211      * method  and then writes the <code>long</code>
212      * value in exactly the manner of the  <code>writeLong</code>
213      * method. The bytes written by this method
214      * may be read by the <code>readDouble</code>
215      * method of interface <code>DataInput</code>,
216      * which will then return a <code>double</code>
217      * equal to <code>v</code>.
218      *
219      * @param      v   the <code>double</code> value to be written.
220      * @throws     IOException  if an I/O error occurs.
221      */
222     void writeDouble(double v) ;
223 
224     /**
225      * Writes a string to the output stream.
226      * For every character in the string
227      * <code>s</code>,  taken in order, one byte
228      * is written to the output stream.  If
229      * <code>s</code> is <code>null</code>, a <code>NullPointerException</code>
230      * is thrown.<p>  If <code>s.length</code>
231      * is zero, then no bytes are written. Otherwise,
232      * the character <code>s[0]</code> is written
233      * first, then <code>s[1]</code>, and so on;
234      * the last character written is <code>s[s.length-1]</code>.
235      * For each character, one byte is written,
236      * the low-order byte, in exactly the manner
237      * of the <code>writeByte</code> method . The
238      * high-order eight bits of each character
239      * in the string are ignored.
240      *
241      * @param      s   the string of bytes to be written.
242      * @throws     IOException  if an I/O error occurs.
243      */
244     void writeBytes(string s) ;
245 
246     /**
247      * Writes every character in the string <code>s</code>,
248      * to the output stream, in order,
249      * two bytes per character. If <code>s</code>
250      * is <code>null</code>, a <code>NullPointerException</code>
251      * is thrown.  If <code>s.length</code>
252      * is zero, then no characters are written.
253      * Otherwise, the character <code>s[0]</code>
254      * is written first, then <code>s[1]</code>,
255      * and so on; the last character written is
256      * <code>s[s.length-1]</code>. For each character,
257      * two bytes are actually written, high-order
258      * byte first, in exactly the manner of the
259      * <code>writeChar</code> method.
260      *
261      * @param      s   the string value to be written.
262      * @throws     IOException  if an I/O error occurs.
263      */
264     void writeChars(string s) ;
265 
266     /**
267      * Writes two bytes of length information
268      * to the output stream, followed
269      * by the
270      * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
271      * representation
272      * of  every character in the string <code>s</code>.
273      * If <code>s</code> is <code>null</code>,
274      * a <code>NullPointerException</code> is thrown.
275      * Each character in the string <code>s</code>
276      * is converted to a group of one, two, or
277      * three bytes, depending on the value of the
278      * character.<p>
279      * If a character <code>c</code>
280      * is in the range <code>&#92;u0001</code> through
281      * <code>&#92;u007f</code>, it is represented
282      * by one byte:
283      * <pre>(byte)c </pre>  <p>
284      * If a character <code>c</code> is <code>&#92;u0000</code>
285      * or is in the range <code>&#92;u0080</code>
286      * through <code>&#92;u07ff</code>, then it is
287      * represented by two bytes, to be written
288      * in the order shown: <pre>{@code
289      * (byte)(0xc0 | (0x1f & (c >> 6)))
290      * (byte)(0x80 | (0x3f & c))
291      * }</pre> <p> If a character
292      * <code>c</code> is in the range <code>&#92;u0800</code>
293      * through <code>uffff</code>, then it is
294      * represented by three bytes, to be written
295      * in the order shown: <pre>{@code
296      * (byte)(0xe0 | (0x0f & (c >> 12)))
297      * (byte)(0x80 | (0x3f & (c >>  6)))
298      * (byte)(0x80 | (0x3f & c))
299      * }</pre>  <p> First,
300      * the total number of bytes needed to represent
301      * all the characters of <code>s</code> is
302      * calculated. If this number is larger than
303      * <code>65535</code>, then a <code>UTFDataFormatException</code>
304      * is thrown. Otherwise, this length is written
305      * to the output stream in exactly the manner
306      * of the <code>writeShort</code> method;
307      * after this, the one-, two-, or three-byte
308      * representation of each character in the
309      * string <code>s</code> is written.<p>  The
310      * bytes written by this method may be read
311      * by the <code>readUTF</code> method of interface
312      * <code>DataInput</code> , which will then
313      * return a <code>string</code> equal to <code>s</code>.
314      *
315      * @param      s   the string value to be written.
316      * @throws     IOException  if an I/O error occurs.
317      */
318     void writeUTF(string s) ;
319 }