Methods Summary |
---|
public int | size()Returns the number of bytes written to this little endian output stream.
(This class is not thread-safe with respect to this method. It is
possible that this number is temporarily less than the actual
number of bytes written.)
return written;
|
public synchronized void | write(int b)Writes the specified byte value to the underlying output stream.
out.write(b);
written++;
|
public synchronized void | write(byte[] data, int offset, int length)Writes length bytes from the specified byte array
starting at offset to the underlying output stream.
out.write(data, offset, length);
written += length;
|
public void | writeBoolean(boolean b)Writes a boolean to the underlying output stream as
a single byte. If the argument is true, the byte value 1 is written.
If the argument is false, the byte value 0 in written.
if (b) this.write(1);
else this.write(0);
|
public void | writeByte(int b)Writes out a byte to the underlying output stream
out.write(b);
written++;
|
public void | writeBytes(java.lang.String s)Writes a string to the underlying output stream as a sequence of
bytes. Each character is written to the data output stream as
if by the writeByte() method.
int length = s.length();
for (int i = 0; i < length; i++) {
out.write((byte) s.charAt(i));
}
written += length;
|
public void | writeChar(int c)Writes a two byte char to the underlying output stream
in little endian order, low byte first.
out.write(c & 0xFF);
out.write((c >>> 8) & 0xFF);
written += 2;
|
public void | writeChars(java.lang.String s)Writes a string to the underlying output stream as a sequence of
characters. Each character is written to the data output stream as
if by the writeChar method.
int length = s.length();
for (int i = 0; i < length; i++) {
int c = s.charAt(i);
out.write(c & 0xFF);
out.write((c >>> 8) & 0xFF);
}
written += length * 2;
|
public final void | writeDouble(double d)Writes an 8 byte Java double to the underlying output stream in
little endian order.
this.writeLong(Double.doubleToLongBits(d));
|
public final void | writeFloat(float f)Writes a 4 byte Java float to the underlying output stream in
little endian order.
this.writeInt(Float.floatToIntBits(f));
|
public void | writeInt(int i)Writes a four-byte int to the underlying output stream
in little endian order, low byte first, high byte last
out.write(i & 0xFF);
out.write((i >>> 8) & 0xFF);
out.write((i >>> 16) & 0xFF);
out.write((i >>> 24) & 0xFF);
written += 4;
|
public void | writeLong(long l)Writes an eight-byte long to the underlying output stream
in little endian order, low byte first, high byte last
out.write((int) l & 0xFF);
out.write((int) (l >>> 8) & 0xFF);
out.write((int) (l >>> 16) & 0xFF);
out.write((int) (l >>> 24) & 0xFF);
out.write((int) (l >>> 32) & 0xFF);
out.write((int) (l >>> 40) & 0xFF);
out.write((int) (l >>> 48) & 0xFF);
out.write((int) (l >>> 56) & 0xFF);
written += 8;
|
public void | writeShort(int s)Writes a two byte short to the underlying output stream in
little endian order, low byte first.
out.write(s & 0xFF);
out.write((s >>> 8) & 0xFF);
written += 2;
|
public void | writeUTF(java.lang.String s)Writes a string of no more than 65,535 characters
to the underlying output stream using little endian UTF-8
encoding. This method first writes a two byte short
in little endian order as if by the
writeShort() method. This gives the number of bytes in
the UTF-8 encoded version of the string, not the number of characters in the string.
Next each character
of the string is written using the little endian UTF-8 encoding
for the character.
int strlen = s.length();
int utflen = 0;
for (int i = 0 ; i < strlen ; i++) {
int c = s.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) utflen++;
else if (c > 0x07FF) utflen += 3;
else utflen += 2;
}
if (utflen > 65535) throw new UTFDataFormatException();
out.write(utflen & 0xFF);
out.write((utflen >>> 8) & 0xFF);
for (int i = 0 ; i < strlen ; i++) {
int c = s.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out.write(c);
}
else if (c > 0x07FF) {
out.write(0x80 | (c & 0x3F));
out.write(0x80 | ((c >> 6) & 0x3F));
out.write(0xE0 | ((c >> 12) & 0x0F));
written += 2;
}
else {
out.write(0x80 | (c & 0x3F));
out.write(0xC0 | ((c >> 6) & 0x1F));
written += 1;
}
}
written += strlen + 2;
|