summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/BasicStream.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-03-24 11:45:18 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-03-24 11:45:18 +0100
commit06a08ecf28e205277336a97a6173db7ccbed1adc (patch)
treea369a5044a63f8cdba9e7c0a461e24ae344486b4 /java/src/IceInternal/BasicStream.java
parentMerge branch 'R3_3_branch' (diff)
parentBug 3924: slice2py missing from VC60 installer (diff)
downloadice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.bz2
ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.xz
ice-06a08ecf28e205277336a97a6173db7ccbed1adc.zip
Merge commit 'origin/R3_3_branch'
Conflicts: CHANGES cpp/demo/Freeze/backup/.depend cpp/demo/Freeze/bench/.depend cpp/demo/Freeze/casino/.depend cpp/demo/Freeze/customEvictor/.depend cpp/demo/Freeze/library/.depend cpp/demo/Freeze/phonebook/.depend cpp/demo/Freeze/transform/.depend cpp/demo/Glacier2/callback/.depend cpp/demo/Glacier2/chat/.depend cpp/demo/Ice/async/.depend cpp/demo/Ice/bidir/.depend cpp/demo/Ice/callback/.depend cpp/demo/Ice/converter/.depend cpp/demo/Ice/hello/.depend cpp/demo/Ice/invoke/.depend cpp/demo/Ice/latency/.depend cpp/demo/Ice/minimal/.depend cpp/demo/Ice/multicast/.depend cpp/demo/Ice/nested/.depend cpp/demo/Ice/nrvo/.depend cpp/demo/Ice/session/.depend cpp/demo/Ice/throughput/.depend cpp/demo/Ice/value/.depend cpp/demo/IceBox/hello/.depend cpp/demo/IceGrid/allocate/.depend cpp/demo/IceGrid/icebox/.depend cpp/demo/IceGrid/replication/.depend cpp/demo/IceGrid/sessionActivation/.depend cpp/demo/IceGrid/simple/.depend cpp/demo/IceStorm/clock/.depend cpp/demo/IceStorm/counter/.depend cpp/demo/IceStorm/replicated/.depend cpp/demo/IceStorm/replicated2/.depend cpp/demo/book/freeze_filesystem/.depend cpp/demo/book/lifecycle/.depend cpp/demo/book/printer/.depend cpp/demo/book/simple_filesystem/.depend cpp/src/Freeze/.depend cpp/src/FreezeScript/.depend cpp/src/Ice/.depend cpp/src/Ice/UdpTransceiver.cpp cpp/src/Ice/UdpTransceiver.h cpp/src/IceBox/.depend cpp/src/IceGrid/.depend cpp/src/IceGridLib/.depend cpp/src/IcePatch2/.depend cpp/src/IceStorm/.depend cpp/src/slice2freeze/.depend cpp/test/Freeze/complex/.depend cpp/test/Freeze/dbmap/.depend cpp/test/Freeze/evictor/.depend cpp/test/Freeze/oldevictor/.depend cpp/test/FreezeScript/dbmap/.depend cpp/test/FreezeScript/evictor/.depend cpp/test/Glacier2/attack/.depend cpp/test/Glacier2/dynamicFiltering/.depend cpp/test/Glacier2/router/.depend cpp/test/Glacier2/sessionControl/.depend cpp/test/Glacier2/ssl/.depend cpp/test/Glacier2/staticFiltering/.depend cpp/test/Ice/adapterDeactivation/.depend cpp/test/Ice/background/.depend cpp/test/Ice/binding/.depend cpp/test/Ice/checksum/.depend cpp/test/Ice/checksum/server/.depend cpp/test/Ice/custom/.depend cpp/test/Ice/exceptions/.depend cpp/test/Ice/facets/.depend cpp/test/Ice/faultTolerance/.depend cpp/test/Ice/gc/.depend cpp/test/Ice/hold/.depend cpp/test/Ice/inheritance/.depend cpp/test/Ice/interceptor/.depend cpp/test/Ice/location/.depend cpp/test/Ice/objects/.depend cpp/test/Ice/operations/.depend cpp/test/Ice/proxy/.depend cpp/test/Ice/retry/.depend cpp/test/Ice/servantLocator/.depend cpp/test/Ice/slicing/exceptions/.depend cpp/test/Ice/slicing/objects/.depend cpp/test/Ice/stream/.depend cpp/test/Ice/stringConverter/.depend cpp/test/Ice/timeout/.depend cpp/test/Ice/udp/.depend cpp/test/IceBox/configuration/.depend cpp/test/IceGrid/activation/.depend cpp/test/IceGrid/allocation/.depend cpp/test/IceGrid/deployer/.depend cpp/test/IceGrid/distribution/.depend cpp/test/IceGrid/replicaGroup/.depend cpp/test/IceGrid/replication/.depend cpp/test/IceGrid/session/.depend cpp/test/IceGrid/simple/.depend cpp/test/IceGrid/update/.depend cpp/test/IceSSL/configuration/.depend cpp/test/IceStorm/federation/.depend cpp/test/IceStorm/federation2/.depend cpp/test/IceStorm/rep1/.depend cpp/test/IceStorm/repgrid/.depend cpp/test/IceStorm/repstress/.depend cpp/test/IceStorm/single/.depend cpp/test/IceStorm/stress/.depend cpp/test/Slice/keyword/.depend cs/src/Ice/Instance.cs cs/src/IceSSL/ConnectorI.cs java/demo/book/simple_filesystem/Filesystem/DirectoryI.java java/demo/book/simple_filesystem/Filesystem/FileI.java java/src/IceInternal/TcpConnector.java java/src/IceSSL/ConnectorI.java py/modules/IcePy/.depend rb/src/IceRuby/.depend
Diffstat (limited to 'java/src/IceInternal/BasicStream.java')
-rw-r--r--java/src/IceInternal/BasicStream.java186
1 files changed, 150 insertions, 36 deletions
diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java
index ae39f1055bb..9be9e9e533c 100644
--- a/java/src/IceInternal/BasicStream.java
+++ b/java/src/IceInternal/BasicStream.java
@@ -367,6 +367,17 @@ public class BasicStream
}
public void
+ endWriteEncapsChecked() // Used by public stream API.
+ {
+ if(_writeEncapsStack == null)
+ {
+ throw new Ice.EncapsulationException("not in an encapsulation");
+ }
+
+ endWriteEncaps();
+ }
+
+ public void
startReadEncaps()
{
{
@@ -478,6 +489,17 @@ public class BasicStream
}
}
+ public void
+ endReadEncapsChecked() // Used by public stream API.
+ {
+ if(_readEncapsStack == null)
+ {
+ throw new Ice.EncapsulationException("not in an encapsulation");
+ }
+
+ endReadEncaps();
+ }
+
public int
getReadEncapsSize()
{
@@ -592,6 +614,14 @@ public class BasicStream
public void
writeTypeId(String id)
{
+ if(_writeEncapsStack == null || _writeEncapsStack.typeIdMap == null)
+ {
+ //
+ // writeObject() must be called first.
+ //
+ throw new Ice.MarshalException("type ids require an encapsulation");
+ }
+
Integer index = _writeEncapsStack.typeIdMap.get(id);
if(index != null)
{
@@ -610,6 +640,14 @@ public class BasicStream
public String
readTypeId()
{
+ if(_readEncapsStack == null || _readEncapsStack.typeIdMap == null)
+ {
+ //
+ // readObject() must be called first.
+ //
+ throw new Ice.MarshalException("type ids require an encapsulation");
+ }
+
String id;
Integer index;
final boolean isIndex = readBool();
@@ -692,6 +730,28 @@ public class BasicStream
}
}
+ public void
+ writeSerializable(java.io.Serializable o)
+ {
+ if(o == null)
+ {
+ writeSize(0);
+ return;
+ }
+ try
+ {
+ OutputStreamWrapper w = new OutputStreamWrapper(this);
+ java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(w);
+ out.writeObject(o);
+ out.close();
+ w.close();
+ }
+ catch(java.lang.Exception ex)
+ {
+ throw new Ice.MarshalException("cannot serialize object: " + ex);
+ }
+ }
+
public byte
readByte()
{
@@ -733,6 +793,27 @@ public class BasicStream
}
}
+ public java.io.Serializable
+ readSerializable()
+ {
+ int sz = readSize();
+ if (sz == 0)
+ {
+ return null;
+ }
+ checkFixedSeq(sz, 1);
+ try
+ {
+ InputStreamWrapper w = new InputStreamWrapper(sz, this);
+ java.io.ObjectInputStream in = new java.io.ObjectInputStream(w);
+ return (java.io.Serializable)in.readObject();
+ }
+ catch(java.lang.Exception ex)
+ {
+ throw new Ice.MarshalException("cannot deserialize object: " + ex);
+ }
+ }
+
public void
writeBool(boolean v)
{
@@ -1377,33 +1458,40 @@ public class BasicStream
int index = readInt();
- if(index == 0)
+ if(patcher != null)
{
- patcher.patch(null);
- return;
- }
+ if(index == 0)
+ {
+ patcher.patch(null);
+ return;
+ }
- if(index < 0 && patcher != null)
- {
- Integer i = new Integer(-index);
- java.util.LinkedList<Patcher> patchlist = _readEncapsStack.patchMap.get(i);
- if(patchlist == null)
+ if(index < 0)
{
+ Integer i = new Integer(-index);
+ java.util.LinkedList<Patcher> patchlist = _readEncapsStack.patchMap.get(i);
+ if(patchlist == null)
+ {
+ //
+ // We have no outstanding instances to be patched for
+ // this index, so make a new entry in the patch map.
+ //
+ patchlist = new java.util.LinkedList<Patcher>();
+ _readEncapsStack.patchMap.put(i, patchlist);
+ }
//
- // We have no outstanding instances to be patched for
- // this index, so make a new entry in the patch map.
+ // Append a patcher for this instance and see if we can
+ // patch the instance. (The instance may have been
+ // unmarshaled previously.)
//
- patchlist = new java.util.LinkedList<Patcher>();
- _readEncapsStack.patchMap.put(i, patchlist);
+ patchlist.add(patcher);
+ patchReferences(null, i);
+ return;
}
- //
- // Append a patcher for this instance and see if we can
- // patch the instance. (The instance may have been
- // unmarshaled previously.)
- //
- patchlist.add(patcher);
- patchReferences(null, i);
- return;
+ }
+ if(index < 0)
+ {
+ throw new Ice.MarshalException("Invalid class instance index");
}
String mostDerivedId = readTypeId();
@@ -1523,6 +1611,7 @@ public class BasicStream
boolean usesClasses = readBool();
String id = readString();
+ final String origId = id;
for(;;)
{
@@ -1567,8 +1656,24 @@ public class BasicStream
{
TraceUtil.traceSlicing("exception", id, _slicingCat, _instance.initializationData().logger);
}
+
skipSlice(); // Slice off what we don't understand.
- id = readString(); // Read type id for next slice.
+
+ try
+ {
+ id = readString(); // Read type id for next slice.
+ }
+ catch(Ice.UnmarshalOutOfBoundsException ex)
+ {
+ //
+ // When readString raises this exception it means we've seen the last slice,
+ // so we set the reason member to a more helpful message.
+ //
+ Ice.UnmarshalOutOfBoundsException e = new Ice.UnmarshalOutOfBoundsException();
+ e.reason = "unknown exception type `" + origId + "'";
+ e.initCause(ex);
+ throw e;
+ }
}
}
@@ -1636,6 +1741,15 @@ public class BasicStream
}
while(num > 0);
+ if(_readEncapsStack != null && _readEncapsStack.patchMap != null && _readEncapsStack.patchMap.size() != 0)
+ {
+ //
+ // If any entries remain in the patch map, the sender has sent an index for an object, but failed
+ // to supply the object.
+ //
+ throw new Ice.MarshalException("Index for class received, but no instance");
+ }
+
//
// Iterate over unmarshaledMap and invoke ice_postUnmarshal on
// each object. We must do this after all objects in this
@@ -2023,7 +2137,7 @@ public class BasicStream
return ucStream;
}
- private void
+ public void
expand(int n)
{
if(!_unlimited && _buf.b != null && _buf.b.position() + n > _messageSizeMax)
@@ -2035,7 +2149,7 @@ public class BasicStream
private static final class DynamicObjectFactory implements Ice.ObjectFactory
{
- DynamicObjectFactory(Class c)
+ DynamicObjectFactory(Class<?> c)
{
_class = c;
}
@@ -2060,7 +2174,7 @@ public class BasicStream
{
}
- private Class _class;
+ private Class<?> _class;
}
private Ice.ObjectFactory
@@ -2070,7 +2184,7 @@ public class BasicStream
try
{
- Class c = findClass(id);
+ Class<?> c = findClass(id);
if(c != null)
{
Ice.ObjectFactory dynamicFactory = new DynamicObjectFactory(c);
@@ -2115,7 +2229,7 @@ public class BasicStream
private static final class DynamicUserExceptionFactory
implements UserExceptionFactory
{
- DynamicUserExceptionFactory(Class c)
+ DynamicUserExceptionFactory(Class<?> c)
{
_class = c;
}
@@ -2145,7 +2259,7 @@ public class BasicStream
{
}
- private Class _class;
+ private Class<?> _class;
}
private UserExceptionFactory
@@ -2162,7 +2276,7 @@ public class BasicStream
{
try
{
- Class c = findClass(id);
+ Class<?> c = findClass(id);
if(c != null)
{
factory = new DynamicUserExceptionFactory(c);
@@ -2187,11 +2301,11 @@ public class BasicStream
return factory;
}
- private Class
+ private Class<?>
findClass(String id)
throws LinkageError
{
- Class c = null;
+ Class<?> c = null;
//
// To convert a Slice type id into a Java class, we do the following:
@@ -2231,13 +2345,13 @@ public class BasicStream
return c;
}
- private Class
+ private Class<?>
getConcreteClass(String className)
throws LinkageError
{
try
{
- Class c = Class.forName(className);
+ Class<?> c = Class.forName(className);
//
// Ensure the class is instantiable. The constants are
// defined in the JVM specification (0x200 = interface,
@@ -2289,7 +2403,7 @@ public class BasicStream
throw new Ice.MarshalException();
}
- StringBuffer buf = new StringBuffer(id.length());
+ StringBuilder buf = new StringBuilder(id.length());
int start = 2;
boolean done = false;
@@ -2417,8 +2531,8 @@ public class BasicStream
return _bzInputStreamCtor != null && _bzOutputStreamCtor != null;
}
- private static java.lang.reflect.Constructor _bzInputStreamCtor;
- private static java.lang.reflect.Constructor _bzOutputStreamCtor;
+ private static java.lang.reflect.Constructor<?> _bzInputStreamCtor;
+ private static java.lang.reflect.Constructor<?> _bzOutputStreamCtor;
static
{
try