CorbaOutput.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* CorbaOutput.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 org.omg.CORBA_2_3.portable.OutputStream;
  33. import java.io.IOException;
  34. import java.io.ObjectOutput;
  35. import java.io.ObjectOutputStream;
  36. import java.io.Serializable;
  37. /**
  38. * A class to substitute as an ObjectOutputStream for objects using writeObject
  39. * method.
  40. *
  41. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
  42. */
  43. public class CorbaOutput
  44. extends ObjectOutputStream
  45. implements ObjectOutput
  46. {
  47. /**
  48. * A CORBA stream where the output is forwarded.
  49. */
  50. final OutputStream stream;
  51. /**
  52. * The utility class to write the object fields in default way.
  53. */
  54. final RmiUtilities util;
  55. /**
  56. * The object currently being written.
  57. */
  58. Object current;
  59. /**
  60. * Create an instance, delegating calls to the given CORBA stream.
  61. */
  62. public CorbaOutput(OutputStream an_output, Object firstObject,
  63. RmiUtilities an_util)
  64. throws Exception
  65. {
  66. stream = an_output;
  67. current = firstObject;
  68. util = an_util;
  69. }
  70. /**
  71. * No action.
  72. */
  73. public void close()
  74. throws IOException
  75. {
  76. }
  77. /** @inheritDoc */
  78. public void flush()
  79. throws IOException
  80. {
  81. stream.flush();
  82. }
  83. /** @inheritDoc */
  84. public void write(byte[] buf, int off, int len)
  85. throws IOException
  86. {
  87. stream.write(buf, off, len);
  88. }
  89. /** @inheritDoc */
  90. public void write(byte[] buf)
  91. throws IOException
  92. {
  93. stream.write(buf);
  94. }
  95. /** @inheritDoc */
  96. public void write(int val)
  97. throws IOException
  98. {
  99. stream.write(val);
  100. }
  101. /** @inheritDoc */
  102. public void writeBoolean(boolean val)
  103. throws IOException
  104. {
  105. stream.write_boolean(val);
  106. }
  107. /** @inheritDoc */
  108. public void writeByte(int val)
  109. throws IOException
  110. {
  111. stream.write(val);
  112. }
  113. /** @inheritDoc */
  114. public void writeBytes(String str)
  115. throws IOException
  116. {
  117. stream.write_string(str);
  118. }
  119. /** @inheritDoc */
  120. public void writeChar(int val)
  121. throws IOException
  122. {
  123. stream.write_wchar((char) val);
  124. }
  125. /** @inheritDoc */
  126. public void writeChars(String str)
  127. throws IOException
  128. {
  129. stream.write_char_array(str.toCharArray(), 0, str.length());
  130. }
  131. /** @inheritDoc */
  132. public void writeDouble(double val)
  133. throws IOException
  134. {
  135. stream.write_double(val);
  136. }
  137. /** @inheritDoc */
  138. public void writeFloat(float val)
  139. throws IOException
  140. {
  141. stream.write_float(val);
  142. }
  143. /** @inheritDoc */
  144. public void writeInt(int val)
  145. throws IOException
  146. {
  147. stream.write_long(val);
  148. }
  149. /** @inheritDoc */
  150. public void writeLong(long val)
  151. throws IOException
  152. {
  153. stream.write_longlong(val);
  154. }
  155. /**
  156. * Objects are written as abstract interfaces.
  157. */
  158. protected void writeObjectOverride(Object obj)
  159. throws IOException
  160. {
  161. current = obj;
  162. stream.write_abstract_interface(obj);
  163. }
  164. /** @inheritDoc */
  165. public void writeShort(int val)
  166. throws IOException
  167. {
  168. stream.write_short((short) val);
  169. }
  170. /**
  171. * Such strings are written as wide strings, not as UTF.
  172. */
  173. public void writeUTF(String str)
  174. throws IOException
  175. {
  176. stream.write_wstring(str);
  177. }
  178. /**
  179. * @inheritDoc
  180. */
  181. public void defaultWriteObject()
  182. throws IOException
  183. {
  184. util.writeFields(stream, (Serializable) current);
  185. }
  186. }