summaryrefslogtreecommitdiff
path: root/gnu/CORBA/CDR/cdrInput.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/CORBA/CDR/cdrInput.java')
-rw-r--r--gnu/CORBA/CDR/cdrInput.java183
1 files changed, 140 insertions, 43 deletions
diff --git a/gnu/CORBA/CDR/cdrInput.java b/gnu/CORBA/CDR/cdrInput.java
index 03be3363b..644e01930 100644
--- a/gnu/CORBA/CDR/cdrInput.java
+++ b/gnu/CORBA/CDR/cdrInput.java
@@ -62,6 +62,7 @@ import org.omg.CORBA.TypeCodePackage.Bounds;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.ObjectImpl;
+import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
@@ -93,7 +94,13 @@ public abstract class cdrInput
* This instance is used to convert primitive data types into the
* byte sequences.
*/
- protected DataInputStream b;
+ protected abstractDataInputStream b;
+
+ /**
+ * The input stream, from where the data are actually
+ * being read.
+ */
+ protected java.io.InputStream actual_stream;
/**
* The associated orb, if any.
@@ -137,7 +144,16 @@ public abstract class cdrInput
private boolean wide_native;
/**
- * Creates the stream.
+ * If true, the stream expect
+ * the multi-byte data in the form "less significant byte
+ * first" (Little Endian). This is the opposite to the
+ * java standard (Big Endian).
+ */
+ private boolean little_endian;
+
+ /**
+ * Creates the stream. The stream reads Big Endian by
+ * default.
*
* @param readFrom a stream to read CORBA input from.
*/
@@ -157,13 +173,33 @@ public abstract class cdrInput
}
/**
+ * Set the Big Endian or Little Endian encoding.
+ * The stream reads Big Endian by default.
+ *
+ * @param use_little_endian if true, the stream expect
+ * the multi-byte data in the form "less significant byte
+ * first" (Little Endian). This is the opposite to the
+ * java standard (Big Endian).
+ */
+ public void setBigEndian(boolean use_big_endian)
+ {
+ little_endian = !use_big_endian;
+ setInputStream(actual_stream);
+ }
+
+ /**
* Set the input stream that receives the CORBA input.
*
* @param readFrom the stream.
*/
public void setInputStream(java.io.InputStream readFrom)
{
- b = new DataInputStream(readFrom);
+ if (little_endian)
+ b = new LittleEndianInputStream(readFrom);
+ else
+ b = new BigEndianInputStream(readFrom);
+
+ actual_stream = readFrom;
}
/**
@@ -209,7 +245,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
{
@@ -230,7 +268,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -260,7 +300,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
}
@@ -276,7 +318,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
}
@@ -292,7 +336,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
}
@@ -344,7 +390,9 @@ public abstract class cdrInput
}
catch (IOException ex)
{
- throw new BAD_OPERATION(ex.toString());
+ BAD_OPERATION bad = new BAD_OPERATION();
+ bad.initCause(ex);
+ throw bad;
}
}
@@ -394,7 +442,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
{
@@ -416,7 +466,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -436,11 +488,13 @@ public abstract class cdrInput
if (narrow_native)
return (char) b.read();
else
- return (char) new InputStreamReader(b, narrow_charset).read();
+ return (char) new InputStreamReader((InputStream) b, narrow_charset).read();
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -463,13 +517,16 @@ public abstract class cdrInput
}
else
{
- InputStreamReader reader = new InputStreamReader(b, narrow_charset);
+ InputStreamReader reader =
+ new InputStreamReader((InputStream) b, narrow_charset);
reader.read(x, offset, length);
}
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -490,7 +547,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -514,7 +573,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -524,8 +585,10 @@ public abstract class cdrInput
}
/**
- * Read the encapsulated stream. The endian flag is already extracted from
- * the returned stream.
+ * 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.
*/
public cdrBufInput read_encapsulation()
{
@@ -538,7 +601,7 @@ public abstract class cdrInput
reading:
while (n < r.length)
{
- n = read(r, n, r.length - n);
+ n += read(r, n, r.length - n);
}
cdrBufInput capsule = new cdrBufInput(r);
@@ -546,17 +609,18 @@ public abstract class cdrInput
int endian = capsule.read_octet();
- // TODO FIXME implement little endian.
if (endian != 0)
{
- throw new NO_IMPLEMENT("Little endian not supported.");
+ capsule.setBigEndian(false);
}
return capsule;
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -578,7 +642,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -599,7 +665,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -623,7 +691,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -644,7 +714,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -668,7 +740,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -713,7 +787,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -733,7 +809,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -753,7 +831,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -780,7 +860,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -801,7 +883,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -825,7 +909,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -860,7 +946,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -944,11 +1032,13 @@ public abstract class cdrInput
if (wide_native)
return (char) b.readShort();
else
- return (char) new InputStreamReader(b, wide_charset).read();
+ return (char) new InputStreamReader((InputStream) b, wide_charset).read();
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
{
@@ -974,13 +1064,16 @@ public abstract class cdrInput
}
else
{
- InputStreamReader reader = new InputStreamReader(b, wide_charset);
+ InputStreamReader reader =
+ new InputStreamReader((InputStream) b, wide_charset);
reader.read(x, offset, length);
}
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -1001,7 +1094,7 @@ public abstract class cdrInput
public String read_wstring()
{
// Native encoding or word oriented data.
- if (wide_charset == null || giop.until_inclusive(1, 1))
+ if (wide_native || giop.until_inclusive(1, 1))
return read_wstring_UTF_16();
try
{
@@ -1015,7 +1108,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -1069,7 +1164,9 @@ public abstract class cdrInput
}
catch (EOFException ex)
{
- throw new MARSHAL(UNEXP_EOF);
+ MARSHAL t = new MARSHAL(UNEXP_EOF);
+ t.initCause(ex);
+ throw t;
}
catch (IOException ex)
@@ -1126,4 +1223,4 @@ public abstract class cdrInput
{
return read_Object();
}
-}
+} \ No newline at end of file