branch | datagramsocketimpl-branch |
changeset 58678 | 9cf78a70fa4f |
parent 47216 | 71c04702a3d5 |
child 58679 | 9c3209ff7550 |
58677:13588c901957 | 58678:9cf78a70fa4f |
---|---|
1 /* |
1 /* |
2 * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
58 private byte bytearr[] = new byte[80]; |
58 private byte bytearr[] = new byte[80]; |
59 private char chararr[] = new char[80]; |
59 private char chararr[] = new char[80]; |
60 |
60 |
61 /** |
61 /** |
62 * Reads some number of bytes from the contained input stream and |
62 * Reads some number of bytes from the contained input stream and |
63 * stores them into the buffer array <code>b</code>. The number of |
63 * stores them into the buffer array {@code b}. The number of |
64 * bytes actually read is returned as an integer. This method blocks |
64 * bytes actually read is returned as an integer. This method blocks |
65 * until input data is available, end of file is detected, or an |
65 * until input data is available, end of file is detected, or an |
66 * exception is thrown. |
66 * exception is thrown. |
67 * |
67 * |
68 * <p>If <code>b</code> is null, a <code>NullPointerException</code> is |
68 * <p>If {@code b} is null, a {@code NullPointerException} is |
69 * thrown. If the length of <code>b</code> is zero, then no bytes are |
69 * thrown. If the length of {@code b} is zero, then no bytes are |
70 * read and <code>0</code> is returned; otherwise, there is an attempt |
70 * read and {@code 0} is returned; otherwise, there is an attempt |
71 * to read at least one byte. If no byte is available because the |
71 * to read at least one byte. If no byte is available because the |
72 * stream is at end of file, the value <code>-1</code> is returned; |
72 * stream is at end of file, the value {@code -1} is returned; |
73 * otherwise, at least one byte is read and stored into <code>b</code>. |
73 * otherwise, at least one byte is read and stored into {@code b}. |
74 * |
74 * |
75 * <p>The first byte read is stored into element <code>b[0]</code>, the |
75 * <p>The first byte read is stored into element {@code b[0]}, the |
76 * next one into <code>b[1]</code>, and so on. The number of bytes read |
76 * next one into {@code b[1]}, and so on. The number of bytes read |
77 * is, at most, equal to the length of <code>b</code>. Let <code>k</code> |
77 * is, at most, equal to the length of {@code b}. Let {@code k} |
78 * be the number of bytes actually read; these bytes will be stored in |
78 * be the number of bytes actually read; these bytes will be stored in |
79 * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving |
79 * elements {@code b[0]} through {@code b[k-1]}, leaving |
80 * elements <code>b[k]</code> through <code>b[b.length-1]</code> |
80 * elements {@code b[k]} through {@code b[b.length-1]} |
81 * unaffected. |
81 * unaffected. |
82 * |
82 * |
83 * <p>The <code>read(b)</code> method has the same effect as: |
83 * <p>The {@code read(b)} method has the same effect as: |
84 * <blockquote><pre> |
84 * <blockquote><pre> |
85 * read(b, 0, b.length) |
85 * read(b, 0, b.length) |
86 * </pre></blockquote> |
86 * </pre></blockquote> |
87 * |
87 * |
88 * @param b the buffer into which the data is read. |
88 * @param b the buffer into which the data is read. |
89 * @return the total number of bytes read into the buffer, or |
89 * @return the total number of bytes read into the buffer, or |
90 * <code>-1</code> if there is no more data because the end |
90 * {@code -1} if there is no more data because the end |
91 * of the stream has been reached. |
91 * of the stream has been reached. |
92 * @exception IOException if the first byte cannot be read for any reason |
92 * @throws IOException if the first byte cannot be read for any reason |
93 * other than end of file, the stream has been closed and the underlying |
93 * other than end of file, the stream has been closed and the underlying |
94 * input stream does not support reading after close, or another I/O |
94 * input stream does not support reading after close, or another I/O |
95 * error occurs. |
95 * error occurs. |
96 * @see java.io.FilterInputStream#in |
96 * @see java.io.FilterInputStream#in |
97 * @see java.io.InputStream#read(byte[], int, int) |
97 * @see java.io.InputStream#read(byte[], int, int) |
98 */ |
98 */ |
99 public final int read(byte b[]) throws IOException { |
99 public final int read(byte b[]) throws IOException { |
100 return in.read(b, 0, b.length); |
100 return in.read(b, 0, b.length); |
101 } |
101 } |
102 |
102 |
103 /** |
103 /** |
104 * Reads up to <code>len</code> bytes of data from the contained |
104 * Reads up to {@code len} bytes of data from the contained |
105 * input stream into an array of bytes. An attempt is made to read |
105 * input stream into an array of bytes. An attempt is made to read |
106 * as many as <code>len</code> bytes, but a smaller number may be read, |
106 * as many as {@code len} bytes, but a smaller number may be read, |
107 * possibly zero. The number of bytes actually read is returned as an |
107 * possibly zero. The number of bytes actually read is returned as an |
108 * integer. |
108 * integer. |
109 * |
109 * |
110 * <p> This method blocks until input data is available, end of file is |
110 * <p> This method blocks until input data is available, end of file is |
111 * detected, or an exception is thrown. |
111 * detected, or an exception is thrown. |
112 * |
112 * |
113 * <p> If <code>len</code> is zero, then no bytes are read and |
113 * <p> If {@code len} is zero, then no bytes are read and |
114 * <code>0</code> is returned; otherwise, there is an attempt to read at |
114 * {@code 0} is returned; otherwise, there is an attempt to read at |
115 * least one byte. If no byte is available because the stream is at end of |
115 * least one byte. If no byte is available because the stream is at end of |
116 * file, the value <code>-1</code> is returned; otherwise, at least one |
116 * file, the value {@code -1} is returned; otherwise, at least one |
117 * byte is read and stored into <code>b</code>. |
117 * byte is read and stored into {@code b}. |
118 * |
118 * |
119 * <p> The first byte read is stored into element <code>b[off]</code>, the |
119 * <p> The first byte read is stored into element {@code b[off]}, the |
120 * next one into <code>b[off+1]</code>, and so on. The number of bytes read |
120 * next one into {@code b[off+1]}, and so on. The number of bytes read |
121 * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of |
121 * is, at most, equal to {@code len}. Let <i>k</i> be the number of |
122 * bytes actually read; these bytes will be stored in elements |
122 * bytes actually read; these bytes will be stored in elements |
123 * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>, |
123 * {@code b[off]} through {@code b[off+}<i>k</i>{@code -1]}, |
124 * leaving elements <code>b[off+</code><i>k</i><code>]</code> through |
124 * leaving elements {@code b[off+}<i>k</i>{@code ]} through |
125 * <code>b[off+len-1]</code> unaffected. |
125 * {@code b[off+len-1]} unaffected. |
126 * |
126 * |
127 * <p> In every case, elements <code>b[0]</code> through |
127 * <p> In every case, elements {@code b[0]} through |
128 * <code>b[off]</code> and elements <code>b[off+len]</code> through |
128 * {@code b[off]} and elements {@code b[off+len]} through |
129 * <code>b[b.length-1]</code> are unaffected. |
129 * {@code b[b.length-1]} are unaffected. |
130 * |
130 * |
131 * @param b the buffer into which the data is read. |
131 * @param b the buffer into which the data is read. |
132 * @param off the start offset in the destination array <code>b</code> |
132 * @param off the start offset in the destination array {@code b} |
133 * @param len the maximum number of bytes read. |
133 * @param len the maximum number of bytes read. |
134 * @return the total number of bytes read into the buffer, or |
134 * @return the total number of bytes read into the buffer, or |
135 * <code>-1</code> if there is no more data because the end |
135 * {@code -1} if there is no more data because the end |
136 * of the stream has been reached. |
136 * of the stream has been reached. |
137 * @exception NullPointerException If <code>b</code> is <code>null</code>. |
137 * @throws NullPointerException If {@code b} is {@code null}. |
138 * @exception IndexOutOfBoundsException If <code>off</code> is negative, |
138 * @throws IndexOutOfBoundsException If {@code off} is negative, |
139 * <code>len</code> is negative, or <code>len</code> is greater than |
139 * {@code len} is negative, or {@code len} is greater than |
140 * <code>b.length - off</code> |
140 * {@code b.length - off} |
141 * @exception IOException if the first byte cannot be read for any reason |
141 * @throws IOException if the first byte cannot be read for any reason |
142 * other than end of file, the stream has been closed and the underlying |
142 * other than end of file, the stream has been closed and the underlying |
143 * input stream does not support reading after close, or another I/O |
143 * input stream does not support reading after close, or another I/O |
144 * error occurs. |
144 * error occurs. |
145 * @see java.io.FilterInputStream#in |
145 * @see java.io.FilterInputStream#in |
146 * @see java.io.InputStream#read(byte[], int, int) |
146 * @see java.io.InputStream#read(byte[], int, int) |
147 */ |
147 */ |
148 public final int read(byte b[], int off, int len) throws IOException { |
148 public final int read(byte b[], int off, int len) throws IOException { |
149 return in.read(b, off, len); |
149 return in.read(b, off, len); |
179 * input stream. |
179 * input stream. |
180 * |
180 * |
181 * @param b the buffer into which the data is read. |
181 * @param b the buffer into which the data is read. |
182 * @param off the start offset in the data array {@code b}. |
182 * @param off the start offset in the data array {@code b}. |
183 * @param len the number of bytes to read. |
183 * @param len the number of bytes to read. |
184 * @exception NullPointerException if {@code b} is {@code null}. |
184 * @throws NullPointerException if {@code b} is {@code null}. |
185 * @exception IndexOutOfBoundsException if {@code off} is negative, |
185 * @throws IndexOutOfBoundsException if {@code off} is negative, |
186 * {@code len} is negative, or {@code len} is greater than |
186 * {@code len} is negative, or {@code len} is greater than |
187 * {@code b.length - off}. |
187 * {@code b.length - off}. |
188 * @exception EOFException if this input stream reaches the end before |
188 * @throws EOFException if this input stream reaches the end before |
189 * reading all the bytes. |
189 * reading all the bytes. |
190 * @exception IOException the stream has been closed and the contained |
190 * @throws IOException the stream has been closed and the contained |
191 * input stream does not support reading after close, or |
191 * input stream does not support reading after close, or |
192 * another I/O error occurs. |
192 * another I/O error occurs. |
193 * @see java.io.FilterInputStream#in |
193 * @see java.io.FilterInputStream#in |
194 */ |
194 */ |
195 public final void readFully(byte b[], int off, int len) throws IOException { |
195 public final void readFully(byte b[], int off, int len) throws IOException { |
203 n += count; |
203 n += count; |
204 } |
204 } |
205 } |
205 } |
206 |
206 |
207 /** |
207 /** |
208 * See the general contract of the <code>skipBytes</code> |
208 * See the general contract of the {@code skipBytes} |
209 * method of <code>DataInput</code>. |
209 * method of {@code DataInput}. |
210 * <p> |
210 * <p> |
211 * Bytes for this operation are read from the contained |
211 * Bytes for this operation are read from the contained |
212 * input stream. |
212 * input stream. |
213 * |
213 * |
214 * @param n the number of bytes to be skipped. |
214 * @param n the number of bytes to be skipped. |
215 * @return the actual number of bytes skipped. |
215 * @return the actual number of bytes skipped. |
216 * @exception IOException if the contained input stream does not support |
216 * @throws IOException if the contained input stream does not support |
217 * seek, or the stream has been closed and |
217 * seek, or the stream has been closed and |
218 * the contained input stream does not support |
218 * the contained input stream does not support |
219 * reading after close, or another I/O error occurs. |
219 * reading after close, or another I/O error occurs. |
220 */ |
220 */ |
221 public final int skipBytes(int n) throws IOException { |
221 public final int skipBytes(int n) throws IOException { |
228 |
228 |
229 return total; |
229 return total; |
230 } |
230 } |
231 |
231 |
232 /** |
232 /** |
233 * See the general contract of the <code>readBoolean</code> |
233 * See the general contract of the {@code readBoolean} |
234 * method of <code>DataInput</code>. |
234 * method of {@code DataInput}. |
235 * <p> |
235 * <p> |
236 * Bytes for this operation are read from the contained |
236 * Bytes for this operation are read from the contained |
237 * input stream. |
237 * input stream. |
238 * |
238 * |
239 * @return the <code>boolean</code> value read. |
239 * @return the {@code boolean} value read. |
240 * @exception EOFException if this input stream has reached the end. |
240 * @throws EOFException if this input stream has reached the end. |
241 * @exception IOException the stream has been closed and the contained |
241 * @throws IOException the stream has been closed and the contained |
242 * input stream does not support reading after close, or |
242 * input stream does not support reading after close, or |
243 * another I/O error occurs. |
243 * another I/O error occurs. |
244 * @see java.io.FilterInputStream#in |
244 * @see java.io.FilterInputStream#in |
245 */ |
245 */ |
246 public final boolean readBoolean() throws IOException { |
246 public final boolean readBoolean() throws IOException { |
249 throw new EOFException(); |
249 throw new EOFException(); |
250 return (ch != 0); |
250 return (ch != 0); |
251 } |
251 } |
252 |
252 |
253 /** |
253 /** |
254 * See the general contract of the <code>readByte</code> |
254 * See the general contract of the {@code readByte} |
255 * method of <code>DataInput</code>. |
255 * method of {@code DataInput}. |
256 * <p> |
256 * <p> |
257 * Bytes |
257 * Bytes |
258 * for this operation are read from the contained |
258 * for this operation are read from the contained |
259 * input stream. |
259 * input stream. |
260 * |
260 * |
261 * @return the next byte of this input stream as a signed 8-bit |
261 * @return the next byte of this input stream as a signed 8-bit |
262 * <code>byte</code>. |
262 * {@code byte}. |
263 * @exception EOFException if this input stream has reached the end. |
263 * @throws EOFException if this input stream has reached the end. |
264 * @exception IOException the stream has been closed and the contained |
264 * @throws IOException the stream has been closed and the contained |
265 * input stream does not support reading after close, or |
265 * input stream does not support reading after close, or |
266 * another I/O error occurs. |
266 * another I/O error occurs. |
267 * @see java.io.FilterInputStream#in |
267 * @see java.io.FilterInputStream#in |
268 */ |
268 */ |
269 public final byte readByte() throws IOException { |
269 public final byte readByte() throws IOException { |
272 throw new EOFException(); |
272 throw new EOFException(); |
273 return (byte)(ch); |
273 return (byte)(ch); |
274 } |
274 } |
275 |
275 |
276 /** |
276 /** |
277 * See the general contract of the <code>readUnsignedByte</code> |
277 * See the general contract of the {@code readUnsignedByte} |
278 * method of <code>DataInput</code>. |
278 * method of {@code DataInput}. |
279 * <p> |
279 * <p> |
280 * Bytes |
280 * Bytes |
281 * for this operation are read from the contained |
281 * for this operation are read from the contained |
282 * input stream. |
282 * input stream. |
283 * |
283 * |
284 * @return the next byte of this input stream, interpreted as an |
284 * @return the next byte of this input stream, interpreted as an |
285 * unsigned 8-bit number. |
285 * unsigned 8-bit number. |
286 * @exception EOFException if this input stream has reached the end. |
286 * @throws EOFException if this input stream has reached the end. |
287 * @exception IOException the stream has been closed and the contained |
287 * @throws IOException the stream has been closed and the contained |
288 * input stream does not support reading after close, or |
288 * input stream does not support reading after close, or |
289 * another I/O error occurs. |
289 * another I/O error occurs. |
290 * @see java.io.FilterInputStream#in |
290 * @see java.io.FilterInputStream#in |
291 */ |
291 */ |
292 public final int readUnsignedByte() throws IOException { |
292 public final int readUnsignedByte() throws IOException { |
295 throw new EOFException(); |
295 throw new EOFException(); |
296 return ch; |
296 return ch; |
297 } |
297 } |
298 |
298 |
299 /** |
299 /** |
300 * See the general contract of the <code>readShort</code> |
300 * See the general contract of the {@code readShort} |
301 * method of <code>DataInput</code>. |
301 * method of {@code DataInput}. |
302 * <p> |
302 * <p> |
303 * Bytes |
303 * Bytes |
304 * for this operation are read from the contained |
304 * for this operation are read from the contained |
305 * input stream. |
305 * input stream. |
306 * |
306 * |
307 * @return the next two bytes of this input stream, interpreted as a |
307 * @return the next two bytes of this input stream, interpreted as a |
308 * signed 16-bit number. |
308 * signed 16-bit number. |
309 * @exception EOFException if this input stream reaches the end before |
309 * @throws EOFException if this input stream reaches the end before |
310 * reading two bytes. |
310 * reading two bytes. |
311 * @exception IOException the stream has been closed and the contained |
311 * @throws IOException the stream has been closed and the contained |
312 * input stream does not support reading after close, or |
312 * input stream does not support reading after close, or |
313 * another I/O error occurs. |
313 * another I/O error occurs. |
314 * @see java.io.FilterInputStream#in |
314 * @see java.io.FilterInputStream#in |
315 */ |
315 */ |
316 public final short readShort() throws IOException { |
316 public final short readShort() throws IOException { |
320 throw new EOFException(); |
320 throw new EOFException(); |
321 return (short)((ch1 << 8) + (ch2 << 0)); |
321 return (short)((ch1 << 8) + (ch2 << 0)); |
322 } |
322 } |
323 |
323 |
324 /** |
324 /** |
325 * See the general contract of the <code>readUnsignedShort</code> |
325 * See the general contract of the {@code readUnsignedShort} |
326 * method of <code>DataInput</code>. |
326 * method of {@code DataInput}. |
327 * <p> |
327 * <p> |
328 * Bytes |
328 * Bytes |
329 * for this operation are read from the contained |
329 * for this operation are read from the contained |
330 * input stream. |
330 * input stream. |
331 * |
331 * |
332 * @return the next two bytes of this input stream, interpreted as an |
332 * @return the next two bytes of this input stream, interpreted as an |
333 * unsigned 16-bit integer. |
333 * unsigned 16-bit integer. |
334 * @exception EOFException if this input stream reaches the end before |
334 * @throws EOFException if this input stream reaches the end before |
335 * reading two bytes. |
335 * reading two bytes. |
336 * @exception IOException the stream has been closed and the contained |
336 * @throws IOException the stream has been closed and the contained |
337 * input stream does not support reading after close, or |
337 * input stream does not support reading after close, or |
338 * another I/O error occurs. |
338 * another I/O error occurs. |
339 * @see java.io.FilterInputStream#in |
339 * @see java.io.FilterInputStream#in |
340 */ |
340 */ |
341 public final int readUnsignedShort() throws IOException { |
341 public final int readUnsignedShort() throws IOException { |
345 throw new EOFException(); |
345 throw new EOFException(); |
346 return (ch1 << 8) + (ch2 << 0); |
346 return (ch1 << 8) + (ch2 << 0); |
347 } |
347 } |
348 |
348 |
349 /** |
349 /** |
350 * See the general contract of the <code>readChar</code> |
350 * See the general contract of the {@code readChar} |
351 * method of <code>DataInput</code>. |
351 * method of {@code DataInput}. |
352 * <p> |
352 * <p> |
353 * Bytes |
353 * Bytes |
354 * for this operation are read from the contained |
354 * for this operation are read from the contained |
355 * input stream. |
355 * input stream. |
356 * |
356 * |
357 * @return the next two bytes of this input stream, interpreted as a |
357 * @return the next two bytes of this input stream, interpreted as a |
358 * <code>char</code>. |
358 * {@code char}. |
359 * @exception EOFException if this input stream reaches the end before |
359 * @throws EOFException if this input stream reaches the end before |
360 * reading two bytes. |
360 * reading two bytes. |
361 * @exception IOException the stream has been closed and the contained |
361 * @throws IOException the stream has been closed and the contained |
362 * input stream does not support reading after close, or |
362 * input stream does not support reading after close, or |
363 * another I/O error occurs. |
363 * another I/O error occurs. |
364 * @see java.io.FilterInputStream#in |
364 * @see java.io.FilterInputStream#in |
365 */ |
365 */ |
366 public final char readChar() throws IOException { |
366 public final char readChar() throws IOException { |
370 throw new EOFException(); |
370 throw new EOFException(); |
371 return (char)((ch1 << 8) + (ch2 << 0)); |
371 return (char)((ch1 << 8) + (ch2 << 0)); |
372 } |
372 } |
373 |
373 |
374 /** |
374 /** |
375 * See the general contract of the <code>readInt</code> |
375 * See the general contract of the {@code readInt} |
376 * method of <code>DataInput</code>. |
376 * method of {@code DataInput}. |
377 * <p> |
377 * <p> |
378 * Bytes |
378 * Bytes |
379 * for this operation are read from the contained |
379 * for this operation are read from the contained |
380 * input stream. |
380 * input stream. |
381 * |
381 * |
382 * @return the next four bytes of this input stream, interpreted as an |
382 * @return the next four bytes of this input stream, interpreted as an |
383 * <code>int</code>. |
383 * {@code int}. |
384 * @exception EOFException if this input stream reaches the end before |
384 * @throws EOFException if this input stream reaches the end before |
385 * reading four bytes. |
385 * reading four bytes. |
386 * @exception IOException the stream has been closed and the contained |
386 * @throws IOException the stream has been closed and the contained |
387 * input stream does not support reading after close, or |
387 * input stream does not support reading after close, or |
388 * another I/O error occurs. |
388 * another I/O error occurs. |
389 * @see java.io.FilterInputStream#in |
389 * @see java.io.FilterInputStream#in |
390 */ |
390 */ |
391 public final int readInt() throws IOException { |
391 public final int readInt() throws IOException { |
399 } |
399 } |
400 |
400 |
401 private byte readBuffer[] = new byte[8]; |
401 private byte readBuffer[] = new byte[8]; |
402 |
402 |
403 /** |
403 /** |
404 * See the general contract of the <code>readLong</code> |
404 * See the general contract of the {@code readLong} |
405 * method of <code>DataInput</code>. |
405 * method of {@code DataInput}. |
406 * <p> |
406 * <p> |
407 * Bytes |
407 * Bytes |
408 * for this operation are read from the contained |
408 * for this operation are read from the contained |
409 * input stream. |
409 * input stream. |
410 * |
410 * |
411 * @return the next eight bytes of this input stream, interpreted as a |
411 * @return the next eight bytes of this input stream, interpreted as a |
412 * <code>long</code>. |
412 * {@code long}. |
413 * @exception EOFException if this input stream reaches the end before |
413 * @throws EOFException if this input stream reaches the end before |
414 * reading eight bytes. |
414 * reading eight bytes. |
415 * @exception IOException the stream has been closed and the contained |
415 * @throws IOException the stream has been closed and the contained |
416 * input stream does not support reading after close, or |
416 * input stream does not support reading after close, or |
417 * another I/O error occurs. |
417 * another I/O error occurs. |
418 * @see java.io.FilterInputStream#in |
418 * @see java.io.FilterInputStream#in |
419 */ |
419 */ |
420 public final long readLong() throws IOException { |
420 public final long readLong() throws IOException { |
428 ((readBuffer[6] & 255) << 8) + |
428 ((readBuffer[6] & 255) << 8) + |
429 ((readBuffer[7] & 255) << 0)); |
429 ((readBuffer[7] & 255) << 0)); |
430 } |
430 } |
431 |
431 |
432 /** |
432 /** |
433 * See the general contract of the <code>readFloat</code> |
433 * See the general contract of the {@code readFloat} |
434 * method of <code>DataInput</code>. |
434 * method of {@code DataInput}. |
435 * <p> |
435 * <p> |
436 * Bytes |
436 * Bytes |
437 * for this operation are read from the contained |
437 * for this operation are read from the contained |
438 * input stream. |
438 * input stream. |
439 * |
439 * |
440 * @return the next four bytes of this input stream, interpreted as a |
440 * @return the next four bytes of this input stream, interpreted as a |
441 * <code>float</code>. |
441 * {@code float}. |
442 * @exception EOFException if this input stream reaches the end before |
442 * @throws EOFException if this input stream reaches the end before |
443 * reading four bytes. |
443 * reading four bytes. |
444 * @exception IOException the stream has been closed and the contained |
444 * @throws IOException the stream has been closed and the contained |
445 * input stream does not support reading after close, or |
445 * input stream does not support reading after close, or |
446 * another I/O error occurs. |
446 * another I/O error occurs. |
447 * @see java.io.DataInputStream#readInt() |
447 * @see java.io.DataInputStream#readInt() |
448 * @see java.lang.Float#intBitsToFloat(int) |
448 * @see java.lang.Float#intBitsToFloat(int) |
449 */ |
449 */ |
450 public final float readFloat() throws IOException { |
450 public final float readFloat() throws IOException { |
451 return Float.intBitsToFloat(readInt()); |
451 return Float.intBitsToFloat(readInt()); |
452 } |
452 } |
453 |
453 |
454 /** |
454 /** |
455 * See the general contract of the <code>readDouble</code> |
455 * See the general contract of the {@code readDouble} |
456 * method of <code>DataInput</code>. |
456 * method of {@code DataInput}. |
457 * <p> |
457 * <p> |
458 * Bytes |
458 * Bytes |
459 * for this operation are read from the contained |
459 * for this operation are read from the contained |
460 * input stream. |
460 * input stream. |
461 * |
461 * |
462 * @return the next eight bytes of this input stream, interpreted as a |
462 * @return the next eight bytes of this input stream, interpreted as a |
463 * <code>double</code>. |
463 * {@code double}. |
464 * @exception EOFException if this input stream reaches the end before |
464 * @throws EOFException if this input stream reaches the end before |
465 * reading eight bytes. |
465 * reading eight bytes. |
466 * @exception IOException the stream has been closed and the contained |
466 * @throws IOException the stream has been closed and the contained |
467 * input stream does not support reading after close, or |
467 * input stream does not support reading after close, or |
468 * another I/O error occurs. |
468 * another I/O error occurs. |
469 * @see java.io.DataInputStream#readLong() |
469 * @see java.io.DataInputStream#readLong() |
470 * @see java.lang.Double#longBitsToDouble(long) |
470 * @see java.lang.Double#longBitsToDouble(long) |
471 */ |
471 */ |
474 } |
474 } |
475 |
475 |
476 private char lineBuffer[]; |
476 private char lineBuffer[]; |
477 |
477 |
478 /** |
478 /** |
479 * See the general contract of the <code>readLine</code> |
479 * See the general contract of the {@code readLine} |
480 * method of <code>DataInput</code>. |
480 * method of {@code DataInput}. |
481 * <p> |
481 * <p> |
482 * Bytes |
482 * Bytes |
483 * for this operation are read from the contained |
483 * for this operation are read from the contained |
484 * input stream. |
484 * input stream. |
485 * |
485 * |
486 * @deprecated This method does not properly convert bytes to characters. |
486 * @deprecated This method does not properly convert bytes to characters. |
487 * As of JDK 1.1, the preferred way to read lines of text is via the |
487 * As of JDK 1.1, the preferred way to read lines of text is via the |
488 * <code>BufferedReader.readLine()</code> method. Programs that use the |
488 * {@code BufferedReader.readLine()} method. Programs that use the |
489 * <code>DataInputStream</code> class to read lines can be converted to use |
489 * {@code DataInputStream} class to read lines can be converted to use |
490 * the <code>BufferedReader</code> class by replacing code of the form: |
490 * the {@code BufferedReader} class by replacing code of the form: |
491 * <blockquote><pre> |
491 * <blockquote><pre> |
492 * DataInputStream d = new DataInputStream(in); |
492 * DataInputStream d = new DataInputStream(in); |
493 * </pre></blockquote> |
493 * </pre></blockquote> |
494 * with: |
494 * with: |
495 * <blockquote><pre> |
495 * <blockquote><pre> |
496 * BufferedReader d |
496 * BufferedReader d |
497 * = new BufferedReader(new InputStreamReader(in)); |
497 * = new BufferedReader(new InputStreamReader(in)); |
498 * </pre></blockquote> |
498 * </pre></blockquote> |
499 * |
499 * |
500 * @return the next line of text from this input stream. |
500 * @return the next line of text from this input stream. |
501 * @exception IOException if an I/O error occurs. |
501 * @throws IOException if an I/O error occurs. |
502 * @see java.io.BufferedReader#readLine() |
502 * @see java.io.BufferedReader#readLine() |
503 * @see java.io.FilterInputStream#in |
503 * @see java.io.FilterInputStream#in |
504 */ |
504 */ |
505 @Deprecated |
505 @Deprecated |
506 public final String readLine() throws IOException { |
506 public final String readLine() throws IOException { |
546 } |
546 } |
547 return String.copyValueOf(buf, 0, offset); |
547 return String.copyValueOf(buf, 0, offset); |
548 } |
548 } |
549 |
549 |
550 /** |
550 /** |
551 * See the general contract of the <code>readUTF</code> |
551 * See the general contract of the {@code readUTF} |
552 * method of <code>DataInput</code>. |
552 * method of {@code DataInput}. |
553 * <p> |
553 * <p> |
554 * Bytes |
554 * Bytes |
555 * for this operation are read from the contained |
555 * for this operation are read from the contained |
556 * input stream. |
556 * input stream. |
557 * |
557 * |
558 * @return a Unicode string. |
558 * @return a Unicode string. |
559 * @exception EOFException if this input stream reaches the end before |
559 * @throws EOFException if this input stream reaches the end before |
560 * reading all the bytes. |
560 * reading all the bytes. |
561 * @exception IOException the stream has been closed and the contained |
561 * @throws IOException the stream has been closed and the contained |
562 * input stream does not support reading after close, or |
562 * input stream does not support reading after close, or |
563 * another I/O error occurs. |
563 * another I/O error occurs. |
564 * @exception UTFDataFormatException if the bytes do not represent a valid |
564 * @throws UTFDataFormatException if the bytes do not represent a valid |
565 * modified UTF-8 encoding of a string. |
565 * modified UTF-8 encoding of a string. |
566 * @see java.io.DataInputStream#readUTF(java.io.DataInput) |
566 * @see java.io.DataInputStream#readUTF(java.io.DataInput) |
567 */ |
567 */ |
568 public final String readUTF() throws IOException { |
568 public final String readUTF() throws IOException { |
569 return readUTF(this); |
569 return readUTF(this); |
570 } |
570 } |
571 |
571 |
572 /** |
572 /** |
573 * Reads from the |
573 * Reads from the |
574 * stream <code>in</code> a representation |
574 * stream {@code in} a representation |
575 * of a Unicode character string encoded in |
575 * of a Unicode character string encoded in |
576 * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format; |
576 * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format; |
577 * this string of characters is then returned as a <code>String</code>. |
577 * this string of characters is then returned as a {@code String}. |
578 * The details of the modified UTF-8 representation |
578 * The details of the modified UTF-8 representation |
579 * are exactly the same as for the <code>readUTF</code> |
579 * are exactly the same as for the {@code readUTF} |
580 * method of <code>DataInput</code>. |
580 * method of {@code DataInput}. |
581 * |
581 * |
582 * @param in a data input stream. |
582 * @param in a data input stream. |
583 * @return a Unicode string. |
583 * @return a Unicode string. |
584 * @exception EOFException if the input stream reaches the end |
584 * @throws EOFException if the input stream reaches the end |
585 * before all the bytes. |
585 * before all the bytes. |
586 * @exception IOException the stream has been closed and the contained |
586 * @throws IOException the stream has been closed and the contained |
587 * input stream does not support reading after close, or |
587 * input stream does not support reading after close, or |
588 * another I/O error occurs. |
588 * another I/O error occurs. |
589 * @exception UTFDataFormatException if the bytes do not represent a |
589 * @throws UTFDataFormatException if the bytes do not represent a |
590 * valid modified UTF-8 encoding of a Unicode string. |
590 * valid modified UTF-8 encoding of a Unicode string. |
591 * @see java.io.DataInputStream#readUnsignedShort() |
591 * @see java.io.DataInputStream#readUnsignedShort() |
592 */ |
592 */ |
593 public static final String readUTF(DataInput in) throws IOException { |
593 public static final String readUTF(DataInput in) throws IOException { |
594 int utflen = in.readUnsignedShort(); |
594 int utflen = in.readUnsignedShort(); |