gnu.CORBA.CDR

Class AbstractCdrInput

Implemented Interfaces:
AutoCloseable, Closeable, DataInputStream, IDLEntity, Serializable, ValueBase
Known Direct Subclasses:
BufferredCdrInput

public abstract class AbstractCdrInput
extends InputStream
implements DataInputStream

A simple CORBA CDR (common data representation) input stream, reading data from the given InputStream. The primitive types are aligned on they natural boundaries by implementing the abstract method align(int boundary). The same class also implements DataInputStream to read the object content 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 static String
UNEXP_EOF
The message, explaining that the exception has been thrown due unexpected end of the input stream.
protected InputStream
actual_stream
The input stream, from where the data are actually being read.
protected AbstractDataInput
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

AbstractCdrInput()
Creates the stream, requiring the subsequent call of setInputStream(InputStream).
AbstractCdrInput(InputStream readFrom)
Creates the stream.

Method Summary

String[]
_truncatable_ids()
This method is required to represent the DataInputStream as a value type object.
abstract void
align(int boundary)
Align the curretn position at the given natural boundary.
void
cloneSettings(AbstractCdrInput stream)
Clone all important settings to another stream.
CodeSetServiceContext
getCodeSet()
Get the current code set context.
long
gnu_read_ulong()
Reads the CORBA unsigned long (java int), returning the value in the sufficiently large java long.
int
gnu_read_ushort()
Read the unsigned short integer value and return it as java int, sufficiently large to hold all values.
boolean
isBigEndian()
Get the used encoding.
ORB
orb()
Return the associated ORB.
int
read()
Read a single byte directly from the buffer.
int
read(byte[] x)
Read bytes directly from the buffer.
int
read(byte[] x, int ofs, int len)
Read bytes directly from the buffer.
Object
read_Abstract()
Read the abstract interface.
Object
read_Object()
Read the CORBA object.
Object
read_Object(Class<T> klass)
Read the object that is an instance of the given class.
TypeCode
read_TypeCode()
Read the type code.
Serializable
read_Value()
Read a value type structure from the stream.
Any
read_any()
Read the CORBA Any.
void
read_any_array(AnySeqHolder holder, int offset, int length)
Read an array.
boolean
read_boolean()
Read the boolean, treating any non zero byte as true, zero byte as false.
void
read_boolean_array(boolean[] x, int offs, int len)
Read the array of boolean.
void
read_boolean_array(BooleanSeqHolder holder, int offset, int length)
Read an array.
char
read_char()
Read a character using narrow charset encoding.
void
read_char_array(char[] x, int offset, int length)
Read a character array, using narrow charset encoding.
void
read_char_array(CharSeqHolder holder, int offset, int length)
Read an array.
double
read_double()
Read the double value, IEEE 754 format.
void
read_double_array(double[] x, int offs, int len)
Read the array of double values, IEEE 754 format.
void
read_double_array(DoubleSeqHolder holder, int offset, int length)
Read an array.
BufferredCdrInput
read_encapsulation()
Read the encapsulated stream.
BigDecimal
read_fixed()
Read the CORBA fixed (the end of the fixed can be determined by its last byte).
float
read_float()
Read the float value, IEEE 754 format.
void
read_float_array(float[] x, int offs, int len)
Read an array of float values, IEEE 754 format.
void
read_float_array(FloatSeqHolder holder, int offset, int length)
Read an array.
int
read_long()
Read the CORBA long (java int), high byte first.
void
read_long_array(int[] x, int offs, int len)
Read an array of CORBA longs (java ints).
void
read_long_array(LongSeqHolder holder, int offset, int length)
Read an array.
long
read_longlong()
Read the CORBA long long (java long).
void
read_longlong_array(long[] x, int offs, int len)
Read an array of CORBA long longs (java longs).
void
read_longlong_array(LongLongSeqHolder holder, int offset, int length)
Read an array.
byte
read_octet()
Read a single byte.
void
read_octet_array(byte[] x, int offs, int len)
Read the byte array.
void
read_octet_array(OctetSeqHolder holder, int offset, int length)
Read an array.
byte[]
read_sequence()
Read the length of the byte array as CORBA long and then the array itseld.
short
read_short()
Read the CORBA short integer.
void
read_short_array(ShortSeqHolder holder, int offset, int length)
Read an array.
void
read_short_array(short[] x, int offs, int len)
Read the array of CORBA short integer values.
String
read_string()
Read a singe byte string.
int
read_ulong()
Reads the CORBA unsigned long (java int), delegating functionality to read_long().
void
read_ulong_array(int[] x, int offs, int len)
Reads the array of CORBA unsigned long (java integer) values, delegating functionality to AbstractCdrInput.
void
read_ulong_array(ULongSeqHolder holder, int offset, int length)
Read an array.
long
read_ulonglong()
Read the CORBA unsigned long long value, delegating functionality to read_longlong().
void
read_ulonglong_array(long[] x, int offs, int len)
Reads the array of CORBA long long (java long) values, delegating functionality to AbstractCdrInput.
void
read_ulonglong_array(ULongLongSeqHolder holder, int offset, int length)
Read an array.
short
read_ushort()
Read the unsigned short integer value.
void
read_ushort_array(UShortSeqHolder holder, int offset, int length)
void
read_ushort_array(short[] x, int offs, int len)
Read an array of unsigned short values, delegating the functionality to read_short_array.
char
read_wchar()
Reads the wide character using the encoding, specified in the wide_charset.
void
read_wchar_array(char[] x, int offset, int length)
Read an array of "wide chars", each representing a two byte Unicode character, high byte first.
void
read_wchar_array(WCharSeqHolder holder, int offset, int length)
Read an array.
String
read_wstring()
Reads the string in wide character format (ussually UTF-16, Unicode).
String
read_wstring_UTF_16()
Reads first length of the string and the all characters as an Unicode (UTF-16) characters.
void
setBigEndian(boolean use_big_endian)
Set the Big Endian or Little Endian encoding.
void
setCodeSet(CodeSetServiceContext a_codeset)
Set the current code set context.
void
setInputStream(InputStream readFrom)
Set the input stream that receives the CORBA input.
abstract void
setOffset(int 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
setVersion(Version giop_version)
Set the GIOP version.
static char
swap(char x)
Swap bytes in the character.

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

read_abstract_interface, read_value, read_value, read_value, read_value

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

orb, read, read_Context, read_Object, read_Principal, read_TypeCode, read_any, read_boolean, read_boolean_array, read_char, read_char_array, read_double, read_double_array, read_fixed, read_float, read_float_array, read_long, read_long_array, read_longlong, read_longlong_array, read_octet, read_octet_array, read_short, read_short_array, read_string, read_ulong, read_ulong_array, read_ulonglong, read_ulonglong_array, read_ushort, read_ushort_array, read_wchar, read_wchar_array, read_wstring

Methods inherited from class java.io.InputStream

available, close, mark, markSupported, read, read, read, reset, skip

Methods inherited from class java.lang.Object

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

Field Details

UNEXP_EOF

protected static final String UNEXP_EOF
The message, explaining that the exception has been thrown due unexpected end of the input stream. This usually happens the server and client disagree on communication or data representation rules.
Field Value:
"Unexpected end of stream"

actual_stream

protected InputStream actual_stream
The input stream, from where the data are actually being read.

b

protected AbstractDataInput 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

AbstractCdrInput

public AbstractCdrInput()
Creates the stream, requiring the subsequent call of setInputStream(InputStream).

AbstractCdrInput

public AbstractCdrInput(InputStream readFrom)
Creates the stream. The stream reads Big Endian by default.
Parameters:
readFrom - a stream to read CORBA input from.

Method Details

_truncatable_ids

public String[] _truncatable_ids()
This method is required to represent the DataInputStream as a value type object.
Specified by:
_truncatable_ids in interface ValueBase
Returns:
a single entity "IDL:omg.org/CORBA/DataInputStream:1.0", always.

align

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

cloneSettings

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

getCodeSet

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

gnu_read_ulong

public long gnu_read_ulong()
Reads the CORBA unsigned long (java int), returning the value in the sufficiently large java long.

gnu_read_ushort

public int gnu_read_ushort()
Read the unsigned short integer value and return it as java int, sufficiently large to hold all values.

isBigEndian

public boolean isBigEndian()
Get the used encoding.
Returns:
true for Big Endian, false for Little Endian.

orb

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

read

public int read()
            throws IOException
Read a single byte directly from the buffer.
Overrides:
read in interface InputStream

read

public int read(byte[] x)
            throws IOException
Read bytes directly from the buffer.
Overrides:
read in interface InputStream

read

public int read(byte[] x,
                int ofs,
                int len)
            throws IOException
Read bytes directly from the buffer.
Overrides:
read in interface InputStream

read_Abstract

public Object read_Abstract()
Read the abstract interface. An abstract interface can be either CORBA value type or CORBA object and is returned as an abstract java.lang.Object. As specified in OMG specification, this reads a single boolean and then delegates either to read_Object() (for false) or to read_Value() (for true).
Specified by:
read_Abstract in interface DataInputStream
Returns:
an abstract interface, unmarshaled from the stream

read_Object

public Object read_Object()
Read the CORBA object. The object to read is represented in the form of the plain (not a string-encoded) IOR profile without the heading endian indicator. The responsible method for reading such data is IOR.read_no_endian. The returned object is usually casted into the given type using the .narrow method of its helper, despite in some cases the direct cast would also work. The null objects are recognised from the empty profile set. For such objects, null is returned.
Specified by:
read_Object in interface DataInputStream
Overrides:
read_Object in interface InputStream
Returns:
the loaded and constructed object.

read_Object

public Object read_Object(Class<T> klass)
Read the object that is an instance of the given class. The current implementation delegates functionality to the parameterless readObject().
Parameters:
klass - a class of that this object the instance is.
Returns:
the returned object.

read_TypeCode

public TypeCode read_TypeCode()
Read the type code. The type code format is defined in the CORBA documenation.
Specified by:
read_TypeCode in interface DataInputStream
Overrides:
read_TypeCode in interface InputStream

read_Value

public Serializable read_Value()
Read a value type structure from the stream. OMG specification states the writing format is outside the scope of GIOP definition. This implementation uses java serialization mechanism, calling ObjectInputStream.readObject
Specified by:
read_Value in interface DataInputStream
Returns:
an value type structure, unmarshaled from the stream

read_any

public Any read_any()
Read the CORBA Any. This method first reads the type code, then delegates the functionality to Any.read_value(InputStream,TypeCode).
Specified by:
read_any in interface DataInputStream
Overrides:
read_any in interface InputStream

read_any_array

public void read_any_array(AnySeqHolder holder,
                           int offset,
                           int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_any_array in interface DataInputStream

read_boolean

public boolean read_boolean()
Read the boolean, treating any non zero byte as true, zero byte as false.
Specified by:
read_boolean in interface DataInputStream
Overrides:
read_boolean in interface InputStream

read_boolean_array

public void read_boolean_array(boolean[] x,
                               int offs,
                               int len)
Read the array of boolean.
Overrides:
read_boolean_array in interface InputStream

read_boolean_array

public void read_boolean_array(BooleanSeqHolder holder,
                               int offset,
                               int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_boolean_array in interface DataInputStream

read_char

public char read_char()
Read a character using narrow charset encoding. Depending form which encoding is set, this still can be Unicode or ever wider.
Specified by:
read_char in interface DataInputStream
Overrides:
read_char in interface InputStream

read_char_array

public void read_char_array(char[] x,
                            int offset,
                            int length)
Read a character array, using narrow charset encoding.
Overrides:
read_char_array in interface InputStream

read_char_array

public void read_char_array(CharSeqHolder holder,
                            int offset,
                            int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_char_array in interface DataInputStream

read_double

public double read_double()
Read the double value, IEEE 754 format.
Specified by:
read_double in interface DataInputStream
Overrides:
read_double in interface InputStream

read_double_array

public void read_double_array(double[] x,
                              int offs,
                              int len)
Read the array of double values, IEEE 754 format.
Overrides:
read_double_array in interface InputStream

read_double_array

public void read_double_array(DoubleSeqHolder holder,
                              int offset,
                              int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_double_array in interface DataInputStream

read_encapsulation

public BufferredCdrInput read_encapsulation()
Read the encapsulated stream. If the encapsulated sequence appears to be in the Little endian format, the flag of the returned stream is set to read Little endian.

read_fixed

public BigDecimal read_fixed()
Read the CORBA fixed (the end of the fixed can be determined by its last byte). The scale is always assumed to be zero.
Overrides:
read_fixed in interface InputStream

read_float

public float read_float()
Read the float value, IEEE 754 format.
Specified by:
read_float in interface DataInputStream
Overrides:
read_float in interface InputStream

read_float_array

public void read_float_array(float[] x,
                             int offs,
                             int len)
Read an array of float values, IEEE 754 format.
Overrides:
read_float_array in interface InputStream

read_float_array

public void read_float_array(FloatSeqHolder holder,
                             int offset,
                             int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_float_array in interface DataInputStream

read_long

public int read_long()
Read the CORBA long (java int), high byte first.
Specified by:
read_long in interface DataInputStream
Overrides:
read_long in interface InputStream

read_long_array

public void read_long_array(int[] x,
                            int offs,
                            int len)
Read an array of CORBA longs (java ints).
Overrides:
read_long_array in interface InputStream

read_long_array

public void read_long_array(LongSeqHolder holder,
                            int offset,
                            int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_long_array in interface DataInputStream

read_longlong

public long read_longlong()
Read the CORBA long long (java long).
Specified by:
read_longlong in interface DataInputStream
Overrides:
read_longlong in interface InputStream

read_longlong_array

public void read_longlong_array(long[] x,
                                int offs,
                                int len)
Read an array of CORBA long longs (java longs).
Overrides:
read_longlong_array in interface InputStream

read_longlong_array

public void read_longlong_array(LongLongSeqHolder holder,
                                int offset,
                                int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_longlong_array in interface DataInputStream

read_octet

public byte read_octet()
Read a single byte.
Specified by:
read_octet in interface DataInputStream
Overrides:
read_octet in interface InputStream

read_octet_array

public void read_octet_array(byte[] x,
                             int offs,
                             int len)
Read the byte array.
Overrides:
read_octet_array in interface InputStream

read_octet_array

public void read_octet_array(OctetSeqHolder holder,
                             int offset,
                             int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_octet_array in interface DataInputStream

read_sequence

public byte[] read_sequence()
Read the length of the byte array as CORBA long and then the array itseld.

read_short

public short read_short()
Read the CORBA short integer.
Specified by:
read_short in interface DataInputStream
Overrides:
read_short in interface InputStream

read_short_array

public void read_short_array(ShortSeqHolder holder,
                             int offset,
                             int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_short_array in interface DataInputStream

read_short_array

public void read_short_array(short[] x,
                             int offs,
                             int len)
Read the array of CORBA short integer values.
Overrides:
read_short_array in interface InputStream

read_string

public String read_string()
Read a singe byte string. The method firs reads the byte array and then calls a constructor to create a string from this array. The character encoding, if previously set, is taken into consideration.
Specified by:
read_string in interface DataInputStream
Overrides:
read_string in interface InputStream
Returns:
a loaded string.

read_ulong

public int read_ulong()
Reads the CORBA unsigned long (java int), delegating functionality to read_long().
Specified by:
read_ulong in interface DataInputStream
Overrides:
read_ulong in interface InputStream

read_ulong_array

public void read_ulong_array(int[] x,
                             int offs,
                             int len)
Reads the array of CORBA unsigned long (java integer) values, delegating functionality to AbstractCdrInput.
Overrides:
read_ulong_array in interface InputStream

read_ulong_array

public void read_ulong_array(ULongSeqHolder holder,
                             int offset,
                             int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_ulong_array in interface DataInputStream

read_ulonglong

public long read_ulonglong()
Read the CORBA unsigned long long value, delegating functionality to read_longlong(). There is no way to return values over the limit of the java signed long in other way than returning the negative value.
Specified by:
read_ulonglong in interface DataInputStream
Overrides:
read_ulonglong in interface InputStream

read_ulonglong_array

public void read_ulonglong_array(long[] x,
                                 int offs,
                                 int len)
Reads the array of CORBA long long (java long) values, delegating functionality to AbstractCdrInput.
Overrides:
read_ulonglong_array in interface InputStream

read_ulonglong_array

public void read_ulonglong_array(ULongLongSeqHolder holder,
                                 int offset,
                                 int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_ulonglong_array in interface DataInputStream

read_ushort

public short read_ushort()
Read the unsigned short integer value. Due strange specification, the returned value must be the short type as well, so the the best solution seems just to delegete functionality to read_short.
Specified by:
read_ushort in interface DataInputStream
Overrides:
read_ushort in interface InputStream

read_ushort_array

public void read_ushort_array(UShortSeqHolder holder,
                              int offset,
                              int length)
Specified by:
read_ushort_array in interface DataInputStream

read_ushort_array

public void read_ushort_array(short[] x,
                              int offs,
                              int len)
Read an array of unsigned short values, delegating the functionality to read_short_array.
Overrides:
read_ushort_array in interface InputStream

read_wchar

public char read_wchar()
Reads the wide character using the encoding, specified in the wide_charset.
Specified by:
read_wchar in interface DataInputStream
Overrides:
read_wchar in interface InputStream

read_wchar_array

public void read_wchar_array(char[] x,
                             int offset,
                             int length)
Read an array of "wide chars", each representing a two byte Unicode character, high byte first.
Overrides:
read_wchar_array in interface InputStream

read_wchar_array

public void read_wchar_array(WCharSeqHolder holder,
                             int offset,
                             int length)
Read an array. In OMG specification is written that if the data does not fit into the holder value field, that array must be resized. The implementation follows this rule. If the holder value field contains null, it is newly instantiated.
Specified by:
read_wchar_array in interface DataInputStream

read_wstring

public String read_wstring()
Reads the string in wide character format (ussually UTF-16, Unicode). Takes the currently set charset into consideration. If the native (UTF-16) encoding is used of the GIOP protocol is before 1.2, delegates functionality to "plain" read_wstring_UTF_16().
Specified by:
read_wstring in interface DataInputStream
Overrides:
read_wstring in interface InputStream

read_wstring_UTF_16

public String read_wstring_UTF_16()
Reads first length of the string and the all characters as an Unicode (UTF-16) characters. Mind that GIOP 1.1 has the extra null character at the end that must be discarded.

setBigEndian

public void setBigEndian(boolean use_big_endian)
Set the Big Endian or Little Endian encoding. The stream reads Big Endian by default.
Parameters:
use_big_endian - if true, the stream expect the multi-byte data in the form "most significant byte first" (Big Endian). This is the java standard.

setCodeSet

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

setInputStream

public void setInputStream(InputStream readFrom)
Set the input stream that receives the CORBA input.
Parameters:
readFrom - the stream.

setOffset

public abstract void setOffset(int 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 -

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 .

swap

public static char swap(char x)
Swap bytes in the character.

AbstractCdrInput.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.