CorbaInput.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /* CorbaInput.java --
  2. Copyright (C) 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package gnu.javax.rmi.CORBA;
  32. import gnu.CORBA.CDR.gnuRuntime;
  33. import org.omg.CORBA_2_3.portable.InputStream;
  34. import java.io.DataInputStream;
  35. import java.io.IOException;
  36. import java.io.ObjectInput;
  37. import java.io.ObjectInputStream;
  38. import java.io.Serializable;
  39. /**
  40. * Converts calls on java ObjectOutputStream to calls on CORBA OutputStream. A
  41. * class to substitute for objects using readObject method.
  42. *
  43. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  44. */
  45. public class CorbaInput
  46. extends ObjectInputStream
  47. implements ObjectInput
  48. {
  49. /**
  50. * The underlying CORBA stream from where the actual input is taken.
  51. */
  52. public InputStream stream;
  53. /**
  54. * The utility class to write the object fields in default way.
  55. */
  56. final RmiUtilities util;
  57. /**
  58. * The object currently being read.
  59. */
  60. Object current;
  61. /**
  62. * The offset of the object currently being read.
  63. */
  64. int offset;
  65. /**
  66. * The repository id of the object currently being read.
  67. */
  68. String rid;
  69. /**
  70. * The runtime, related to the object currently being read.
  71. */
  72. gnuRuntime runtime;
  73. /**
  74. * Create an instance, delegating calls to the given CORBA stream.
  75. */
  76. public CorbaInput(InputStream an_input, Object firstObject,
  77. RmiUtilities an_util, int an_offset, String a_rid,
  78. gnuRuntime a_runtime)
  79. throws Exception
  80. {
  81. stream = an_input;
  82. current = firstObject;
  83. util = an_util;
  84. offset = an_offset;
  85. rid = a_rid;
  86. runtime = a_runtime;
  87. }
  88. /** @inheritDoc */
  89. public int available()
  90. throws IOException
  91. {
  92. return stream.available();
  93. }
  94. /**
  95. * No action.
  96. */
  97. public void close()
  98. throws IOException
  99. {
  100. }
  101. /** @inheritDoc */
  102. public void defaultReadObject()
  103. throws IOException, ClassNotFoundException
  104. {
  105. util.readFields(offset, rid, (Serializable) current, stream, runtime);
  106. }
  107. /** @inheritDoc */
  108. public void mark(int readlimit)
  109. {
  110. stream.mark(readlimit);
  111. }
  112. /** @inheritDoc */
  113. public boolean markSupported()
  114. {
  115. return stream.markSupported();
  116. }
  117. /** @inheritDoc */
  118. public int read()
  119. throws IOException
  120. {
  121. return stream.read();
  122. }
  123. /** @inheritDoc */
  124. public int read(byte[] buf, int off, int len)
  125. throws IOException
  126. {
  127. return stream.read(buf, off, len);
  128. }
  129. /** @inheritDoc */
  130. public int read(byte[] b)
  131. throws IOException
  132. {
  133. return stream.read(b);
  134. }
  135. /** @inheritDoc */
  136. public boolean readBoolean()
  137. throws IOException
  138. {
  139. return stream.read_boolean();
  140. }
  141. /** @inheritDoc */
  142. public byte readByte()
  143. throws IOException
  144. {
  145. return (byte) stream.read();
  146. }
  147. /** @inheritDoc */
  148. public char readChar()
  149. throws IOException
  150. {
  151. return stream.read_char();
  152. }
  153. /** @inheritDoc */
  154. public double readDouble()
  155. throws IOException
  156. {
  157. return stream.read_double();
  158. }
  159. /** @inheritDoc */
  160. public float readFloat()
  161. throws IOException
  162. {
  163. return stream.read_float();
  164. }
  165. /** @inheritDoc */
  166. public void readFully(byte[] buf, int off, int len)
  167. throws IOException
  168. {
  169. // This class only reads from the buffered streams.
  170. stream.read(buf, off, len);
  171. }
  172. /** @inheritDoc */
  173. public void readFully(byte[] buf)
  174. throws IOException
  175. {
  176. // This class only reads from the buffered streams.
  177. stream.read(buf);
  178. }
  179. /** @inheritDoc */
  180. public int readInt()
  181. throws IOException
  182. {
  183. return stream.read_long();
  184. }
  185. /** @inheritDoc */
  186. public String readLine()
  187. throws IOException
  188. {
  189. return new DataInputStream(this).readLine();
  190. }
  191. /** @inheritDoc */
  192. public long readLong()
  193. throws IOException
  194. {
  195. return stream.read_longlong();
  196. }
  197. /** @inheritDoc */
  198. public short read_short()
  199. throws IOException
  200. {
  201. return stream.read_short();
  202. }
  203. /** @inheritDoc */
  204. public int readUnsignedByte()
  205. throws IOException
  206. {
  207. return (stream.read() & 0xFF);
  208. }
  209. /** @inheritDoc */
  210. public int readUnsignedShort()
  211. throws IOException
  212. {
  213. return (stream.read_short() & 0xFFFF);
  214. }
  215. /**
  216. * Read as wide string (not as UTF).
  217. */
  218. public String readUTF()
  219. throws IOException
  220. {
  221. return stream.read_wstring();
  222. }
  223. /** @inheritDoc */
  224. public void reset()
  225. throws IOException
  226. {
  227. stream.reset();
  228. }
  229. /** @inheritDoc */
  230. public long skip(long n)
  231. throws IOException
  232. {
  233. return stream.skip(n);
  234. }
  235. /** @inheritDoc */
  236. public int skipBytes(int len)
  237. throws IOException
  238. {
  239. return (int) stream.skip(len);
  240. }
  241. /**
  242. * Objects are read as abstract interfaces.
  243. */
  244. protected Object readObjectOverride()
  245. throws IOException, ClassNotFoundException
  246. {
  247. current = stream.read_abstract_interface();
  248. return current;
  249. }
  250. }