Methods Summary |
---|
public boolean | readBoolean()Reads a boolean from the underlying input stream by
reading a single byte. If the byte is zero, false is returned.
If the byte is positive, true is returned.
int bool = in.read();
if (bool == -1) throw new EOFException();
return (bool != 0);
|
public byte | readByte(int b)Reads a signed byte from the underlying input stream
with value between -128 and 127
int temp = in.read();
if (temp == -1) throw new EOFException();
return (byte) temp;
|
public char | readChar()Reads a two byte Unicode char from the underlying
input stream in little endian order, low byte first.
int byte1 = in.read();
int byte2 = in.read();
if (byte2 == -1) throw new EOFException();
return (char) ((byte2 << 8) + byte1);
|
public final double | readDouble()
return Double.longBitsToDouble(this.readLong());
|
public final float | readFloat()
return Float.intBitsToFloat(this.readInt());
|
public int | readInt()Reads a four byte signed int from the underlying
input stream in little endian order, low byte first.
int byte1, byte2, byte3, byte4;
synchronized (this) {
byte1 = in.read();
byte2 = in.read();
byte3 = in.read();
byte4 = in.read();
}
if (byte4 == -1) {
throw new EOFException();
}
return (byte4 << 24) + (byte3 << 16) + (byte2 << 8) + byte1;
|
public long | readLong()Reads an eight byte signed int from the underlying
input stream in little endian order, low byte first.
long byte1 = in.read();
long byte2 = in.read();
long byte3 = in.read();
long byte4 = in.read();
long byte5 = in.read();
long byte6 = in.read();
long byte7 = in.read();
long byte8 = in.read();
if (byte8 == -1) {
throw new EOFException();
}
return (byte8 << 56) + (byte7 << 48) + (byte6 << 40) + (byte5 << 32) +
(byte4 << 24) + (byte3 << 16) + (byte2 << 8) + byte1;
|
public short | readShort()Reads a two byte signed short from the underlying
input stream in little endian order, low byte first.
int byte1 = in.read();
int byte2 = in.read();
// only need to test last byte read
// if byte1 is -1 so is byte2
if (byte2 == -1) throw new EOFException();
return (short) ((byte2 << 8) + byte1);
|
public java.lang.String | readUTF()Reads a string of no more than 65,535 characters
from the underlying input stream using UTF-8
encoding. This method first reads a two byte short
in big endian order as required by the
UTF-8 specification. This gives the number of bytes in
the UTF-8 encoded version of the string.
Next this many bytes are read and decoded as UTF-8
encoded characters.
int byte1 = in.read();
int byte2 = in.read();
if (byte2 == -1) throw new EOFException();
int numbytes = (byte1 << 8) + byte2;
char result[] = new char[numbytes];
int numread = 0;
int numchars = 0;
while (numread < numbytes) {
int c1 = readUnsignedByte();
int c2, c3;
// look at the first four bits of c1 to determine how many
// bytes in this char
int test = c1 >> 4;
if (test < 8) { // one byte
numread++;
result[numchars++] = (char) c1;
}
else if (test == 12 || test == 13) { // two bytes
numread += 2;
if (numread > numbytes) throw new UTFDataFormatException();
c2 = readUnsignedByte();
if ((c2 & 0xC0) != 0x80) throw new UTFDataFormatException();
result[numchars++] = (char) (((c1 & 0x1F) << 6) | (c2 & 0x3F));
}
else if (test == 14) { // three bytes
numread += 3;
if (numread > numbytes) throw new UTFDataFormatException();
c2 = readUnsignedByte();
c3 = readUnsignedByte();
if (((c2 & 0xC0) != 0x80) || ((c3 & 0xC0) != 0x80)) {
throw new UTFDataFormatException();
}
result[numchars++] = (char)
(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
}
else { // malformed
throw new UTFDataFormatException();
}
} // end while
return new String(result, 0, numchars);
|
public int | readUnsignedByte()Reads an unsigned byte from the underlying
input stream with value between 0 and 255
int temp = in.read();
if (temp == -1) throw new EOFException();
return temp;
|
public int | readUnsignedShort()Reads a two byte unsigned short from the underlying
input stream in little endian order, low byte first.
int byte1 = in.read();
int byte2 = in.read();
if (byte2 == -1) throw new EOFException();
return (byte2 << 8) + byte1;
|
public final int | skipBytes(int n)Skip exactly n bytes of input in the underlying
input stream. This method blocks until all the bytes are skipped,
the end of the stream is detected, or an exception is thrown.
for (int i = 0; i < n; i += (int) skip(n - i));
return n;
|