1 // DataOutputStream.java - Output filter that implements DataOutput
3 /* Copyright (C) 1998, 1999 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date September 24, 1998
18 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
19 * "The Java Language Specification", ISBN 0-201-63451-1
20 * Status: Complete to version 1.1.
23 public class DataOutputStream
extends FilterOutputStream
implements DataOutput
25 public DataOutputStream (OutputStream out
)
31 public void flush () throws IOException
36 public final int size ()
41 public synchronized void write (int b
) throws IOException
47 public synchronized void write (byte[] b
, int off
, int len
)
48 throws IOException
, NullPointerException
, IndexOutOfBoundsException
50 out
.write(b
, off
, len
);
54 public final void writeBoolean (boolean v
) throws IOException
59 public final void writeByte (int v
) throws IOException
64 public final void writeShort (int v
) throws IOException
66 write ((byte) (0xff & (v
>> 8)));
67 write ((byte) (0xff & v
));
70 public final void writeChar (int v
) throws IOException
72 write ((byte) (0xff & (v
>> 8)));
73 write ((byte) (0xff & v
));
76 public final void writeInt (int v
) throws IOException
78 write ((byte) (0xff & (v
>> 24)));
79 write ((byte) (0xff & (v
>> 16)));
80 write ((byte) (0xff & (v
>> 8)));
81 write ((byte) (0xff & v
));
84 public final void writeLong (long v
) throws IOException
86 write ((byte) (0xff & (v
>> 56)));
87 write ((byte) (0xff & (v
>> 48)));
88 write ((byte) (0xff & (v
>> 40)));
89 write ((byte) (0xff & (v
>> 32)));
90 write ((byte) (0xff & (v
>> 24)));
91 write ((byte) (0xff & (v
>> 16)));
92 write ((byte) (0xff & (v
>> 8)));
93 write ((byte) (0xff & v
));
96 public final void writeFloat (float v
) throws IOException
98 writeInt (Float
.floatToIntBits(v
));
101 public final void writeDouble (double v
) throws IOException
103 writeLong (Double
.doubleToLongBits(v
));
106 public final void writeBytes (String s
) throws IOException
108 int len
= s
.length();
109 for (int i
= 0; i
< len
; ++i
)
110 writeByte (s
.charAt(i
));
113 public final void writeChars (String s
) throws IOException
115 int len
= s
.length();
116 for (int i
= 0; i
< len
; ++i
)
117 writeChar (s
.charAt(i
));
120 public final void writeUTF (String s
) throws IOException
122 int len
= s
.length();
125 for (int i
= 0; i
< len
&& sum
<= 65535; ++i
)
127 char c
= s
.charAt(i
);
128 if (c
>= '\u0001' && c
<= '\u007f')
130 else if (c
== '\u0000' || (c
>= '\u0080' && c
<= '\u07ff'))
137 throw new UTFDataFormatException ();
141 for (int i
= 0; i
< len
; ++i
)
143 char c
= s
.charAt(i
);
144 if (c
>= '\u0001' && c
<= '\u007f')
146 else if (c
== '\u0000' || (c
>= '\u0080' && c
<= '\u07ff'))
148 write (0xc0 | (0x1f & (c
>> 6)));
149 write (0x80 | (0x3f & c
));
153 // JSL says the first byte should be or'd with 0xc0, but
154 // that is a typo. Unicode says 0xe0, and that is what is
155 // consistent with DataInputStream.
156 write (0xe0 | (0x0f & (c
>> 12)));
157 write (0x80 | (0x3f & (c
>> 6)));
158 write (0x80 | (0x3f & c
));
163 // Number of bytes written so far.
164 protected int written
;