gnu.CORBA.CDR

Class AbstractCdrOutput

Implemented Interfaces:
AutoCloseable, Closeable, DataOutputStream, Flushable, IDLEntity, Serializable, ValueBase
Known Direct Subclasses:
BufferedCdrOutput, EncapsulationStream

public abstract class AbstractCdrOutput
extends OutputStream
implements DataOutputStream

A simple CORBA CDR (common data representation) output stream, writing data into the given OutputStream. The same class also implements the 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.

Field Summary

protected AbstractDataOutput
b
This instance is used to convert primitive data types into the byte sequences.
protected CodeSetServiceContext
codeset
The code set information.
protected Version
giop
The GIOP version.
protected ORB
orb
The associated orb, if any.
gnuRuntime
runtime
The runtime, associated with this stream.

Constructor Summary

AbstractCdrOutput()
Creates the stream, requiring the subsequent call of setOutputStream(OutputStream).
AbstractCdrOutput(OutputStream writeTo)
Creates the stream.

Method Summary

String[]
_truncatable_ids()
Get the truncatable repository ids.
abstract void
align(int boundary)
Align the curretn position at the given natural boundary.
void
cloneSettings(AbstractCdrOutput stream)
Clone all important settings to another stream.
AbstractCdrOutput
createEncapsulation()
Create the encapsulation stream, associated with the current stream.
CodeSetServiceContext
getCodeSet()
Get the current code set context.
ORB
orb()
Return the associated ORB.
void
setBigEndian(boolean use_big_endian)
Specify if the stream should use the Big Endian (usual for java) or Little Encoding.
void
setCodeSet(CodeSetServiceContext a_codeset)
Set the current code set context.
abstract void
setOffset(int an_offset)
Set the alignment offset, if the index of the first byte in the stream is different from 0.
void
setOrb(ORB an_orb)
Set the orb, associated with this stream.
void
setOutputStream(OutputStream writeTo)
Set the output stream that receives the CORBA output.
void
setVersion(Version giop_version)
Set the GIOP version.
void
write(byte[] x)
Write bytes directly into the underlying stream.
void
write(byte[] x, int ofs, int len)
Write bytes directly into the underlying stream.
void
write(int n)
Write a single byte.
void
write_Abstract(Object value)
void
write_Context(Context context, ContextList contexts)
Following the specification, this is not implemented.
void
write_Object(Object x)
Read the CORBA object.
void
write_TypeCode(TypeCode x)
Write the TypeCode.
void
write_Value(Serializable value)
void
write_any(Any x)
Writes an instance of the CORBA Any.
void
write_any_array(Any[] anys, int offset, int length)
void
write_boolean(boolean x)
Writes a single byte, 0 for false, 1 for true.
void
write_boolean_array(boolean[] x, int ofs, int len)
Writes the boolean array.
void
write_char(char x)
Writes the lower byte of the passed parameter.
void
write_char_array(char[] chars, int offset, int length)
Writes the lower bytes of the passed array members.
void
write_double(double x)
Writes the double value (IEEE 754 format).
void
write_double_array(double[] x, int ofs, int len)
Writes the array of double values.
void
write_fixed(BigDecimal fixed)
Writes CORBA fixed, storing all digits but not the scale.
void
write_float(float x)
Write the float value (IEEE 754 format).
void
write_float_array(float[] x, int ofs, int len)
Writes an array of the float values.
void
write_long(int x)
Writes the integer value (CORBA long, four bytes, high byte first).
void
write_long_array(int[] x, int ofs, int len)
Writes the array of integer (CORBA long) values.
void
write_longlong(long x)
Writes the long (CORBA long long) value, 8 bytes, high byte first.
void
write_longlong_array(long[] x, int ofs, int len)
Writes the array of longs (CORBA long longs) values.
void
write_octet(byte x)
Writes this byte.
void
write_octet_array(byte[] x, int ofs, int len)
Writes the array of bytes (CORBA octets) values.
void
write_sequence(byte[] buf)
Writes first the size of array, and then the byte array using the OutputStream.write(byte[]).
void
write_sequence(BufferedCdrOutput from)
Writes the contents of the provided stream.
void
write_short(short x)
Writes the two byte integer (short), high byte first.
void
write_short_array(short[] x, int ofs, int len)
Writes the array of short (two byte integer) values.
void
write_string(String x)
Writes the string.
void
write_ulong(int x)
Writes the CORBA unsigned long in the same way as CORBA long.
void
write_ulong_array(int[] x, int ofs, int len)
Writes the array of CORBA unsigned longs in the same way as array of ordinary longs.
void
write_ulonglong(long x)
Write the unsigned long long in the same way as an ordinary long long.
void
write_ulonglong_array(long[] x, int ofs, int len)
Write the array of unsingel long longs in the same way an an array of the ordinary long longs.
void
write_ushort(short x)
Write the unsigned short in the same way as an ordinary short.
void
write_ushort_array(short[] x, int ofs, int len)
Write an array of unsigned short integersin the same way as an array of ordinary short integers.
void
write_wchar(char x)
Writes the character as two byte short integer (Unicode value), high byte first.
void
write_wchar_array(char[] chars, int offset, int length)
Write the array of wide chars.
void
write_wstring(String x)
Writes the length of the string in bytes (not characters) and then all characters as two byte unicode chars.

