Source for gnu.javax.rmi.CORBA.CorbaInput

   1: /* CorbaInput.java --
   2:    Copyright (C) 2005 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 gnu.javax.rmi.CORBA;
  40: 
  41: import gnu.CORBA.CDR.gnuRuntime;
  42: 
  43: import org.omg.CORBA_2_3.portable.InputStream;
  44: 
  45: import java.io.DataInputStream;
  46: import java.io.IOException;
  47: import java.io.ObjectInput;
  48: import java.io.ObjectInputStream;
  49: import java.io.Serializable;
  50: 
  51: /**
  52:  * Converts calls on java ObjectOutputStream to calls on CORBA OutputStream. A
  53:  * class to substitute for objects using readObject method.
  54:  *
  55:  * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  56:  */
  57: public class CorbaInput
  58:   extends ObjectInputStream
  59:   implements ObjectInput
  60: {
  61: 
  62:   /**
  63:    * The underlying CORBA stream from where the actual input is taken.
  64:    */
  65:   public InputStream stream;
  66: 
  67:   /**
  68:    * The utility class to write the object fields in default way.
  69:    */
  70:   final RmiUtilities util;
  71: 
  72:   /**
  73:    * The object currently being read.
  74:    */
  75:   Object current;
  76: 
  77:   /**
  78:    * The offset of the object currently being read.
  79:    */
  80:   int offset;
  81: 
  82:   /**
  83:    * The repository id of the object currently being read.
  84:    */
  85:   String rid;
  86: 
  87:   /**
  88:    * The runtime, related to the object currently being read.
  89:    */
  90:   gnuRuntime runtime;
  91: 
  92:   /**
  93:    * Create an instance, delegating calls to the given CORBA stream.
  94:    */
  95:   public CorbaInput(InputStream an_input, Object firstObject,
  96:                           RmiUtilities an_util, int an_offset, String a_rid,
  97:                           gnuRuntime a_runtime)
  98:     throws Exception
  99:   {
 100:     stream = an_input;
 101:     current = firstObject;
 102:     util = an_util;
 103: 
 104:     offset = an_offset;
 105:     rid = a_rid;
 106:     runtime = a_runtime;
 107:   }
 108: 
 109:   /** @inheritDoc */
 110:   public int available()
 111:     throws IOException
 112:   {
 113:     return stream.available();
 114:   }
 115: 
 116:   /**
 117:    * No action.
 118:    */
 119:   public void close()
 120:     throws IOException
 121:   {
 122:   }
 123: 
 124:   /** @inheritDoc */
 125:   public void defaultReadObject()
 126:     throws IOException, ClassNotFoundException
 127:   {
 128:     util.readFields(offset, rid, (Serializable) current, stream, runtime);
 129:   }
 130: 
 131:   /** @inheritDoc */
 132:   public void mark(int readlimit)
 133:   {
 134:     stream.mark(readlimit);
 135:   }
 136: 
 137:   /** @inheritDoc */
 138:   public boolean markSupported()
 139:   {
 140:     return stream.markSupported();
 141:   }
 142: 
 143:   /** @inheritDoc */
 144:   public int read()
 145:     throws IOException
 146:   {
 147:     return stream.read();
 148:   }
 149: 
 150:   /** @inheritDoc */
 151:   public int read(byte[] buf, int off, int len)
 152:     throws IOException
 153:   {
 154:     return stream.read(buf, off, len);
 155:   }
 156: 
 157:   /** @inheritDoc */
 158:   public int read(byte[] b)
 159:     throws IOException
 160:   {
 161:     return stream.read(b);
 162:   }
 163: 
 164:   /** @inheritDoc */
 165:   public boolean readBoolean()
 166:     throws IOException
 167:   {
 168:     return stream.read_boolean();
 169:   }
 170: 
 171:   /** @inheritDoc */
 172:   public byte readByte()
 173:     throws IOException
 174:   {
 175:     return (byte) stream.read();
 176:   }
 177: 
 178:   /** @inheritDoc */
 179:   public char readChar()
 180:     throws IOException
 181:   {
 182:     return stream.read_char();
 183:   }
 184: 
 185:   /** @inheritDoc */
 186:   public double readDouble()
 187:     throws IOException
 188:   {
 189:     return stream.read_double();
 190:   }
 191: 
 192:   /** @inheritDoc */
 193:   public float readFloat()
 194:     throws IOException
 195:   {
 196:     return stream.read_float();
 197:   }
 198: 
 199:   /** @inheritDoc */
 200:   public void readFully(byte[] buf, int off, int len)
 201:     throws IOException
 202:   {
 203:     // This class only reads from the buffered streams.
 204:     stream.read(buf, off, len);
 205:   }
 206: 
 207:   /** @inheritDoc */
 208:   public void readFully(byte[] buf)
 209:     throws IOException
 210:   {
 211:     // This class only reads from the buffered streams.
 212:     stream.read(buf);
 213:   }
 214: 
 215:   /** @inheritDoc */
 216:   public int readInt()
 217:     throws IOException
 218:   {
 219:     return stream.read_long();
 220:   }
 221: 
 222:   /** @inheritDoc */
 223:   public String readLine()
 224:     throws IOException
 225:   {
 226:     return new DataInputStream(this).readLine();
 227:   }
 228: 
 229:   /** @inheritDoc */
 230:   public long readLong()
 231:     throws IOException
 232:   {
 233:     return stream.read_longlong();
 234:   }
 235: 
 236:   /** @inheritDoc */
 237:   public short read_short()
 238:     throws IOException
 239:   {
 240:     return stream.read_short();
 241:   }
 242: 
 243:   /** @inheritDoc */
 244:   public int readUnsignedByte()
 245:     throws IOException
 246:   {
 247:     return (stream.read() & 0xFF);
 248:   }
 249: 
 250:   /** @inheritDoc */
 251:   public int readUnsignedShort()
 252:     throws IOException
 253:   {
 254:     return (stream.read_short() & 0xFFFF);
 255:   }
 256: 
 257:   /**
 258:    * Read as wide string (not as UTF).
 259:    */
 260:   public String readUTF()
 261:     throws IOException
 262:   {
 263:     return stream.read_wstring();
 264:   }
 265: 
 266:   /** @inheritDoc */
 267:   public void reset()
 268:     throws IOException
 269:   {
 270:     stream.reset();
 271:   }
 272: 
 273:   /** @inheritDoc */
 274:   public long skip(long n)
 275:     throws IOException
 276:   {
 277:     return stream.skip(n);
 278:   }
 279: 
 280:   /** @inheritDoc */
 281:   public int skipBytes(int len)
 282:     throws IOException
 283:   {
 284:     return (int) stream.skip(len);
 285:   }
 286: 
 287:   /**
 288:    * Objects are read as abstract interfaces.
 289:    */
 290:   protected Object readObjectOverride()
 291:     throws IOException, ClassNotFoundException
 292:   {
 293:     current = stream.read_abstract_interface();
 294:     return current;
 295:   }
 296: 
 297: }