home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class DataOutputStream extends FilterOutputStream implements DataOutput {
- protected int written;
-
- public DataOutputStream(OutputStream out) {
- super(out);
- }
-
- public synchronized void write(int b) throws IOException {
- super.out.write(b);
- ++this.written;
- }
-
- public synchronized void write(byte[] b, int off, int len) throws IOException {
- super.out.write(b, off, len);
- this.written += len;
- }
-
- public void flush() throws IOException {
- super.out.flush();
- }
-
- public final void writeBoolean(boolean v) throws IOException {
- super.out.write(v ? 1 : 0);
- ++this.written;
- }
-
- public final void writeByte(int v) throws IOException {
- super.out.write(v);
- ++this.written;
- }
-
- public final void writeShort(int v) throws IOException {
- OutputStream out = super.out;
- out.write(v >>> 8 & 255);
- out.write(v & 255);
- this.written += 2;
- }
-
- public final void writeChar(int v) throws IOException {
- OutputStream out = super.out;
- out.write(v >>> 8 & 255);
- out.write(v & 255);
- this.written += 2;
- }
-
- public final void writeInt(int v) throws IOException {
- OutputStream out = super.out;
- out.write(v >>> 24 & 255);
- out.write(v >>> 16 & 255);
- out.write(v >>> 8 & 255);
- out.write(v & 255);
- this.written += 4;
- }
-
- public final void writeLong(long v) throws IOException {
- OutputStream out = super.out;
- out.write((int)(v >>> 56) & 255);
- out.write((int)(v >>> 48) & 255);
- out.write((int)(v >>> 40) & 255);
- out.write((int)(v >>> 32) & 255);
- out.write((int)(v >>> 24) & 255);
- out.write((int)(v >>> 16) & 255);
- out.write((int)(v >>> 8) & 255);
- out.write((int)v & 255);
- this.written += 8;
- }
-
- public final void writeFloat(float v) throws IOException {
- this.writeInt(Float.floatToIntBits(v));
- }
-
- public final void writeDouble(double v) throws IOException {
- this.writeLong(Double.doubleToLongBits(v));
- }
-
- public final void writeBytes(String s) throws IOException {
- OutputStream out = super.out;
- int len = s.length();
-
- for(int i = 0; i < len; ++i) {
- out.write((byte)s.charAt(i));
- }
-
- this.written += len;
- }
-
- public final void writeChars(String s) throws IOException {
- OutputStream out = super.out;
- int len = s.length();
-
- for(int i = 0; i < len; ++i) {
- int v = s.charAt(i);
- out.write(v >>> 8 & 255);
- out.write(v & 255);
- }
-
- this.written += len * 2;
- }
-
- public final void writeUTF(String str) throws IOException {
- OutputStream out = super.out;
- int strlen = str.length();
- int utflen = 0;
-
- for(int i = 0; i < strlen; ++i) {
- int c = str.charAt(i);
- if (c >= 1 && c <= 127) {
- ++utflen;
- } else if (c > 2047) {
- utflen += 3;
- } else {
- utflen += 2;
- }
- }
-
- out.write(utflen >>> 8 & 255);
- out.write(utflen & 255);
-
- for(int i = 0; i < strlen; ++i) {
- int c = str.charAt(i);
- if (c >= 1 && c <= 127) {
- out.write(c);
- } else if (c > 2047) {
- out.write(224 | c >> 12 & 15);
- out.write(128 | c >> 6 & 63);
- out.write(128 | c & 63);
- this.written += 2;
- } else {
- out.write(192 | c >> 6 & 31);
- out.write(128 | c & 63);
- ++this.written;
- }
- }
-
- this.written += strlen + 2;
- }
-
- public final int size() {
- return this.written;
- }
- }
-