Methods inherited from class org.omg.CORBA_2_3.portable.OutputStream

write_abstract_interface, write_value, write_value, write_value

Methods inherited from class org.omg.CORBA.portable.OutputStream

create_input_stream, orb, write, write_Context, write_Object, write_Principal, write_TypeCode, write_any, write_boolean, write_boolean_array, write_char, write_char_array, write_double, write_double_array, write_fixed, write_float, write_float_array, write_long, write_long_array, write_longlong, write_longlong_array, write_octet, write_octet_array, write_short, write_short_array, write_string, write_ulong, write_ulong_array, write_ulonglong, write_ulonglong_array, write_ushort, write_ushort_array, write_wchar, write_wchar_array, write_wstring

Methods inherited from class java.io.OutputStream

close, flush, write, write, write

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

b

protected AbstractDataOutput b
This instance is used to convert primitive data types into the byte sequences.

codeset

protected CodeSetServiceContext codeset
The code set information.

giop

protected Version giop
The GIOP version.

orb

protected ORB orb
The associated orb, if any.

runtime

public gnuRuntime runtime
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.

Constructor Details

AbstractCdrOutput

public AbstractCdrOutput()
Creates the stream, requiring the subsequent call of setOutputStream(OutputStream).

AbstractCdrOutput

public AbstractCdrOutput(OutputStream writeTo)
Creates the stream.
Parameters:
writeTo - a stream to write CORBA output to.

Method Details

_truncatable_ids

public String[] _truncatable_ids()
Get the truncatable repository ids.
Specified by:
_truncatable_ids in interface ValueBase
Returns:
the array of repository ids, defining the base types, to that basic types this value base can be truncated.

align

public abstract void align(int boundary)
Align the curretn position at the given natural boundary.

cloneSettings

public void cloneSettings(AbstractCdrOutput stream)
Clone all important settings to another stream.

createEncapsulation

public AbstractCdrOutput createEncapsulation()
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.
Returns:
the encapsulated stream.

getCodeSet

public CodeSetServiceContext getCodeSet()
Get the current code set context.

orb

public ORB orb()
Return the associated ORB.
Overrides:
orb in interface OutputStream
Returns:
the associated ORB or null is no such is set.

setBigEndian

public void setBigEndian(boolean use_big_endian)
Specify if the stream should use the Big Endian (usual for java) or Little Encoding. The default is Big Endian.
Parameters:
use_big_endian - if true, use Big Endian, if false, use Little Endian.

setCodeSet

public void setCodeSet(CodeSetServiceContext a_codeset)
Set the current code set context.

setOffset

public abstract void setOffset(int an_offset)
Set the alignment offset, if the index of the first byte in the stream is different from 0.

setOrb

public void setOrb(ORB an_orb)
Set the orb, associated with this stream.
Parameters:
an_orb -

setOutputStream

public void setOutputStream(OutputStream writeTo)
Set the output stream that receives the CORBA output.
Parameters:
writeTo - the stream.

setVersion

public void setVersion(Version giop_version)
Set the GIOP version. Some data types are written differently for the different versions. The default version is 1.0 .

write

public void write(byte[] x)
            throws IOException
Write bytes directly into the underlying stream.
Overrides:
write in interface OutputStream

write

public void write(byte[] x,
                  int ofs,
                  int len)
            throws IOException
Write bytes directly into the underlying stream.
Overrides:
write in interface OutputStream

write

public void write(int n)
Write a single byte.
Overrides:
write in interface OutputStream
Parameters:
n - byte to write (low 8 bits are written).

write_Abstract

public void write_Abstract(Object value)
Specified by:
write_Abstract in interface DataOutputStream

write_Context

public void write_Context(Context context,
                          ContextList contexts)
Following the specification, this is not implemented. Override to get the functionality.
Overrides:
write_Context in interface OutputStream

write_Object

public void write_Object(Object x)
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 IOR.write_no_endian. The null value is written as defined in OMG specification (zero length string, followed by an empty set of profiles).
Specified by:
write_Object in interface DataOutputStream
Overrides:
write_Object in interface OutputStream

write_TypeCode

public void write_TypeCode(TypeCode x)
Write the TypeCode. This implementation delegates functionality to cdrTypeCode.
Specified by:
write_TypeCode in interface DataOutputStream
Overrides:
write_TypeCode in interface OutputStream
Parameters:
x - a TypeCode to write.

write_Value

public void write_Value(Serializable value)
Specified by:
write_Value in interface DataOutputStream

write_any

public void write_any(Any x)
Writes an instance of the CORBA Any. This method writes the typecode, followed by value itself. In Any contains null (value not set), the TCKind.tk_null is written.
Specified by:
write_any in interface DataOutputStream
Overrides:
write_any in interface OutputStream
Parameters:
x - the Any to write.

write_any_array

public void write_any_array(Any[] anys,
                            int offset,
                            int length)
Specified by:
write_any_array in interface DataOutputStream

write_boolean

public void write_boolean(boolean x)
Writes a single byte, 0 for false, 1 for true.
Specified by:
write_boolean in interface DataOutputStream
Overrides:
write_boolean in interface OutputStream
Parameters:
x - the value to write

write_boolean_array

public void write_boolean_array(boolean[] x,
                                int ofs,
                                int len)
Writes the boolean array.
Specified by:
write_boolean_array in interface DataOutputStream
Overrides:
write_boolean_array in interface OutputStream
Parameters:
x - array
ofs - offset
len - length.

write_char

public void write_char(char x)
Writes the lower byte of the passed parameter.
Specified by:
write_char in interface DataOutputStream
Overrides:
write_char in interface OutputStream
Parameters:
x - the char to write It is effective to write more characters at once.

write_char_array

public void write_char_array(char[] chars,
                             int offset,
                             int length)
Writes the lower bytes of the passed array members.
Specified by:
write_char_array in interface DataOutputStream
Overrides:
write_char_array in interface OutputStream
Parameters:
chars - an array
offset - offset
length - length

write_double

public void write_double(double x)
Writes the double value (IEEE 754 format).
Specified by:
write_double in interface DataOutputStream
Overrides:
write_double in interface OutputStream

write_double_array

public void write_double_array(double[] x,
                               int ofs,
                               int len)
Writes the array of double values.
Specified by:
write_double_array in interface DataOutputStream
Overrides:
write_double_array in interface OutputStream

write_fixed

public void write_fixed(BigDecimal fixed)
Writes CORBA fixed, storing all digits but not the scale. The end of the record on fixed can be determined from its last byte.
Overrides:
write_fixed in interface OutputStream

write_float

public void write_float(float x)
Write the float value (IEEE 754 format).
Specified by:
write_float in interface DataOutputStream
Overrides:
write_float in interface OutputStream

write_float_array

public void write_float_array(float[] x,
                              int ofs,
                              int len)
Writes an array of the float values.
Specified by:
write_float_array in interface DataOutputStream
Overrides:
write_float_array in interface OutputStream

write_long

public void write_long(int x)
Writes the integer value (CORBA long, four bytes, high byte first).
Specified by:
write_long in interface DataOutputStream
Overrides:
write_long in interface OutputStream
Parameters:
x - the value to write.

write_long_array

public void write_long_array(int[] x,
                             int ofs,
                             int len)
Writes the array of integer (CORBA long) values.
Specified by:
write_long_array in interface DataOutputStream
Overrides:
write_long_array in interface OutputStream
Parameters:
x - value
ofs - offset
len - length

write_longlong

public void write_longlong(long x)
Writes the long (CORBA long long) value, 8 bytes, high byte first.
Specified by:
write_longlong in interface DataOutputStream
Overrides:
write_longlong in interface OutputStream
Parameters:
x - the value to write.

write_longlong_array

public void write_longlong_array(long[] x,
                                 int ofs,
                                 int len)
Writes the array of longs (CORBA long longs) values.
Specified by:
write_longlong_array in interface DataOutputStream
Overrides:
write_longlong_array in interface OutputStream
Parameters:
x - value
ofs - offset
len - length

write_octet

public void write_octet(byte x)
Writes this byte.
Specified by:
write_octet in interface DataOutputStream
Overrides:
write_octet in interface OutputStream
Parameters:
x -

write_octet_array

public void write_octet_array(byte[] x,
                              int ofs,
                              int len)
Writes the array of bytes (CORBA octets) values.
Specified by:
write_octet_array in interface DataOutputStream
Overrides:
write_octet_array in interface OutputStream
Parameters:
x - value
ofs - offset
len - length

write_sequence

public void write_sequence(byte[] buf)
Writes first the size of array, and then the byte array using the OutputStream.write(byte[]). The sequence being written is preceeded by the int, representing the array length.

write_sequence

public void write_sequence(BufferedCdrOutput from)
Writes the contents of the provided stream. The sequence being written is preceeded by the int, representing the stream buffer length (the number of bytes being subsequently written).

write_short

public void write_short(short x)
Writes the two byte integer (short), high byte first.
Specified by:
write_short in interface DataOutputStream
Overrides:
write_short in interface OutputStream
Parameters:
x - the integer to write.

write_short_array

public void write_short_array(short[] x,
                              int ofs,
                              int len)
Writes the array of short (two byte integer) values.
Specified by:
write_short_array in interface DataOutputStream
Overrides:
write_short_array in interface OutputStream
Parameters:
x - value
ofs - offset
len - length

write_string

public void write_string(String x)
Writes the string. This implementation first calls String.getBytes() and then writes the length of the returned array (as CORBA ulong) and the returned array itself. The encoding information, if previously set, is taken into consideration.
Specified by:
write_string in interface DataOutputStream
Overrides:
write_string in interface OutputStream
Parameters:
x - the string to write.

write_ulong

public void write_ulong(int x)
Writes the CORBA unsigned long in the same way as CORBA long.
Specified by:
write_ulong in interface DataOutputStream
Overrides:
write_ulong in interface OutputStream

write_ulong_array

public void write_ulong_array(int[] x,
                              int ofs,
                              int len)
Writes the array of CORBA unsigned longs in the same way as array of ordinary longs.
Specified by:
write_ulong_array in interface DataOutputStream
Overrides:
write_ulong_array in interface OutputStream

write_ulonglong

public void write_ulonglong(long x)
Write the unsigned long long in the same way as an ordinary long long.
Specified by:
write_ulonglong in interface DataOutputStream
Overrides:
write_ulonglong in interface OutputStream
Parameters:
x - a value to write.

write_ulonglong_array

public void write_ulonglong_array(long[] x,
                                  int ofs,
                                  int len)
Write the array of unsingel long longs in the same way an an array of the ordinary long longs.
Specified by:
write_ulonglong_array in interface DataOutputStream
Overrides:
write_ulonglong_array in interface OutputStream

write_ushort

public void write_ushort(short x)
Write the unsigned short in the same way as an ordinary short.
Specified by:
write_ushort in interface DataOutputStream
Overrides:
write_ushort in interface OutputStream

write_ushort_array

public void write_ushort_array(short[] x,
                               int ofs,
                               int len)
Write an array of unsigned short integersin the same way as an array of ordinary short integers.
Specified by:
write_ushort_array in interface DataOutputStream
Overrides:
write_ushort_array in interface OutputStream

write_wchar

public void write_wchar(char x)
Writes the character as two byte short integer (Unicode value), high byte first. Writes in Big Endian, but never writes the endian indicator. The character is always written using the native UTF-16BE charset because its size under arbitrary encoding is not evident.
Specified by:
write_wchar in interface DataOutputStream
Overrides:
write_wchar in interface OutputStream

write_wchar_array

public void write_wchar_array(char[] chars,
                              int offset,
                              int length)
Write the array of wide chars.
Specified by:
write_wchar_array in interface DataOutputStream
Overrides:
write_wchar_array in interface OutputStream
Parameters:
chars - the array of wide chars
offset - offset
length - length The char array is always written using the native UTF-16BE charset because the character size under arbitrary encoding is not evident.

write_wstring

public void write_wstring(String x)
Writes the length of the string in bytes (not characters) and then all characters as two byte unicode chars. Adds the Big Endian indicator, 0xFFFE, at the beginning and null wide char at the end.
Specified by:
write_wstring in interface DataOutputStream
Overrides:
write_wstring in interface OutputStream
Parameters:
x - the string to write.

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 modify it under the terms of the GNU General Public License as published by the 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, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.