📄 vio.java
字号:
else if (input instanceof HeadlessInput) { // There is no need to instantiate one more HeadlessInput // as we can just reset. ((HeadlessInput) input).subsequentCalls = false; } else { BufferedCdrOutput bout = new BufferedCdrOutput(); int c; while ((c = input.read()) >= 0) bout.write((byte) c); input = new HeadlessInput( (BufferredCdrInput) bout.create_input_stream(), input); } } } catch (IOException ex) { MARSHAL m = new MARSHAL("Unable to read chunks"); m.minor = Minor.Value; m.initCause(ex); throw m; } return readValue(input, position, value, helper, id, ids, codebase); } /** * Create a buffer, inheriting critical settings from the passed input stream. */ private static BufferedCdrOutput createBuffer(InputStream input, int proposed_size) { BufferedCdrOutput bout; bout = new BufferedCdrOutput(2 * proposed_size + 256); if (input instanceof BufferredCdrInput) { BufferredCdrInput in = (BufferredCdrInput) input; bout.setBigEndian(in.isBigEndian()); } if (input instanceof gnuValueStream) bout.setRunTime(((gnuValueStream) input).getRunTime()); else bout.setRunTime(new gnuRuntime(null, null)); return bout; } /** * Read the chunked nested value from the given input stream, transferring the * contents to the given output stream. * * @param value_tag the value tag of the value being read. * @param input the input stream from where the remainder of the nested value * must be read. * @param output the output stream where the unchunked nested value must be * copied. * * @return the tag that ended the nested value. */ public static int readNestedValue(int value_tag, InputStream input, BufferedCdrOutput output, int level) throws IOException { String id = null; if (level < -1) { // For the first level, this information is already behind. output.write_long(value_tag - vf_CHUNKING); // The nested value should be aways chunked. if ((value_tag & vf_CHUNKING) == 0) { MARSHAL m = new MARSHAL("readNestedValue: must be chunked"); m.minor = Minor.Chunks; throw m; } else if (value_tag == vt_NULL) { MARSHAL m = new MARSHAL("readNestedValue: nul"); m.minor = Minor.Chunks; throw m; } else if (value_tag == vt_INDIRECTION) { MARSHAL m = new MARSHAL("readNestedValue: indirection"); m.minor = Minor.Chunks; throw m; } else { // Read the value. if ((value_tag & vf_CODEBASE) != 0) { String codebase = read_string(input); write_string(output, codebase); } if ((value_tag & vf_MULTIPLE_IDS) != 0) { // Multiple supported repository ids are present. String[] ids = read_string_array(input); id = ids[0]; write_string_array(output, ids); } else if ((value_tag & vf_ID) != 0) { id = read_string(input); write_string(output, id); } } } int n = -1; // Read all chunks. int chunk_size; byte[] r = null; while (true) { // Read the size of the next chunk or it may also be the // header of the nested value. chunk_size = input.read_long(); // End of chunk terminator. if (chunk_size < 0 && chunk_size >= level) return chunk_size; else if (chunk_size >= 0x7FFFFF00) { int onInput = getCurrentPosition(input) - 4; int onOutput = output.getPosition(); output.getRunTime().redirect(onInput, onOutput); // Value over 0x7FFFFF00 indicates that the nested value // starts here. Read the nested value, storing it into the output. // First parameter is actually the value tag. chunk_size = readNestedValue(chunk_size, input, output, level - 1); if (chunk_size < 0 && chunk_size >= level) return chunk_size; } else { // The chunk follows. if (r == null || r.length < chunk_size) r = new byte[chunk_size + 256]; n = 0; reading: while (n < chunk_size) n += input.read(r, n, chunk_size - n); output.write(r, 0, n); } } } /** * Read the value (the header must be behind). */ public static Serializable readValue(InputStream input, final int position, Object value, BoxedValueHelper helper, String id, String[] ids, String codebase) { gnuRuntime g; gnuValueStream c = ((gnuValueStream) input); if (c.getRunTime() == null) { g = new gnuRuntime(codebase, value); c.setRunTime(g); } else { g = c.getRunTime(); g.addCodeBase(codebase); g.target = (Serializable) value; } if (value != null) g.objectWritten(value, position); if (input instanceof HeadlessInput) ((HeadlessInput) input).subsequentCalls = false; boolean ok = true; // The user-defined io operations are implemented. if (value instanceof CustomMarshal) { CustomMarshal marsh = (CustomMarshal) value; marsh.unmarshal((DataInputStream) input); } else // The IDL-generated io operations are implemented. if (value instanceof Streamable) { ((Streamable) value)._read(input); } else if (helper != null) { // If helper is non-null the value should normally be null. value = helper.read_value(input); g.objectWritten(value, position); } else { ok = false; ValueFactory factory = null; org.omg.CORBA_2_3.ORB orb = (org.omg.CORBA_2_3.ORB) input.orb(); if (id != null) factory = orb.lookup_value_factory(id); if (factory == null && ids != null) { for (int i = 0; i < ids.length && factory == null; i++) { factory = orb.lookup_value_factory(ids[i]); } } if (factory != null) { value = factory.read_value((org.omg.CORBA_2_3.portable.InputStream) input); ok = true; } } if (!ok && value instanceof Serializable) // Delegate to ValueHandler { if (ids != null && ids.length > 0) id = ids[0]; value = handler.readValue(input, position, value.getClass(), id, g); ok = true; } if (!ok) { if (value != null) { MARSHAL m = new MARSHAL(value.getClass().getName() + " must be Streamable, CustomMarshal or Serializable"); m.minor = Minor.UnsupportedValue; throw m; } else { MARSHAL m = new MARSHAL("Unable to instantiate " + id + ":" + list(ids) + " helper " + helper); m.minor = Minor.UnsupportedValue; throw m; } } else return (Serializable) value; } /** * Conveniency method to list ids in exception reports. */ static String list(String[] s) { if (s == null) return "null"; else { StringBuffer b = new StringBuffer("{"); for (int i = 0; i < s.length; i++) { b.append(s[i]); b.append(" "); } b.append("}"); return b.toString(); } } /** * Write the value base into the given stream. * * @param output a stream to write to. * * @param value a value type object, must be either Streamable or * CustomMarshal. * * @throws MARSHAL if the writing failed due any reason. */ public static void write(OutputStream output, Serializable value) { // Write null if this is a null value. if (value == null) output.write_long(vt_NULL); else if (value instanceof String) write(output, value, m_StringValueHelper); else write(output, value, value.getClass()); } /** * Write the value base into the given stream, stating that it is an instance * of the given class. * * @param output a stream to write to. * * @param value a value to write. * * @throws MARSHAL if the writing failed due any reason. */ public static void write(OutputStream output, Serializable value, Class substitute) { // Write null if this is a null value. if (value == null) output.write_long(vt_NULL); else if (value instanceof String || substitute == String.class) writeString(output, value); else { String vId = ObjectCreator.getRepositoryId(value.getClass()); if (substitute == null || value.getClass().equals(substitute)) write_instance(output, value, vId, getHelper(value.getClass(), vId)); else { String vC = ObjectCreator.getRepositoryId(substitute); String[] ids = new String[] { vId, vC }; BoxedValueHelper h = getHelper(substitute.getClass(), ids); // If the helper is available, it is also responsible for // providing the repository Id. Otherwise, write both // ids. if (h == null) write_instance(output, value, ids, null); else write_instance(output, value, h.get_id(), null); } } } /** * Write the value base into the given stream, supplementing it with an array * of the provided repository ids plus the repository id, derived from the * passed value. * * @param output a stream to write to. * * @param value a value to write. * * @throws MARSHAL if the writing failed due any reason. */ public static void write(OutputStream output, Serializable value, String[] multiple_ids) { // Write null if this is a null value. if (value == null) output.write_long(vt_NULL); else { String[] ids = new String[multiple_ids.length + 1]; ids[0] = ObjectCreator.getRepositoryId(value.getClass()); System.arraycopy(multiple_ids, 0, ids, 1, multiple_ids.length); BoxedValueHelper h = getHelper(value.getClass(), ids); write_instance(output, value, ids, h); } } /** * Write value when its repository Id is explicitly given. Only this Id is * written, the type of value is not taken into consideration. * * @param output an output stream to write into. * @param value a value to write. * @param id a value repository id. */ public static void write(OutputStream output, Serializable value, String id) { if (value == null) output.write_long(vt_NULL); else write_instance(output, value, id, getHelper(value.getClass(), id)); } /** * Write standard value type header, followed by contents, produced by the * boxed value helper. * * @param output the stream to write to. * @param value the value to write, can be null. * @param helper the helper that writes the value content if it is not null * (must be provided for this method). */ public static void write(OutputStream output, Serializable value, BoxedValueHelper helper) { if (helper == null) throw new AssertionError("Helper must be provided"); if (value == null) output.write_long(vt_NULL); else write_instance(output, value, helper.get_id(), helper); } /** * Write the parameter that is surely a string and not null. */ private static void writeString(OutputStream output, Serializable string) { write_instance(output, string, m_StringValueHelper.get_id(), m_StringValueHelper); } /** * Write value when its repository Id is explicitly given. Does not handle * null. * * @param output an output stream to write into. * @param value a value to write. * @param id a value repository id (can be either single string or string * array). * @param helper a helper, writing object - specifical part. Can be null if * the value should be written using other methods. */ static void write_instance(OutputStream output, Serializable value, Object ids, BoxedValueHelper helper) { gnuValueStream rout = null; gnuRuntime runtime = null; try { if (output instanceof gnuValueStream) { int position; rout = (gnuValueStream) output; runtime = rout.getRunTime(); if (runtime == null) { runtime = new gnuRuntime(null, value); rout.setRunTime(runtime); rout.getRunTime().objectWritten(value, position = rout.getPosition()); } else if (runtime.target == value) { if (!writeSelf(output, value)) throw new InternalError("Recursive helper call for " + value.getClass().getName()); return; } else { position = runtime.isWrittenAt(value); if (position >= 0) { // The object was already written. output.write_long(vt_INDIRECTION); output.write_long(position - rout.getPosition()); // Replacing object write data by indirection reference. return; } else { runtime.objectWritten(value, position = rout.getPosition()); } } } int value_tag = vt_VALUE_TAG; if (ids instanceof String) value_tag |= vf_ID; else if (ids instanceof String[]) // OMG standard requires to set both flags. value_tag |= vf_MULTIPLE_IDS | vf_ID; int chunkSizeLocation; OutputStream outObj; if (USE_CHUNKING) { // Wrap the value being written into one chunk (makes sense only for // compatibility reasons). outObj = output; value_tag |= vf_CHUNKING; } else outObj = output; output.write_long(value_tag); if ((value_tag & vf_MULTIPLE_IDS) != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -