00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sun.corba.se.impl.encoding;
00011
00012 import java.nio.ByteBuffer;
00013 import org.omg.CORBA.CompletionStatus;
00014 import com.sun.org.omg.SendingContext.CodeBase;
00015 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
00016 import com.sun.corba.se.impl.encoding.CDRInputStream;
00017 import com.sun.corba.se.impl.encoding.BufferManagerFactory;
00018 import com.sun.corba.se.impl.encoding.CodeSetConversion;
00019 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
00020 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
00021
00022 import com.sun.corba.se.spi.orb.ORB;
00023
00024 import com.sun.corba.se.spi.logging.CORBALogDomains;
00025
00026 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
00027
00028 import java.io.*;
00029 import sun.misc.HexDumpEncoder;
00043 public class EncapsInputStream extends CDRInputStream
00044 {
00045 private ORBUtilSystemException wrapper ;
00046
00047 public static final boolean MESSAGE_DUMP = false;
00048 public static final boolean DUMP_TO_FILE = false;
00049
00050
00051 private static ByteBuffer wrap(byte[] buf, org.omg.CORBA.ORB orb) {
00052 if (DUMP_TO_FILE) {
00053 String id = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
00054 try {
00055 FileWriter os = new FileWriter("jcorba." + id + ".msgct", true);
00056 os.write(buf.length + " bytes\n");
00057 os.close();
00058 } catch (IOException e) {}
00059 if (MESSAGE_DUMP) {
00060 try {
00061 FileWriter os = new FileWriter("jcorba." + id + ".msgs", true);
00062 os.write(new sun.misc.HexDumpEncoder().encode(buf));
00063 os.write("\n");
00064 os.close();
00065 } catch (java.io.IOException e) {}
00066 }
00067 } else {
00068 System.out.println(buf.length + " bytes");
00069 if (MESSAGE_DUMP)
00070 System.out.println(new sun.misc.HexDumpEncoder().encode(buf));
00071 }
00072 return ByteBuffer.wrap(buf);
00073 }
00074
00075
00076
00077
00078
00079 public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] buf,
00080 int size, boolean littleEndian,
00081 GIOPVersion version) {
00082 super(orb, wrap(buf, orb), size, littleEndian,
00083 version, Message.CDR_ENC_VERSION,
00084 BufferManagerFactory.newBufferManagerRead(BufferManagerFactory.GROW,
00085 Message.CDR_ENC_VERSION,
00086 (ORB)orb));
00087
00088 wrapper = ORBUtilSystemException.get((ORB)orb,
00089 CORBALogDomains.RPC_ENCODING ) ;
00090
00091 performORBVersionSpecificInit();
00092 }
00093
00094 public EncapsInputStream(org.omg.CORBA.ORB orb, ByteBuffer byteBuffer,
00095 int size, boolean littleEndian,
00096 GIOPVersion version) {
00097 super(orb, byteBuffer, size, littleEndian,
00098 version, Message.CDR_ENC_VERSION,
00099 BufferManagerFactory.newBufferManagerRead(
00100 BufferManagerFactory.GROW,
00101 Message.CDR_ENC_VERSION,
00102 (com.sun.corba.se.spi.orb.ORB)orb));
00103
00104 performORBVersionSpecificInit();
00105 }
00106
00107
00108
00109
00110
00111 public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data, int size)
00112 {
00113 this(orb, data, size, GIOPVersion.V1_2);
00114 }
00115
00116
00117 public EncapsInputStream(EncapsInputStream eis)
00118 {
00119 super(eis);
00120
00121 wrapper = ORBUtilSystemException.get( (ORB)(eis.orb()),
00122 CORBALogDomains.RPC_ENCODING ) ;
00123
00124 performORBVersionSpecificInit();
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] data, int size, GIOPVersion version)
00134 {
00135 this(orb, data, size, false, version);
00136 }
00137
00144 public EncapsInputStream(org.omg.CORBA.ORB orb,
00145 byte[] data,
00146 int size,
00147 GIOPVersion version,
00148 CodeBase codeBase) {
00149 super(orb,
00150 ByteBuffer.wrap(data),
00151 size,
00152 false,
00153 version, Message.CDR_ENC_VERSION,
00154 BufferManagerFactory.newBufferManagerRead(
00155 BufferManagerFactory.GROW,
00156 Message.CDR_ENC_VERSION,
00157 (ORB)orb));
00158
00159 this.codeBase = codeBase;
00160
00161 performORBVersionSpecificInit();
00162 }
00163
00164 public CDRInputStream dup() {
00165 return new EncapsInputStream(this);
00166 }
00167
00168 protected CodeSetConversion.BTCConverter createCharBTCConverter() {
00169 return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.ISO_8859_1);
00170 }
00171
00172 protected CodeSetConversion.BTCConverter createWCharBTCConverter() {
00173
00174 if (getGIOPVersion().equals(GIOPVersion.V1_0))
00175 throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
00176
00177
00178
00179 if (getGIOPVersion().equals(GIOPVersion.V1_1))
00180 return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
00181 isLittleEndian());
00182
00183
00184
00185
00186
00187
00188
00189
00190 return CodeSetConversion.impl().getBTCConverter(OSFCodeSetRegistry.UTF_16,
00191 false);
00192 }
00193
00194 public CodeBase getCodeBase() {
00195 return codeBase;
00196 }
00197
00198 private CodeBase codeBase;
00199 }