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

📄 abstractcdroutput.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* AbstractCdrOutput.java --   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.CORBA.CDR;import gnu.CORBA.BigDecimalHelper;import gnu.CORBA.IOR;import gnu.CORBA.IorProvider;import gnu.CORBA.Minor;import gnu.CORBA.TypeCodeHelper;import gnu.CORBA.Unexpected;import gnu.CORBA.Version;import gnu.CORBA.GIOP.CharSets_OSF;import gnu.CORBA.GIOP.CodeSetServiceContext;import gnu.CORBA.typecodes.PrimitiveTypeCode;import org.omg.CORBA.Any;import org.omg.CORBA.BAD_OPERATION;import org.omg.CORBA.Context;import org.omg.CORBA.ContextList;import org.omg.CORBA.DataInputStream;import org.omg.CORBA.MARSHAL;import org.omg.CORBA.NO_IMPLEMENT;import org.omg.CORBA.ORB;import org.omg.CORBA.TCKind;import org.omg.CORBA.TypeCode;import org.omg.CORBA.UserException;import org.omg.CORBA.TypeCodePackage.BadKind;import org.omg.CORBA.portable.Delegate;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.Streamable;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.Serializable;import java.math.BigDecimal;/** * A simple CORBA CDR (common data representation) * output stream, writing data into the * given {@link java.io.OutputStream}. * * The same class also implements the {@link DataInputStream}, * providing support for writing the value type objects * in a user defined way. *  * TODO This class uses 16 bits per Unicode character only, as it was until * jdk 1.4 inclusive. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */public abstract class AbstractCdrOutput  extends org.omg.CORBA_2_3.portable.OutputStream  implements org.omg.CORBA.DataOutputStream{  /**   * The runtime, associated with this stream. This field is only used when    * reading and writing value types and filled-in in gnu.CORBA.CDR.Vio.   */  public transient gnuRuntime runtime;      /**   * This instance is used to convert primitive data types into the   * byte sequences.   */  protected AbstractDataOutput b;  /**   * The associated orb, if any.   */  protected ORB orb;  /**   * The GIOP version.   */  protected Version giop = new Version(1, 2);  /**   * The code set information.   */  protected CodeSetServiceContext codeset;  /**   * The name of the currently used narrow charset.   */  private String narrow_charset;  /**   * The name of the currently used wide charset, null if   * the native wide charset is used.   */  private String wide_charset;  /**   * True if the native code set is used for narrow characters.   * If the set is native, no the intermediate Reader object   * is instantiated when writing characters.   */  private boolean narrow_native;  /**   * True if the native code set is used for wide characters.   * If the set is native, no the intermediate Reader object   * is instantiated when writing characters.   */  private boolean wide_native;  /**   * If true, the Little Endian encoding is used to write the   * data. Otherwise, the Big Endian encoding is used.   */  private boolean little_endian;  /**   * The stream whre the data are actually written.   */  private java.io.OutputStream actual_stream;  /**   * Creates the stream.   *   * @param writeTo a stream to write CORBA output to.   */  public AbstractCdrOutput(java.io.OutputStream writeTo)  {    setOutputStream(writeTo);    setCodeSet(CodeSetServiceContext.STANDARD);  }  /**   * Creates the stream, requiring the subsequent call   * of {@link #setOutputStream(java.io.OutputStream)}.   */  public AbstractCdrOutput()  {    setCodeSet(CodeSetServiceContext.STANDARD);  }  /**   * Set the alignment offset, if the index of the first byte in the   * stream is different from 0.   */  public abstract void setOffset(int an_offset);    /**   * Clone all important settings to another stream.   */  public void cloneSettings(AbstractCdrOutput stream)  {    stream.setBigEndian(!little_endian);    stream.setCodeSet(getCodeSet());    stream.setVersion(giop);    stream.setOrb(orb);  }    /**   * Set the current code set context.   */  public void setCodeSet(CodeSetServiceContext a_codeset)  {    this.codeset = a_codeset;    narrow_charset = CharSets_OSF.getName(codeset.char_data);    wide_charset = CharSets_OSF.getName(codeset.wide_char_data);    narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data;    wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data;  }  /**   * Get the current code set context.   */  public CodeSetServiceContext getCodeSet()  {    return codeset;  }  /**   * Set the orb, associated with this stream.   * @param an_orb   */  public void setOrb(ORB an_orb)  {    orb = an_orb;  }  /**   * Set the output stream that receives the CORBA output.   *   * @param writeTo the stream.   */  public void setOutputStream(java.io.OutputStream writeTo)  {    if (little_endian)      b = new LittleEndianOutputStream(writeTo);    else      b = new BigEndianOutputStream(writeTo);    actual_stream = writeTo;  }  /**   * Set the GIOP version. Some data types are written differently   * for the different versions. The default version is 1.0 .   */  public void setVersion(Version giop_version)  {    giop = giop_version;  }  /**   * Specify if the stream should use the Big Endian (usual for java)   * or Little Encoding. The default is Big Endian.   *   * @param use_big_endian if true, use Big Endian, if false,   * use Little Endian.   */  public void setBigEndian(boolean use_big_endian)  {    little_endian = !use_big_endian;    setOutputStream(actual_stream);  }  /**   * Align the curretn position at the given natural boundary.   */  public abstract void align(int boundary);  /**   * Create the encapsulation stream, associated with the current   * stream. The encapsulated stream must be closed. When being   * closed, the encapsulation stream writes its buffer into   * this stream using the CORBA CDR encapsulation rules.   *   * It is not allowed to write to the current stream directly   * before the encapsulation stream is closed.   *   * The encoding (Big/Little Endian) inside the encapsulated   * sequence is the same as used into the parent stream.   *   * @return the encapsulated stream.   */  public AbstractCdrOutput createEncapsulation()  {    return new EncapsulationStream(this, !little_endian);  }  /**   * Return the associated {@link ORB}.   * @return the associated {@link ORB} or null is no such is set.   */  public ORB orb()  {    return orb;  }  /**   * Write a single byte.   * @param a byte to write (low 8 bits are written).   */  public void write(int n)  {    try      {        b.write(n);      }    catch (IOException ex)      {        Unexpected.error(ex);      }  }  /**   * Write bytes directly into the underlying stream.   */  public void write(byte[] x)             throws java.io.IOException  {    b.write(x);  }  /**   * Write bytes directly into the underlying stream.   */  public void write(byte[] x, int ofs, int len)             throws java.io.IOException  {    b.write(x, ofs, len);  }  /**   * Following the specification, this is not implemented.   * Override to get the functionality.   */  public void write_Context(Context context, ContextList contexts)  {    throw new NO_IMPLEMENT();  }  /**   * Read the CORBA object. The object is written form of the plain (not a   * string-encoded) IOR profile without the heading endian indicator. The   * responsible method for reading such data is {@link IOR.write_no_endian}.   *    * The null value is written as defined in OMG specification (zero length   * string, followed by an empty set of profiles).   */  public void write_Object(org.omg.CORBA.Object x)  {    ORB w_orb = orb;    if (x instanceof IorProvider)      {        ((IorProvider) x).getIor()._write_no_endian(this);        return;      }    else if (x == null)      {        IOR.write_null(this);        return;      }    else if (x instanceof ObjectImpl)      {        Delegate d = ((ObjectImpl) x)._get_delegate();        if (d instanceof IorProvider)          {            ((IorProvider) d).getIor()._write_no_endian(this);            return;          }        else          {            ORB d_orb = d.orb(x);            if (d_orb != null)              w_orb = d_orb;          }      }    // Either this is not an ObjectImpl or it has the    // unexpected delegate. Try to convert via ORBs    // object_to_string().    if (w_orb != null)      {        IOR ior = IOR.parse(w_orb.object_to_string(x));        ior._write_no_endian(this);        return;      }    else      throw new BAD_OPERATION(        "Please set the ORB for this stream, cannot write "          + x.getClass().getName());  }  /**   * Write the TypeCode. This implementation delegates functionality   * to {@link cdrTypeCode}.   *   * @param x a TypeCode to write.   */  public void write_TypeCode(TypeCode x)  {    try      {        TypeCodeHelper.write(this, x);      }    catch (UserException ex)      {        Unexpected.error(ex);      }  }  /**   * Writes an instance of the CORBA {@link Any}.   * This method writes the typecode, followed   * by value itself. In Any contains null   * (value not set), the {@link TCKind#tk_null}   * is written.   *   * @param x the {@link Any} to write.   */  public void write_any(Any x)  {    Streamable value = x.extract_Streamable();    if (value != null)      {        write_TypeCode(x.type());        value._write(this);      }    else      {        PrimitiveTypeCode p = new PrimitiveTypeCode(TCKind.tk_null);        write_TypeCode(p);      }  }  /**   * Writes a single byte, 0 for <code>false</code>,   * 1 for <code>true</code>.   *   * @param x the value to write   */  public void write_boolean(boolean x)  {    try      {        b.write(x ? 1 : 0);      }    catch (IOException ex)      {        Unexpected.error(ex);      }  }  /**   * Writes the boolean array.   *   * @param x array   * @param ofs offset   * @param len length.   */  public void write_boolean_array(boolean[] x, int ofs, int len)  {    try      {        for (int i = ofs; i < ofs + len; i++)          {            b.write(x [ i ] ? 1 : 0);          }      }    catch (IOException ex)      {        Unexpected.error(ex);      }  }  /**   * Writes the lower byte of the passed parameter.   * @param x the char to write   *   * It is effective to write more characters at once.   */  public void write_char(char x)  {    try      {        if (narrow_native)          b.write(x);        else          {            OutputStreamWriter ow =              new OutputStreamWriter((OutputStream) b, narrow_charset);            ow.write(x);            ow.flush();          }      }    catch (IOException ex)      {        Unexpected.error(ex);      }  }  /**   * Writes the lower bytes of the passed array members.   *   * @param chars an array   * @param offsets offset   * @param length length   */  public void write_char_array(char[] chars, int offset, int length)  {    try      {        if (narrow_native)          {            for (int i = offset; i < offset + length; i++)              {                b.write(chars [ i ]);              }          }        else          {            OutputStreamWriter ow =              new OutputStreamWriter((OutputStream) b, narrow_charset);            ow.write(chars, offset, length);            ow.flush();          }      }    catch (IOException ex)      {        Unexpected.error(ex);

⌨️ 快捷键说明

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