~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/imageio/stream/ImageOutputStreamImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
package javax.imageio.stream;
40
40
 
 
41
import gnu.classpath.NotImplementedException;
 
42
 
41
43
import java.io.IOException;
 
44
import java.io.UTFDataFormatException;
42
45
import java.nio.ByteOrder;
43
46
 
44
47
/**
52
55
    // Do nothing here.
53
56
  }
54
57
 
55
 
  protected void flushBits()
56
 
    throws IOException
 
58
  protected final void flushBits()
 
59
    throws IOException, NotImplementedException
57
60
  {
58
61
    // FIXME: Implement me.
59
62
    throw new Error("not implemented");
72
75
    throws IOException;
73
76
 
74
77
  public void writeBit(int bit)
75
 
    throws IOException
 
78
    throws IOException, NotImplementedException
76
79
  {
77
80
    // FIXME: Implement me.
78
81
    throw new Error("not implemented");
79
82
  }
80
83
 
81
84
  public void writeBits(long bits, int numBits)
82
 
    throws IOException
 
85
    throws IOException, NotImplementedException
83
86
  {
84
87
    // FIXME: Implement me.
85
88
    throw new Error("not implemented");
100
103
  public void writeBytes(String data)
101
104
    throws IOException
102
105
  {
103
 
    write(data.getBytes());
 
106
    // This is bogus, but it is how the method is specified.
 
107
    // Sun ought to deprecate this method.
 
108
    int len = data.length();
 
109
    for (int i = 0; i < len; ++i)
 
110
      writeByte(data.charAt(i));
104
111
  }
105
112
 
106
113
  public void writeChar(int value)
107
114
    throws IOException
108
115
  {
109
 
    writeShort((short) value);
 
116
    writeShort(value);
110
117
  }
111
118
 
112
119
  public void writeChars(char[] data, int offset, int len)
119
126
  public void writeChars(String data)
120
127
    throws IOException
121
128
  {
122
 
    // FIXME: Implement me.
123
 
    throw new Error("not implemented");
 
129
    int len = data.length();
 
130
    for (int i = 0; i < len; ++i)
 
131
      writeChar(data.charAt(i));
124
132
  }
125
133
 
126
134
  public void writeDouble(double value)
127
135
    throws IOException
128
136
  {
129
 
    writeLong((long) value);
 
137
    writeLong(Double.doubleToLongBits(value));
130
138
  }
131
139
 
132
140
  public void writeDoubles(double[] data, int offset, int len)
139
147
  public void writeFloat(float value)
140
148
    throws IOException
141
149
  {
142
 
    writeInt((int) value);
 
150
    writeInt(Float.floatToIntBits(value));
143
151
  }
144
152
  
145
153
  public void writeFloats(float[] data, int offset, int len)
237
245
      writeShort(data[offset + i]);
238
246
  }
239
247
  
240
 
  public void writeUTF(String data)
 
248
  public void writeUTF(String value)
241
249
    throws IOException
242
250
  {
243
 
    throw new Error("not implemented");
 
251
    // NOTE: this code comes directly from DataOutputStream.
 
252
    int len = value.length();
 
253
    int sum = 0;
 
254
 
 
255
    for (int i = 0; i < len && sum <= 65535; ++i)
 
256
      {
 
257
        char c = value.charAt(i);
 
258
        if (c >= '\u0001' && c <= '\u007f')
 
259
          sum += 1;
 
260
        else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))
 
261
          sum += 2;
 
262
        else
 
263
          sum += 3;
 
264
      }
 
265
 
 
266
    if (sum > 65535)
 
267
      throw new UTFDataFormatException ();
 
268
 
 
269
    int pos = 0;
 
270
    byte[] buf = new byte[sum];
 
271
 
 
272
    for (int i = 0; i < len; ++i)
 
273
      {
 
274
        char c = value.charAt(i);
 
275
        if (c >= '\u0001' && c <= '\u007f')
 
276
          buf[pos++] = (byte) c;
 
277
        else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff'))
 
278
          {
 
279
            buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6)));
 
280
            buf[pos++] = (byte) (0x80 | (0x3f & c));
 
281
          }
 
282
        else
 
283
          {
 
284
            // JSL says the first byte should be or'd with 0xc0, but
 
285
            // that is a typo.  Unicode says 0xe0, and that is what is
 
286
            // consistent with DataInputStream.
 
287
            buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12)));
 
288
            buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6)));
 
289
            buf[pos++] = (byte) (0x80 | (0x3f & c));
 
290
          }
 
291
      }
 
292
    
 
293
    writeShort (sum);
 
294
    write(buf, 0, sum);
244
295
  }
245
296
}