Methods Summary |
---|
long | countUTFBytes(java.lang.String str)
int utfCount = 0, length = str.length();
for (int i = 0; i < length; i++) {
int charValue = str.charAt(i);
if (charValue > 0 && charValue <= 127) {
utfCount++;
} else if (charValue <= 2047) {
utfCount += 2;
} else {
utfCount += 3;
}
}
return utfCount;
|
public void | flush()Flushes this stream to ensure all pending data is sent out to the target
stream. This implementation then also flushes the target stream.
super.flush();
|
public final int | size()Returns the total number of bytes written to the target stream so far.
if (written < 0) {
written = Integer.MAX_VALUE;
}
return written;
|
public void | write(byte[] buffer, int offset, int count)Writes {@code count} bytes from the byte array {@code buffer} starting at
{@code offset} to the target stream.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
out.write(buffer, offset, count);
written += count;
|
public void | write(int oneByte)Writes a byte to the target stream. Only the least significant byte of
the integer {@code oneByte} is written.
out.write(oneByte);
written++;
|
public final void | writeBoolean(boolean val)Writes a boolean to the target stream.
out.write(val ? 1 : 0);
written++;
|
public final void | writeByte(int val)Writes an 8-bit byte to the target stream. Only the least significant
byte of the integer {@code val} is written.
out.write(val);
written++;
|
public final void | writeBytes(java.lang.String str)Writes the low order bytes from a string to the target stream.
if (str.length() == 0) {
return;
}
byte bytes[] = new byte[str.length()];
for (int index = 0; index < str.length(); index++) {
bytes[index] = (byte) str.charAt(index);
}
out.write(bytes);
written += bytes.length;
|
public final void | writeChar(int val)Writes a 16-bit character to the target stream. Only the two lower bytes
of the integer {@code val} are written, with the higher one written
first. This corresponds to the Unicode value of {@code val}.
out.write(val >> 8);
out.write(val);
written += 2;
|
public final void | writeChars(java.lang.String str)Writes the 16-bit characters contained in {@code str} to the target
stream.
byte newBytes[] = new byte[str.length() * 2];
for (int index = 0; index < str.length(); index++) {
int newIndex = index == 0 ? index : index * 2;
newBytes[newIndex] = (byte) (str.charAt(index) >> 8);
newBytes[newIndex + 1] = (byte) str.charAt(index);
}
out.write(newBytes);
written += newBytes.length;
|
public final void | writeDouble(double val)Writes a 64-bit double to the target stream. The resulting output is the
eight bytes resulting from calling Double.doubleToLongBits().
writeLong(Double.doubleToLongBits(val));
|
public final void | writeFloat(float val)Writes a 32-bit float to the target stream. The resulting output is the
four bytes resulting from calling Float.floatToIntBits().
writeInt(Float.floatToIntBits(val));
|
public final void | writeInt(int val)Writes a 32-bit int to the target stream. The resulting output is the
four bytes, highest order first, of {@code val}.
out.write(val >> 24);
out.write(val >> 16);
out.write(val >> 8);
out.write(val);
written += 4;
|
public final void | writeLong(long val)Writes a 64-bit long to the target stream. The resulting output is the
eight bytes, highest order first, of {@code val}.
writeInt((int) (val >> 32));
writeInt((int) val);
|
public final void | writeShort(int val)Writes the specified 16-bit short to the target stream. Only the lower
two bytes of the integer {@code val} are written, with the higher one
written first.
writeChar(val);
|
public final void | writeUTF(java.lang.String str)Writes the specified encoded in {@link DataInput modified UTF-8} to this
stream.
// END android-added
int length = str.length();
// BEGIN android-changed
if (length <= MAX_BUF_SIZE / 3) {
int size = length * 3;
byte[] utfBytes = new byte[size];
// boolean makeBuf = true;
// synchronized (DataInputStream.byteBuf) {
// if (DataInputStream.useShared) {
// DataInputStream.useShared = false;
// makeBuf = false;
// }
// }
// if (makeBuf) {
// utfBytes = new byte[size];
// } else {
// if (DataInputStream.byteBuf.length < size) {
// DataInputStream.byteBuf = new byte[size];
// }
// utfBytes = DataInputStream.byteBuf;
// }
int utfIndex = 0;
for (int i = 0; i < length; i++) {
int charValue = str.charAt(i);
if (charValue > 0 && charValue <= 127) {
utfBytes[utfIndex++] = (byte) charValue;
} else if (charValue <= 2047) {
utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
} else {
utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
}
}
writeShort(utfIndex);
write(utfBytes, 0, utfIndex);
// if (!makeBuf) {
// DataInputStream.useShared = true;
// }
} else {
long utfCount;
if (length <= 65535 && (utfCount = countUTFBytes(str)) <= 65535) {
writeShort((int) utfCount);
writeUTFBytes(str, utfCount);
} else {
throw new UTFDataFormatException(Msg.getString("K0068")); //$NON-NLS-1$
}
}
// END android-changed
|
void | writeUTFBytes(java.lang.String str, long count)
boolean single = true;
int size = (int) count;
// BEGIN android-changed
if (count > MAX_BUF_SIZE) {
single = false;
size = MAX_BUF_SIZE;
}
byte[] utfBytes = new byte[size];
// END android-changed
// BEGIN android-removed
// boolean makeBuf = true;
// if (DataInputStream.useShared) {
// synchronized (DataInputStream.cacheLock) {
// if (DataInputStream.useShared) {
// DataInputStream.useShared = false;
// makeBuf = false;
// }
// }
// }
// if (makeBuf) {
// utfBytes = new byte[size];
// } else {
// // byteBuf is not protected by the cacheLock, so sample it first
// utfBytes = DataInputStream.byteBuf;
// if (utfBytes.length < size) {
// utfBytes = DataInputStream.byteBuf = new byte[size];
// }
// }
// END android-removed
int utfIndex = 0, i = 0, length = str.length();
int end = length;
while (i < length) {
if (!single) {
end = i + ((utfBytes.length - utfIndex) / 3);
if (end > length) {
end = length;
}
}
for (int j = i; j < end; j++) {
int charValue = str.charAt(j);
if (charValue > 0 && charValue <= 127) {
utfBytes[utfIndex++] = (byte) charValue;
} else if (charValue <= 2047) {
utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
} else {
utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
}
}
if (single || utfIndex > utfBytes.length - 300) {
write(utfBytes, 0, utfIndex);
if (single) {
return;
}
utfIndex = 0;
}
i = end;
}
if (utfIndex > 0) {
write(utfBytes, 0, utfIndex);
}
// BEGIN android-removed
// if (!makeBuf) {
// // Update the useShared flag optimistically (see DataInputStream
// // equivalent)
// DataInputStream.useShared = true;
// }
// END android-removed
|