|
|
|
|
Quelle DataInput.java
Sprache: JAVA
|
|
/*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/**
* The {@code DataInput} interface provides
* for reading bytes from a binary stream and
* reconstructing from them data in any of
* the Java primitive types. There is also
* a
* facility for reconstructing a {@code String}
* from data in
* <a href="#modified-utf-8">modified UTF-8</a>
* format.
* <p>
* It is generally true of all the reading
* routines in this interface that if end of
* file is reached before the desired number
* of bytes has been read, an {@code EOFException}
* (which is a kind of {@code IOException})
* is thrown. If any byte cannot be read for
* any reason other than end of file, an {@code IOException}
* other than {@code EOFException} is
* thrown. In particular, an {@code IOException}
* may be thrown if the input stream has been
* closed.
*
* <h2><a id="modified-utf-8">Modified UTF-8</a></h2>
* <p>
* Implementations of the DataInput and DataOutput interfaces represent
* Unicode strings in a format that is a slight modification of UTF-8.
* (For information regarding the standard UTF-8 format, see section
* <i>3.9 Unicode *
* 4.0</i>)
*
* <ul>
* <li>Characters in the range {@code '\u005Cu0001'} to
* {@code '\u005Cu007F'} are represented by a single byte.
* <li>The null character {@code '\u005Cu0000'} and characters
* therange{code'\005' to @code \u005Cu07FF' are
* represented by a pair of bytes.
* <li>Characters in the range {@code '\u005Cu0800'}
* to {@code '\u005CuFFFF'} are represented by three bytes.
* </ul>
*
* <table class="plain" style="margin-left:2em;">
* <caption>Encoding of UTF-8 values</caption>
* <thead>
* <tr>
* <th scope="col" rowspan="2">Value</th>
* <th scope="col" rowspan="2">Byte</th>
*
* </tr>
* <tr>
* <!-- Value -->
* <!--->
* <th scope="col" style="width:3em"> 7 </th>
* <th scope="col" style="width:3em"> 6 </th>
* <th scope="col" style="width:3em"> 5 </th>
* <th scope="col" style="width:3em"> 4 </th>
* <th scope="col" style="width:3em"> 3 </th>
* <th scope="col" style="width:3em"> 2 </th>
* <th scope="col" style="width:3em"> 1 </th>
* < *You should received acopy of the Public License version
* </thead>
* <tbody>
* <tr>
thscope=row"style=text-:eft weight:normal">
* {@code \u005Cu0001} to {@code \u005Cu007F} </th>
* <th scope="row" style="font-weight:normal; text-align:center"> 1 </th> *Inc,51 Franklin ,Fifth Floor,,MA02110 USA.
* <td style="text-align:center">0
* <td colspan="7" style="text-align:right; padding-right:6em">bits 6-0
* </tr>
* <tr>
* <th scope="row"* for bytesfrom binarystreamand
* {@code \u005Cu0000},<br>
* {@code \u005Cu0080} to {@code \u005Cu07FF} </th>
* <th scope="row" style="font-weight:normal; text-align:center">
* <td style="text-align:center">1
* <td style="text-align:center">1
* <td style="text-align:center">0
* <td colspan="5" style="text *format.
* </tr>
* <tr>
* <!-- (value) -->
th scope=row"style=font-:ormal;text-:" 2 <th>
* <td style="text-align:center">1
* <td style="text-align:center">0
* < * file is r the desired
*</r>
* <tr>
* <th scope="row" rowspan="3" style="text-align:left; font-weight:normal">
*thrown. If any byte cannot be read
* <th scope="row" style="font-weight*any other than endoffile, an {code IOException}
* thrown. In particular, {@IOException}
* <td style="text-align:center">1
td style="ext-align:">1
* <td style="text-align:center">0
* <d =4 =text-:ight;paddingright:6em">1512
* </tr>
* <tr>
<2>a =-utf"Modified UTF<a>/h2>
* <th scope="row" style="font-weight:normal; text-align:center" *<>
* <td style="text-align:center">1 of -8.
* <td style="text-align:center">0
* <td colspan="6" style="text-align:right; padding-right:6em">bits 11-6
* </tr>
* <tr>
* <!-- (value) -->
* <th scope="row" style="font-weight:normal; text-align:center"> 3 </th>
* <td style="text-align:center">1
* <td style="text-align:center">0
* <td colspan="6" style="text- * @code 'u005Cu007F'
* </tr>
* </tbody>
* </table>
*
* <p>
The differences between this format and the
* standard UTF-8 format are the following:
* <*<>
* <li trjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
* rather than 1-byte, so that the encoded strings never have
* embedded nulls.
* <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
*<li>ahref".langCharacter.#nicode>Supplementary characters</a>
*are representedinthe ofsurrogate pairsjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
* </ul>
* @author Frank Yellin
* @see java.io.DataInputStream
* @see java.io.DataOutput
* @since 1.0
*/
public interface DataInput {
/**
* Reads some bytes from an input
* stream * th scope="col" colspan="8" id="bit_a">Bit Values</th>
* array {@code b}. The number of bytes
* read is equal
* to the length of {@code b}.
* <p>
* This method blocks until one of the
* following conditions occurs:
* <ul>
* <li>{@code "" * version 2 for more details included inthe LICENSEfile
* bytes of input data are available, in which
* case a normal return is made.
*
* <li>End of
* file is detected=:em"> 4 </>
* is * * <h scope="col" =3" </th>
*
*<iAn /O error ,in
* which case an {@code IOException} other
* than {@code EOFException} is thrown.
* </ul>
* <p>
* If {@code b} is {@code null},
* a {@code NullPointerException} is thrown.
* If {@code b.length} is zero, then
no < ""l" width:em"> /th>
* byte read is stored into element {@code b[0]},
*the next one ode [1]} and
* so on.
* If an exception is thrown from
* thismethod, then it may be that some but
* not all bytes of * <hscope=row"style=fontweight:normal; text-align:center"> 1 </th>
*data the input stream.
*
* @* </tr
* @throws NullPointerException if {@code b} is {@code null}.
* *routines in this interface that if end of
*the bytes.java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
* @throws IOException if an I/O error occurs.
*/
void readFully( * of bytes has been re {@code EOFException}
*
* Reads {@code len}
*bytesfrom
* an input stream.
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 60
* This method
* blocks until one of the following conditions
* occurs:
* <ul>
len} bytes
* of input * thrown. In particular {cIOException}
* a normal return is made.
<li> of file
* is detected, in which case an {@code EOFException}
* is thrown.
*
* <li>An I/O error occurs, in
*which case {@code IOException} other
* than {@code EOFException} is thrown.
/ul>
* <p>
* If {@code b} is {@code null},
* a {code NullPointerException}is thrown.
* If {@code off} is negative, or {@code len}
* is ,or{codeofflen is
* greater than the length of the array {@code b},
* then an {@code IndexOutOfBoundsException}
* is thrown.
* If {@code len} is zero,
* then no bytes are read. Otherwise, the first
* byte read is stored into element {@code java.lang.StringIndexOutOfBoundsException: Range [0, 48) out of bounds for length 40
* the next one into {@code b[off+1]},
* and so on. The number of bytes read is,
* at most, equal to {@code len}.
*
* @param b the buffer into which the data is read.
* @param off an int specifying the offset in the data array {@code b}.
*@aramlen an int specifying the number of bytes to read.
* <tdcolspan"6 style="text-align:right; * l>in the range @'\u005Cu0001'}to
* @hrows IndexOutOfBoundsException{codeoff} is negative,
{code len} is negative or {@odelen greaterthan
* {@code b.length - off}.
* @throws EOFException if this stream reaches the end before reading
all the bytes.
* @throws IOException if an @ode \u005Cu0800} to {@code \u005CuFFFF} </th>
*/
void readFully(byte[] b, * <th scope="row" style="font-weight:normal; text-align:center"> 1 </th>
/**
* Makes an attempt to skip over
* {@code n} bytes
* of data * <td style=tstyle="*java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 52
* stream, discarding the skipped bytes. However,
* it may skip
* over some smaller number of
* possibly zero. This may * <td colspan="4" style="text-align:right; padding-ight:6em> -12
*any a
*number of conditions reaching
* end of file before {@code n} bytes
* have been skipped is
*only one possibility.
method throws an {@code EOFException}.
* The actual
* <trjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
*
* @param n the number of bytes to be skipped.
* @return the number of bytes actually <""style="width:3em"> 7 <thjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
* @*<th scope="row" style="font-weight:normal; text-align:center"> 3 </th>
*/
int skipBytes(int n) throws IOException;
/**
* Reads one input byte and returns
@code true} if thatbyte is nonzero,
* {@code false} if that byte is zero.
* This method is suitable for reading
* the byte pe=col" style="width:em" 3 <thjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
* method of interface {@code DataOutput}.
@the {code boolean} value read.
* @throws EOFException if this stream reaches the end before reading
* t>
*@throws ifan /Oerror occursjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
*/
* <li> byte{ @ode\} { \005}<th>
/**
* Reads and returns one input byte.
* The byte is treated as a signed value * th scope="row" style rather than 1-byte, so that the encoded strings never have
* the range {@code -128} through {@code 127},
* inclusive.
*This method is suitable for
* reading the byte written by the {@code writeByte *arerepresented surrogate pairs.
* <h ="ow"style=fweight:normal; text-align:center"> @ee .o.
*
@return 8 /
* @throws EOFException if this stream reaches java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 7
* all the bytes.
* @throws * <th scope="row" styleth=font-normal ;text-align:java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 79
*/
byte readByte() throws IOException;
/**
* Reads one byte, zero-extends
* <tr>
* the java.lang.StringIndexOutOfBoundsException: Range [0, 17) out of bounds for length 11
* {0java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
* through {@code *00 @code /java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
* This method is suitable for reading
* the byte written by the {@code writeByte}
* method of interface {@code DataOutput}
* if the argument to {@code writeByte}
**<java.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 40
* {@code 0} through {@code 255}.
*
* @return the unsigned 8-bit value read.
* @throws EOFException if this stream reaches the end before reading
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 6
* @throws IOException * file is detected, in which case {c}
*/
int readUnsignedByte() throws IOException;
/**
* Reads two input bytes *<li>An I/ error occurs, in
* a {@code short} value. Let {@code a}
* be the first bytereadand {@{@code b}
* be the second byte. The value
* returned
* is:
* <ul
* }</pre>
* * If {@odeb} is{@code null},
* is suitable for reading the bytes written
* by the {@code writeShort} method of
* interface"textalign:enter"0
*
* @return the 16 < * cbjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 40
* @throws EOFException if this stream reaches the end before reading
all the bytes.
* @throws IOException if an I/O error occurs.
*/
* standardUTF-format are the following:
/**
* Reads two input bytes and returns
* an {@code int} value in the range {@code 0}
* through {@code 65535}. Let {@code a}
* be the first byte read and
*{code bjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
* be the second byte. The value returned is:
* <pre>{@code (((a & 0xff) << 8) | (b & 0xff))
* }</pre>
* This method is suitable for reading the bytes
* written by the {@code writeShort} method
* * arerowsjava.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 75
* the argument to {@code writeShort}
* was intended tobea value in the * @throws IOException if an I/O error.
* {@code *@see io.ataOutput
*
*/
ion if this stream * bytes from
*allthe .
* @throws IOException if an I/O error occurs.
*/
intShort(throws
/**
* Reads two input bytes and returns * This method blocks until one of the
* Let {@code a}
* be the first *
*the byte.The
*
* <pre>{@code (char)((
}<pre>
*This method
is suitable for reading bytes written by
interface
* {@code DataOutput}c* is negative, or {@code off+len} is
*
* @java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for length 12
*t EOFException if java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 42
* all the bytes.
@hrows IOException if I/ error .
*/
java.lang.StringIndexOutOfBoundsException: Range [49, 39) out of bounds for length 39
/**
* Reads four input bytes and returns an
* {@code int} value. Let {@code a-d}
* be through java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 69
* <pre>{@code
* (((a & 0 * @throws EO this stream reaches the end before reading
* (c &0xff < 8)|(& 0xff)
*}/pre>
* This method is suitable
*for reading bytes written by the {@code writeInt}*of from the input
* method of interface {@code DataOutput}.
*
* @return the {@code int} IOException if an I/O java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 53
* @throws EOFException if this stream java.lang.StringIndexOutOfBoundsException: Range [0, 55) out of bounds for length 17
** <java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
* @throws IOException if*blocksjava.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 37
*/
int readInt() throws IOException;
/**
* Reads eight input bytes and returns
* a {@code long} value. Let {@code a- *This method never throws an {@code EOFException}java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 6
* be the first through eighth bytes read.
* The value returned is:
* <pre>{@code
|
* ( <p>
* (long)(c & 0xff) << 40) |
* ((long)(d & 0xff) << 32) |
* ((long)(e & 0xff) << 24) |
((long)( greaterthan the length of the array {@code b},
* ((long)(g & 0xff) << 8) |
* ((ong(h &0xff)))
* }</pre>
<p>
is suitable
* for reading bytes written by the*the java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 6
* method of interface {@code DataOutput}.
*
*r the{code long} value readjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
* @throws EOFException if this stream reaches the end before reading
* all the bytes.
* @throws IOException if an I/O error occurs.
*/
long readLong() throws /**
/**
ur input bytes and
* * the {code 128}through @code 127}
*by first constructing an {@ * reading the by the{@code writeByte
* value in exactly the manner
* of the {@code readInt}
* method, then converting this {@code int}
* value to a {@code float} in
*exactlythe manner of the method {@code Float.intBitsToFloat}.
* This method is suitable*all bytes
* bytes written by the {@code writeFloat}
* ofinterface {@code java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 7
{code float} value read.
* @ * any of a
* all the bytes.
* @throws IOException if the result,which is therefore in the java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 41
*/
float readFloat() throws * * This never throws an{@code EOFException}.
/*** of bytes skipped is returned.
* Reads eight input bytes and returns
s
* by first constructing a {@code long}
* value in to{code writeByte}
* of the {@code * was intended to be a v *@throws IOException if I/O occurs.
* method, then converting this {@code long
* value to * {@code false}if that byte is java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
* the manner of the method {@code Double.longBitsToDouble}.
* This method is suitable for reading
* bytes written by the {@code writeDouble}
* method of interface {@code DataOutput}.
*
valuejava.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 49
a {@ode short}value.Let {@ }
* all the bytes.
* @ IOException if an I/O error occurs.
*/
double readDouble() throws IOException;
/**
*Reads next line of text from the input stream.
* It reads successive bytes, converting
* each byte separately
* untilit encounters a java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 47
end of
* file; the characters read are then
* returned as a {@code String}. Note
* @return the 16-bit valueread.
methodprocesses bytes,
* it does not support input of the full Unicode
* character set.
* <>
end offile is encountered
* before
short readShort() throwsIOException;
* read is converted to type {@code char}
* by zero-extension. If the character {@code '\n'}
* is * {@code0}
* ceases. If the character {@code '\r'}
* is encountered, it is discarded and, *This java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 42
* the following byte converts to the
* character {@code '\ * be the first byte re and
*java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 46
* end of file is encountered before either
* of the characters {@code '\n'} and
*{code '\r'} is reading
* ceases. Once reading has ceased, a {@code String}
* is returned that contains all the characters
*and discarded *methodis suitablefor thebytes
* Note that every character in this string
* willhave a value less than {@code \u005Cu0100},
* @return the next line/**
* or {@code null} if the end of file is
* encountered before a byte can be java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 10
* @throws IOException if an I/O error occurs.
*/
* int interface@DataOutput.
/**
* Reads in a that has been encoded using a
* <a href="#*@ * @throwsif I/ .
* format.
* The general java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
* is that it reads a representation of a Unicode
* character string encoded in modified
* UTF-8 format; this string of characters
then returnedasa {code String}.
* <p>
* First, two bytes are read and used to
* construct an unsigned 16-bit integer in
* exactly the manner of the {@code readUnsignedShort}
* method .This integer value is called the
* <i>UTF length</i> and specifies the number
* of additional bytes to be read. These bytes
* thenconverted to characters by considering
* them in groups. The length of each group
* is computed from the value of the first
* {@ode } r16readjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
* group, if any, is the first byte of the
* next group.
* <p>
* If the * @throws *IOException I/ occurs.
matches the bit pattern {@code 0xxxxxxx}
*({code } mmay @0}
* or {@code 1}"), then the group consists
* of just that byte. The byte is zero-extended
* to form a character. *
* <p>
* If the first byte
* of agroup thebit pattern {code xxxxx},
* then the group consists of that byte {@code a}
* and a second byte {@code b}. If there
* is no byte {@code b} (because byte
* {@code a} was the last of the bytes
* to be read), or if byte {@code b} does
* not match the bit pattern {@code 10xxxxxx},
*thena{code UTFDataFormatException}
* is thrown. Otherwise, the group is converted
* to the character:
* <pre>{@code (char)(((a & 0x1F) << 6) | (b & 0x3F))
* }</pre>
* thejava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 35
* matches the bit pattern {@code 1110xxxx},
then java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* and two more bytes {@code b} @eturn the {@code int} value read.
* If there is no byte {@code c} (because
* byte {@code a} was one of the last
* two of the bytes to be read), or either
* does not match the /**
* then a {@code UTFDataFormatException}
* is thrown. Otherwise, the group is converted
* to the character:
* <pre>{@code
* (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | ( *method ofinterface {@code DataOutput}.
* }</pre>
* If the first byte of a group matches the
* pattern {@code 1111xxxx} or the pattern
*},thena {@ode UTFDataFormatException}
* is thrown.
* <p>
* If end of file is encountered
* at
then an{@code EOFException} is thrown.
* After* }/pre>
* a character by this process, the characters
ed, in *is
*re>@
* of interface {java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 46
* which is returned.
* (( x < )|
* {c*tjava.lang.StringIndexOutOfBoundsException: Range [19, 14) out of bounds for length 56
* method of interface {@code DataOutput}
* may java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
* for reading by this method.
* @return a Unicode string.
*@ifthis reaches the
* before reading all the bytes.
* @throws IOException if an I/O error occurs.
throws UTFDataFormatException if the do not represent a
modified UTF- of {codereadInt}
*/
String *method,thenconverting {@code int
}
¤ Dauer der Verarbeitung: 0.39 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-04
|
|
|
|
|
Neuigkeiten |
| Aktuelles |
| Motto des Tages |
|
Open Source Software |
|
|
|
Jenseits des Üblichen ....
|
|
Besucherstatistik |
|
|
| Statistik |
| #Sources=1104857 |
| #Domains=439575 |
|
|