⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vio.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
          write_string_array(output, (String[]) ids);        else if ((value_tag & vf_ID) != 0)          write_string(output, (String) ids);        if (USE_CHUNKING)          {            // So far, write 0x55555555 instead of the chunk size (alignment may            // take place).            output.write_long(0x55555555);            // If the chunking is involved, the chunk size must be written here.            chunkSizeLocation = rout.getPosition() - INT_SIZE;          }        else          // Not in use for this case.          chunkSizeLocation = -1;        writeValue(outObj, value, helper);        if (USE_CHUNKING)          {            // Write the chunk size where the place for it was reserved.            int chunkSize = rout.getPosition() - chunkSizeLocation - INT_SIZE;            int current = rout.getPosition();            rout.seek(chunkSizeLocation);            output.write_long(chunkSize);            rout.seek(current);            // The end of record marker.            output.write_long(-1);          }      }    finally      {        if (runtime != null)          runtime.target = null;      }  }  /**   * Write value (after header).   */  static void writeValue(OutputStream output, Serializable value,    BoxedValueHelper helper)  {    ((gnuValueStream) output).getRunTime().target = value;    if (helper != null)      helper.write_value(output, value);    else if (!writeSelf(output, value))      {        // Try to find helper via class loader.        boolean ok = false;        if (!ok)          {            if (output instanceof BufferedCdrOutput)              {                BufferedCdrOutput b = (BufferedCdrOutput) output;                if (b.runtime == null)                  b.runtime = new gnuRuntime(null, value);              }            handler.writeValue(output, value);          }      }  }  /**   * Try to write value supposing that it implements self-streamable interfaces.   * Return false if it does not or true on success.   */  static boolean writeSelf(OutputStream output, Serializable value)  {    // User defined write method is present.    if (value instanceof CustomMarshal)      {        ((CustomMarshal) value).marshal((DataOutputStream) output);        return true;      }    else if (value instanceof Streamable)      {        ((Streamable) value)._write(output);        return true;      }    return false;  }  /**   * Read the indirection data and return the object that was already written to   * this stream.   *    * @param an_input the input stream, must be BufferredCdrInput.   */  static Serializable readIndirection(InputStream an_input)  {    if (!(an_input instanceof gnuValueStream))      throw new NO_IMPLEMENT(gnuValueStream.class.getName()        + " expected as parameter");    gnuValueStream in = (gnuValueStream) an_input;    int current_pos = in.getPosition();    int offset = an_input.read_long();    if (offset > -INT_SIZE)      {        MARSHAL m = new MARSHAL("Indirection tag refers to " + offset        + " (must be less than -" + INT_SIZE + ")");        m.minor = Minor.Offset;        throw m;      }    int stored_at = current_pos + offset;    if (in.getRunTime() == null)      {        MARSHAL m = new MARSHAL(stored_at + " offset " + offset + ": not written");        m.minor = Minor.Value;        throw m;      }    return (Serializable) in.getRunTime().isObjectWrittenAt(stored_at, offset);  }  /**   * Check the passed value tag for correctness.   *    * @param value_tag a tag to check, must be between 0x7fffff00 and 0x7fffffff   *    * @throws MARSHAL if the tag is outside this interval.   */  static void checkTag(int value_tag)  {    if ((value_tag < 0x7fffff00 || value_tag > 0x7fffffff)      && value_tag != vt_NULL && value_tag != vt_INDIRECTION)      {        MARSHAL m = new MARSHAL("Invalid value record, unsupported header tag: "        + value_tag + " (0x" + Integer.toHexString(value_tag) + ")");        m.minor = Minor.ValueHeaderTag;        throw m;      }    if ((value_tag & vf_MULTIPLE_IDS) != 0 && (value_tag & vf_ID) == 0)      {        MARSHAL m = new MARSHAL("Invalid value record header flag combination (0x"        + Integer.toHexString(value_tag) + ")");        m.minor = Minor.ValueHeaderFlags;        throw m;      }  }  /**   * Throw MARSHAL.   */  static void throwIt(String msg, String id1, String id2, Throwable e)    throws MARSHAL  {    MARSHAL m = new MARSHAL(msg + ":'" + id1 + "' versus '" + id2 + "'");    if (e != null)      m.initCause(e);    m.minor = Minor.Value;    throw m;  }  /**   * Load class by name and create the instance.   */  static Object createInstance(String id, String[] ids, String codebase)  {    Object o = null;    if (id != null)      o = _createInstance(id, codebase);    if (ids != null)      for (int i = 0; i < ids.length && o == null; i++)        o = _createInstance(ids[i], codebase);    return o;  }  static Object _createInstance(String id, String codebase)  {    if (id == null)      return null;    if (id.equals(StringValueHelper.id()))      return "";    StringTokenizer st = new StringTokenizer(id, ":");    String prefix = st.nextToken();    if (prefix.equalsIgnoreCase("IDL"))      return ObjectCreator.Idl2Object(id);    else if (prefix.equalsIgnoreCase("RMI"))      {        String className = st.nextToken();        String hashCode = st.nextToken();        String sid = null;        if (st.hasMoreElements())          sid = st.nextToken();        try          {            Class objectClass = Util.loadClass(className, codebase,              Vio.class.getClassLoader());            String rid = ObjectCreator.getRepositoryId(objectClass);            if (!rid.equals(id))              {                // If direct string comparison fails, compare by meaning.                StringTokenizer st2 = new StringTokenizer(rid, ":");                if (!st2.nextToken().equals("RMI"))                  throw new InternalError("RMI format expected: '" + rid + "'");                if (!st2.nextToken().equals(className))                  throwIt("Class name mismatch", id, rid, null);                try                  {                    long h1 = Long.parseLong(hashCode, 16);                    long h2 = Long.parseLong(st2.nextToken(), 16);                    if (h1 != h2)                      throwIt("Hashcode mismatch", id, rid, null);                    if (sid != null && st2.hasMoreTokens())                      {                        long s1 = Long.parseLong(hashCode, 16);                        long s2 = Long.parseLong(st2.nextToken(), 16);                        if (s1 != s2)                          throwIt("serialVersionUID mismatch", id, rid, null);                      }                  }                catch (NumberFormatException e)                  {                    throwIt("Invalid hashcode or svuid format: ", id, rid, e);                  }              }            // Low - level instantiation required here.            return instantiateAnyWay(objectClass);          }        catch (Exception ex)          {            MARSHAL m = new MARSHAL("Unable to instantiate " + id);            m.minor = Minor.Instantiation;            m.initCause(ex);            throw m;          }      }    else      throw new NO_IMPLEMENT("Unsupported prefix " + prefix + ":");  }  /**   * Read string, expecting the probable indirection.   */  static String read_string(InputStream input)  {    gnuValueStream g = (gnuValueStream) input;    int previous = g.getPosition();    int l = input.read_long();    if (l != vt_INDIRECTION)      {        g.seek(previous);        String s = input.read_string();        if (g.getRunTime() == null)          g.setRunTime(new gnuRuntime(null, null));        g.getRunTime().singleIdWritten(s, previous);        return s;      }    else      {        gnuRuntime r = g.getRunTime();        int base = g.getPosition();        int delta = input.read_long();        if (r == null)          {            previous = g.getPosition();            g.seek(base + delta);            String indir = input.read_string();            g.seek(previous);            return indir;          }        else          {            return (String) r.isObjectWrittenAt(base + delta, delta);          }      }  }  /**   * Read string array, expecting the probable indirection.   */  static String[] read_string_array(InputStream input)  {    gnuValueStream g = (gnuValueStream) input;    int previous = g.getPosition();    int l = input.read_long();    if (l != vt_INDIRECTION)      {        g.seek(previous);        String[] s = StringSeqHelper.read(input);        if (g.getRunTime() == null)          g.setRunTime(new gnuRuntime(null, null));        g.getRunTime().objectWritten(s, previous);        return s;      }    else      {        gnuRuntime r = g.getRunTime();        int base = g.getPosition();        int delta = input.read_long();        if (r == null)          {            previous = g.getPosition();            g.seek(base + delta);            String[] indir = StringSeqHelper.read(input);            g.seek(previous);            return indir;          }        else          {            return (String[]) r.isObjectWrittenAt(base + delta, delta);          }      }  }  /**   * Write repository Id, probably shared.   */  static void write_string(OutputStream output, String id)  {    if (output instanceof gnuValueStream)      {        gnuValueStream b = (gnuValueStream) output;        if (b != null)          {            int written = b.getRunTime().idWrittenAt(id);            if (written >= 0)              {                // Reuse existing id record.                output.write_long(vt_INDIRECTION);                int p = b.getPosition();                output.write_long(written - p);              }            else              {                b.getRunTime().singleIdWritten(id, b.getPosition());                output.write_string(id);              }          }      }    else      output.write_string(id);  }  /**   * Write repository Id, probably shared.   */  static void write_string_array(OutputStream output, String[] ids)  {    if (output instanceof gnuValueStream)      {        gnuValueStream b = (gnuValueStream) output;        if (b != null)          {            int written = b.getRunTime().idWrittenAt(ids);            if (written >= 0)              {                // Reuse existing id record.                output.write_long(vt_INDIRECTION);                int p = b.getPosition();                output.write_long(written - p);              }            else              {                b.getRunTime().multipleIdsWritten(ids, b.getPosition());                StringSeqHelper.write(output, ids);              }          }      }    else      StringSeqHelper.write(output, ids);  }  /**   * Get the helper that could write the given object, or null if no pre-defined   * helper available for this object.   */  public static BoxedValueHelper getHelper(Class x, Object ids)  {    if (x != null && x.equals(String.class))      return m_StringValueHelper;    else if (x != null && x.isArray())      return new ArrayValueHelper(x);    else if (ids instanceof String)      return locateHelper((String) ids);    else if (ids instanceof String[])      {        String[] ia = (String[]) ids;        BoxedValueHelper h;        for (int i = 0; i < ia.length; i++)          {            h = locateHelper(ia[i]);            if (h != null)              return h;          }        return null;      }    else      return null;  }  /**   * Get the helper that could write the given object, or null if no pre-defined   * helper available for this object.   */  public static BoxedValueHelper getHelper(Class x, String id)  {    if (x != null && x.equals(String.class))      return m_StringValueHelper;    else if (x != null && x.isArray())      return new ArrayValueHelper(x);    else      return locateHelper(id);  }  /**   * Try to locate helper from the repository id.   */  static BoxedValueHelper locateHelper(String id)  {    if (id != null)      {        if (id.equals(m_StringValueHelper.get_id()))          return m_StringValueHelper;        else        // Try to locate helper for IDL type.        if (id.startsWith("IDL:"))          {            try              {                Class helperClass = ObjectCreator.findHelper(id);                if (BoxedValueHelper.class.isAssignableFrom(helperClass))                  return (BoxedValueHelper) helperClass.newInstance();                else if (helperClass != null)                  return new IDLTypeHelper(helperClass);                else                  return null;              }            catch (Exception ex)              {                return null;              }          }      }    return null;  }  /**   * Get the current position.   */  static int getCurrentPosition(InputStream x)  {    if (x instanceof gnuValueStream)      return ((gnuValueStream) x).getPosition();    else      return 0;  }  /**   * Instantiate an instance of this class anyway; also in the case when it has   * no parameterless or any other constructor. The fields will be assigned   * while reading the class from the stream.   *    * @param clazz a class for that the instance should be instantiated.   */  public static Object instantiateAnyWay(Class clazz)    throws Exception  {    Class first_nonserial = clazz;    while (Serializable.class.isAssignableFrom(first_nonserial)      || Modifier.isAbstract(first_nonserial.getModifiers()))      first_nonserial = first_nonserial.getSuperclass();    final Class local_constructor_class = first_nonserial;    Constructor constructor = local_constructor_class.getDeclaredConstructor(new Class[0]);    return VMVio.allocateObject(clazz, constructor.getDeclaringClass(),      constructor);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -