Source for javax.imageio.stream.ImageOutputStreamImpl

   1: /* ImageOutputStream.java --
   2:    Copyright (C) 2004  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.imageio.stream;
  40: 
  41: import java.io.IOException;
  42: import java.nio.ByteOrder;
  43: 
  44: /**
  45:  * @author Michael Koch (konqueror@gmx.de)
  46:  */
  47: public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl
  48:   implements ImageOutputStream
  49: {
  50:   public ImageOutputStreamImpl()
  51:   {
  52:     // Do nothing here.
  53:   }
  54: 
  55:   protected void flushBits()
  56:     throws IOException
  57:   {
  58:     // FIXME: Implement me.
  59:     throw new Error("not implemented");
  60:   }
  61: 
  62:   public void write(byte[] data)
  63:     throws IOException
  64:   {
  65:     write(data, 0, data.length);
  66:   }
  67: 
  68:   public abstract void write(byte[] data, int offset, int len)
  69:     throws IOException;
  70: 
  71:   public abstract void write(int value)
  72:     throws IOException;
  73: 
  74:   public void writeBit(int bit)
  75:     throws IOException
  76:   {
  77:     // FIXME: Implement me.
  78:     throw new Error("not implemented");
  79:   }
  80: 
  81:   public void writeBits(long bits, int numBits)
  82:     throws IOException
  83:   {
  84:     // FIXME: Implement me.
  85:     throw new Error("not implemented");
  86:   }
  87: 
  88:   public void writeBoolean(boolean value)
  89:     throws IOException
  90:   {
  91:     writeByte(value ? 1 : 0);
  92:   }
  93: 
  94:   public void writeByte(int value)
  95:     throws IOException
  96:   {
  97:     write(value & 0xff);
  98:   }
  99: 
 100:   public void writeBytes(String data)
 101:     throws IOException
 102:   {
 103:     write(data.getBytes());
 104:   }
 105: 
 106:   public void writeChar(int value)
 107:     throws IOException
 108:   {
 109:     writeShort((short) value);
 110:   }
 111: 
 112:   public void writeChars(char[] data, int offset, int len)
 113:     throws IOException
 114:   {
 115:     for(int i = 0; i < len; ++len)
 116:       writeChar(data[offset + i]);
 117:   }
 118: 
 119:   public void writeChars(String data)
 120:     throws IOException
 121:   {
 122:     // FIXME: Implement me.
 123:     throw new Error("not implemented");
 124:   }
 125: 
 126:   public void writeDouble(double value)
 127:     throws IOException
 128:   {
 129:     writeLong((long) value);
 130:   }
 131: 
 132:   public void writeDoubles(double[] data, int offset, int len)
 133:     throws IOException
 134:   {
 135:     for(int i = 0; i < len; ++len)
 136:       writeDouble(data[offset + i]);
 137:   }
 138:   
 139:   public void writeFloat(float value)
 140:     throws IOException
 141:   {
 142:     writeInt((int) value);
 143:   }
 144:   
 145:   public void writeFloats(float[] data, int offset, int len)
 146:     throws IOException
 147:   {
 148:     for(int i = 0; i < len; ++len)
 149:       writeFloat(data[offset + i]);
 150:   }
 151:   
 152:   public void writeInt(int value)
 153:     throws IOException
 154:   {
 155:     if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
 156:       {
 157:         buffer[0] = ((byte) value);
 158:         buffer[1] = ((byte) (value >> 8));
 159:         buffer[2] = ((byte) (value >> 16));
 160:         buffer[3] = ((byte) (value >> 24));
 161:       }
 162:     else
 163:       {
 164:         buffer[0] = ((byte) (value >> 24));
 165:         buffer[1] = ((byte) (value >> 16));
 166:         buffer[2] = ((byte) (value >> 8));
 167:         buffer[3] = ((byte) value);
 168:       }
 169:     
 170:     write(buffer, 0, 4);
 171:   }
 172:   
 173:   public void writeInts(int[] data, int offset, int len)
 174:     throws IOException
 175:   {
 176:     for(int i = 0; i < len; ++len)
 177:       writeInt(data[offset + i]);
 178:   }
 179:   
 180:   public void writeLong(long value)
 181:     throws IOException
 182:   {
 183:     if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
 184:       {
 185:         buffer[0] = ((byte) value);
 186:         buffer[1] = ((byte) (value >> 8));
 187:         buffer[2] = ((byte) (value >> 16));
 188:         buffer[3] = ((byte) (value >> 24));
 189:         buffer[4] = ((byte) (value >> 32));
 190:         buffer[5] = ((byte) (value >> 40));
 191:         buffer[6] = ((byte) (value >> 48));
 192:         buffer[7] = ((byte) (value >> 56));
 193:       }
 194:     else
 195:       {
 196:         buffer[0] = ((byte) (value >> 56));
 197:         buffer[1] = ((byte) (value >> 48));
 198:         buffer[2] = ((byte) (value >> 40));
 199:         buffer[3] = ((byte) (value >> 32));
 200:         buffer[4] = ((byte) (value >> 24));
 201:         buffer[5] = ((byte) (value >> 16));
 202:         buffer[6] = ((byte) (value >> 8));
 203:         buffer[7] = ((byte) value);
 204:       }
 205:     
 206:     write(buffer, 0, 8);
 207:   }
 208:   
 209:   public void writeLongs(long[] data, int offset, int len)
 210:     throws IOException
 211:   {
 212:     for(int i = 0; i < len; ++len)
 213:       writeLong(data[offset + i]);
 214:   }
 215:   
 216:   public void writeShort(int value)
 217:     throws IOException
 218:   {
 219:     if (getByteOrder() == ByteOrder.LITTLE_ENDIAN)
 220:       {
 221:         buffer[0] = ((byte) value);
 222:         buffer[1] = ((byte) (value >> 8));
 223:       }
 224:     else
 225:       {
 226:         buffer[0] = ((byte) (value >> 8));
 227:         buffer[1] = ((byte) value);
 228:       }
 229:     
 230:     write(buffer, 0, 2);
 231:   }
 232:   
 233:   public void writeShorts(short[] data, int offset, int len)
 234:     throws IOException
 235:   {
 236:     for(int i = 0; i < len; ++len)
 237:       writeShort(data[offset + i]);
 238:   }
 239:   
 240:   public void writeUTF(String data)
 241:     throws IOException
 242:   {
 243:     throw new Error("not implemented");
 244:   }
 245: }