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

📄 ior.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        for (int i = 0; i < x.length(); i = i + 2)          {            cx = (char) Integer.parseInt(x.substring(i, i + 2), 16);            buf.write(cx);          }        BufferredCdrInput cdr = new BufferredCdrInput(buf.toByteArray());        r._read(cdr);        return r;      }    catch (Exception ex)      {        ex.printStackTrace();        throw new BAD_PARAM(ex + " while parsing " + stringified_reference,                            FAILED, CompletionStatus.COMPLETED_NO);      }  }  /**   * Read the IOR from the provided input stream.   *   * @param c a stream to read from.   * @throws IOException if the stream throws it.   */  public void _read(AbstractCdrInput c)    throws IOException, BAD_PARAM  {    int endian;    endian = c.read_long();    if (endian != 0)      {        Big_Endian = false;        c.setBigEndian(false);      }    _read_no_endian(c);  }  /**   * Read the IOR from the provided input stream, not reading the endian data at   * the beginning of the stream. The IOR is thansferred in this form in   * {@link write_Object(org.omg.CORBA.Object)}.   *   * If the stream contains a null value, the Id and Internet fields become   * equal to null. Otherwise Id contains some string (possibly empty).   *   * Id is checked for null in AbstractCdrInput that then returns null instead of   * object.   *   * @param c a stream to read from.   * @throws IOException if the stream throws it.   */  public void _read_no_endian(AbstractCdrInput c)    throws IOException, BAD_PARAM  {    Id = c.read_string();    int n_profiles = c.read_long();    if (n_profiles == 0)      {        Id = null;        Internet = null;        return;      }    for (int i = 0; i < n_profiles; i++)      {        int tag = c.read_long();        BufferredCdrInput profile = c.read_encapsulation();        if (tag == Internet_profile.TAG_INTERNET_IOP)          {            Internet = new Internet_profile();            Internet.version = Version.read_version(profile);            Internet.host = profile.read_string();            Internet.port = profile.gnu_read_ushort();            key = profile.read_sequence();            // Read tagged components.            int n_components = 0;            try              {                if (Internet.version.since_inclusive(1, 1))                  n_components = profile.read_long();                for (int t = 0; t < n_components; t++)                  {                    int ctag = profile.read_long();                    if (ctag == CodeSets_profile.TAG_CODE_SETS)                      {                        Internet.CodeSets.read(profile);                      }                    else                      {                        // Construct a generic component for codesets                        // profile.                        TaggedComponent pc = new TaggedComponent();                        pc.tag = ctag;                        pc.component_data = profile.read_sequence();                        Internet.components.add(pc);                      }                  }              }            catch (Unexpected ex)              {                ex.printStackTrace();              }          }        else          {            // Construct a generic profile.            TaggedProfile p = new TaggedProfile();            p.tag = tag;            p.profile_data = profile.buffer.getBuffer();            profiles.add(p);          }      }  }  /**   * Write this IOR record to the provided CDR stream. This procedure writes the   * zero (Big Endian) marker first.   */  public void _write(AbstractCdrOutput out)  {    // Always use Big Endian.    out.write(0);    _write_no_endian(out);  }  /**   * Write a null value to the CDR output stream.   *   * The null value is written as defined in OMG specification (zero length   * string, followed by an empty set of profiles).   */  public static void write_null(AbstractCdrOutput out)  {    // Empty Id string.    out.write_string("");    // Empty set of profiles.    out.write_long(0);  }  /**   * Write this IOR record to the provided CDR stream. The procedure writed data   * in Big Endian, but does NOT add any endian marker to the beginning.   */  public void _write_no_endian(AbstractCdrOutput out)  {    // Write repository id.    out.write_string(Id);    out.write_long(1 + profiles.size());    // Write the Internet profile.    out.write_long(Internet_profile.TAG_INTERNET_IOP);    Internet.write(out);    // Write other profiles.    TaggedProfile tp;    for (int i = 0; i < profiles.size(); i++)      {        tp = (TaggedProfile) profiles.get(i);        TaggedProfileHelper.write(out, tp);      }  }  /**   * Returns a human readable string representation of this IOR object.   */  public String toString()  {    StringBuffer b = new StringBuffer();    b.append(Id);    b.append(" at ");    b.append(Internet);    if (!Big_Endian)      b.append(" (Little endian) ");    b.append(" Key ");    for (int i = 0; i < key.length; i++)      {        b.append(Integer.toHexString(key[i] & 0xFF));      }    b.append(" ");    b.append(Internet.CodeSets);    return b.toString();  }    /**   * Returns a multiline formatted human readable string representation of    * this IOR object.   */  public String toStringFormatted()  {    StringBuffer b = new StringBuffer();    b.append("\nObject Id:\n  ");    b.append(Id);    b.append("\nObject is accessible at:\n  ");    b.append(Internet);    if (Big_Endian)      b.append("\n  Big endian encoding");    else      b.append("\n  Little endian encoding.");          b.append("\nObject Key\n  ");    for (int i = 0; i < key.length; i++)      {        b.append(Integer.toHexString(key[i] & 0xFF));      }    b.append("\nSupported code sets:");    b.append("\n Wide:");    b.append(Internet.CodeSets.wide.toStringFormatted());    b.append(" Narrow:");    b.append(Internet.CodeSets.wide.toStringFormatted());    return b.toString();  }    /**   * Returs a stringified reference.   *   * @return a newly constructed stringified reference.   */  public String toStringifiedReference()  {    BufferedCdrOutput out = new BufferedCdrOutput();    _write(out);    StringBuffer b = new StringBuffer("IOR:");    byte[] binary = out.buffer.toByteArray();    String s;    for (int i = 0; i < binary.length; i++)      {        s = Integer.toHexString(binary[i] & 0xFF);        if (s.length() == 1)          b.append('0');        b.append(s);      }    return b.toString();  }  /**   * Adds a service-specific component to the IOR profile. The specified   * component will be included in all profiles, present in the IOR.   *   * @param tagged_component a tagged component being added.   */  public void add_ior_component(TaggedComponent tagged_component)  {    // Add to the Internet profile.    Internet.components.add(tagged_component);    // Add to others.    for (int i = 0; i < profiles.size(); i++)      {        TaggedProfile profile = (TaggedProfile) profiles.get(i);        addComponentTo(profile, tagged_component);      }  }  /**   * Adds a service-specific component to the IOR profile.   *   * @param tagged_component a tagged component being added.   *   * @param profile_id the IOR profile to that the component must be added. The   * 0 value ({@link org.omg.IOP.TAG_INTERNET_IOP#value}) adds to the Internet   * profile where host and port are stored by default.   */  public void add_ior_component_to_profile(TaggedComponent tagged_component,                                           int profile_id)  {    if (profile_id == TAG_INTERNET_IOP.value)      // Add to the Internet profile      Internet.components.add(tagged_component);    else      {        // Add to others.        for (int i = 0; i < profiles.size(); i++)          {            TaggedProfile profile = (TaggedProfile) profiles.get(i);            if (profile.tag == profile_id)              addComponentTo(profile, tagged_component);          }      }  }  /**   * Add given component to the given profile that is NOT an Internet profile.   *   * @param profile the profile, where the component should be added.   * @param component the component to add.   */  private static void addComponentTo(TaggedProfile profile,                                     TaggedComponent component)  {    if (profile.tag == TAG_MULTIPLE_COMPONENTS.value)      {        TaggedComponent[] present;        if (profile.profile_data.length > 0)          {            BufferredCdrInput in = new BufferredCdrInput(profile.profile_data);            present = new TaggedComponent[in.read_long()];            for (int i = 0; i < present.length; i++)              {                present[i] = TaggedComponentHelper.read(in);              }          }        else          present = new TaggedComponent[0];        BufferedCdrOutput out = new BufferedCdrOutput(profile.profile_data.length                                            + component.component_data.length                                            + 8);        // Write new amount of components.        out.write_long(present.length + 1);        // Write other components.        for (int i = 0; i < present.length; i++)          TaggedComponentHelper.write(out, present[i]);        // Write the passed component.        TaggedComponentHelper.write(out, component);        try          {            out.close();          }        catch (IOException e)          {            throw new Unexpected(e);          }        profile.profile_data = out.buffer.toByteArray();      }    else      // The future supported tagged profiles should be added here.      throw new BAD_PARAM("Unsupported profile type " + profile.tag);  }    /**   * Checks for equality.   */  public boolean equals(Object x)  {    if (x instanceof IOR)      {        boolean keys;        boolean hosts = true;        IOR other = (IOR) x;                if (Internet==null || other.Internet==null)          return Internet == other.Internet;                if (key != null && other.key != null)          keys = Arrays.equals(key, other.key);        else          keys = key == other.key;        if (Internet != null && Internet.host != null)          if (other.Internet != null && other.Internet.host != null)            hosts = other.Internet.host.equals(Internet.host);        return keys & hosts && Internet.port==other.Internet.port;      }    else      return false;  }    /**   * Get the hashcode of this IOR.   */  public int hashCode()  {    Adler32 adler = new Adler32();    if (key != null)      adler.update(key);    if (Internet != null)      {        if (Internet.host != null)          adler.update(Internet.host.getBytes());        adler.update(Internet.port);      }    return (int) adler.getValue();  }}

⌨️ 快捷键说明

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