1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46:
47:
50: public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl
51: implements ImageOutputStream
52: {
53: public ImageOutputStreamImpl()
54: {
55:
56: }
57:
58: protected final void flushBits()
59: throws IOException, NotImplementedException
60: {
61:
62: throw new Error("not implemented");
63: }
64:
65: public void write(byte[] data)
66: throws IOException
67: {
68: write(data, 0, data.length);
69: }
70:
71: public abstract void write(byte[] data, int offset, int len)
72: throws IOException;
73:
74: public abstract void write(int value)
75: throws IOException;
76:
77: public void writeBit(int bit)
78: throws IOException, NotImplementedException
79: {
80:
81: throw new Error("not implemented");
82: }
83:
84: public void writeBits(long bits, int numBits)
85: throws IOException, NotImplementedException
86: {
87:
88: throw new Error("not implemented");
89: }
90:
91: public void writeBoolean(boolean value)
92: throws IOException
93: {
94: writeByte(value ? 1 : 0);
95: }
96:
97: public void writeByte(int value)
98: throws IOException
99: {
100: write(value & 0xff);
101: }
102:
103: public void writeBytes(String data)
104: throws IOException
105: {
106:
107:
108: int len = data.length();
109: for (int i = 0; i < len; ++i)
110: writeByte(data.charAt(i));
111: }
112:
113: public void writeChar(int value)
114: throws IOException
115: {
116: writeShort(value);
117: }
118:
119: public void writeChars(char[] data, int offset, int len)
120: throws IOException
121: {
122: for(int i = 0; i < len; ++len)
123: writeChar(data[offset + i]);
124: }
125:
126: public void writeChars(String data)
127: throws IOException
128: {
129: int len = data.length();
130: for (int i = 0; i < len; ++i)
131: writeChar(data.charAt(i));
132: }
133:
134: public void writeDouble(double value)
135: throws IOException
136: {
137: writeLong(Double.doubleToLongBits(value));
138: }
139:
140: public void writeDoubles(double[] data, int offset, int len)
141: throws IOException
142: {
143: for(int i = 0; i < len; ++len)
144: writeDouble(data[offset + i]);
145: }
146:
147: public void writeFloat(float value)
148: throws IOException
149: {
150: writeInt(Float.floatToIntBits(value));
151: }
152:
153: public void writeFloats(float[] data, int offset, int len)
154: throws IOException
155: {
156: for(int i = 0; i < len; ++len)
157: writeFloat(data[offset + i]);
158: }
159:
160: public void writeInt(int value)
161: throws IOException
162: {
163: if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
164: {
165: buffer[0] = ((byte) value);
166: buffer[1] = ((byte) (value >> 8));
167: buffer[2] = ((byte) (value >> 16));
168: buffer[3] = ((byte) (value >> 24));
169: }
170: else
171: {
172: buffer[0] = ((byte) (value >> 24));
173: buffer[1] = ((byte) (value >> 16));
174: buffer[2] = ((byte) (value >> 8));
175: buffer[3] = ((byte) value);
176: }
177:
178: write(buffer, 0, 4);
179: }
180:
181: public void writeInts(int[] data, int offset, int len)
182: throws IOException
183: {
184: for(int i = 0; i < len; ++len)
185: writeInt(data[offset + i]);
186: }
187:
188: public void writeLong(long value)
189: throws IOException
190: {
191: if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
192: {
193: buffer[0] = ((byte) value);
194: buffer[1] = ((byte) (value >> 8));
195: buffer[2] = ((byte) (value >> 16));
196: buffer[3] = ((byte) (value >> 24));
197: buffer[4] = ((byte) (value >> 32));
198: buffer[5] = ((byte) (value >> 40));
199: buffer[6] = ((byte) (value >> 48));
200: buffer[7] = ((byte) (value >> 56));
201: }
202: else
203: {
204: buffer[0] = ((byte) (value >> 56));
205: buffer[1] = ((byte) (value >> 48));
206: buffer[2] = ((byte) (value >> 40));
207: buffer[3] = ((byte) (value >> 32));
208: buffer[4] = ((byte) (value >> 24));
209: buffer[5] = ((byte) (value >> 16));
210: buffer[6] = ((byte) (value >> 8));
211: buffer[7] = ((byte) value);
212: }
213:
214: write(buffer, 0, 8);
215: }
216:
217: public void writeLongs(long[] data, int offset, int len)
218: throws IOException
219: {
220: for(int i = 0; i < len; ++len)
221: writeLong(data[offset + i]);
222: }
223:
224: public void writeShort(int value)
225: throws IOException
226: {
227: if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
228: {
229: buffer[0] = ((byte) value);
230: buffer[1] = ((byte) (value >> 8));
231: }
232: else
233: {
234: buffer[0] = ((byte) (value >> 8));
235: buffer[1] = ((byte) value);
236: }
237:
238: write(buffer, 0, 2);
239: }
240:
241: public void writeShorts(short[] data, int offset, int len)
242: throws IOException
243: {
244: for(int i = 0; i < len; ++len)
245: writeShort(data[offset + i]);
246: }
247:
248: public void writeUTF(String value)
249: throws IOException
250: {
251:
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:
285:
286:
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);
295: }
296: }