diff --git a/src/org/jacorb/orb/CDROutputStream.java b/src/org/jacorb/orb/CDROutputStream.java index 644c8c3..4951226 100644 --- a/src/org/jacorb/orb/CDROutputStream.java +++ b/src/org/jacorb/orb/CDROutputStream.java @@ -78,7 +78,7 @@ public class CDROutputStream size, but that have not yet been written */ private int deferred_writes; - private final IBufferManager bufMgr; + private IBufferManager bufMgr; protected byte[] buffer; private boolean closed; @@ -156,7 +156,7 @@ public class CDROutputStream private int deferredArrayQueueSize; - protected final org.jacorb.orb.ORBSingleton orb; + protected org.jacorb.orb.ORBSingleton orb; protected int giop_minor = 2; @@ -184,7 +184,7 @@ public class CDROutputStream // by default stream version is 1 for GIOP v1.2 messages private byte maxStreamFormatVersion = ValueHandler.STREAM_FORMAT_VERSION_1; - private final TypeCodeCompactor typeCodeCompactor; + private TypeCodeCompactor typeCodeCompactor; private final static DelegatingTypeCodeWriter typeCodeWriter = new DelegatingTypeCodeWriter(); @@ -208,23 +208,18 @@ public class CDROutputStream } /** - * internal c'tor + * size selecting c'tor * @param orb must be a JacORB ORB * @param bufferSize -1 to fetch the default buffer size, * value > 0 to specify a specific size + * @param no_deferred true overrides the configured deferred writes bhavior + * and forces all date into the single buffer while marshalling */ - private CDROutputStream(org.omg.CORBA.ORB orb, int bufferSize) + public CDROutputStream(org.omg.CORBA.ORB orb, int bufferSize, boolean no_deferred) { super(); - if (! (orb instanceof ORBSingleton)) - { - throw new BAD_PARAM("don't pass in a non JacORB ORB"); - } - - this.orb = (ORBSingleton) orb; - bufMgr = this.orb.getBufferManager(); - typeCodeCompactor = this.orb.getTypeCodeCompactor(); + shared_init (orb, no_deferred); if (bufferSize == -1) { @@ -234,7 +229,24 @@ public class CDROutputStream { buffer = bufMgr.getBuffer(bufferSize); } + + } + + /** + * buffer supplying c'tor + * @param orb must be a JacORB ORB + * @param bufferSize -1 to fetch the default buffer size, + * value > 0 to specify a specific size + * @param no_deferred true overrides the configured deferred writes bhavior + * and forces all date into the single buffer while marshalling + */ + public CDROutputStream(org.omg.CORBA.ORB orb, byte [] extbuff ) + { + super(); + shared_init (orb, true); + this.buffer = extbuff; } + /** * OutputStreams created using this constructor * are used also for in memory marshaling, but do use the @@ -242,16 +254,7 @@ public class CDROutputStream */ public CDROutputStream(final org.omg.CORBA.ORB orb) { - this(orb, -1); - - try - { - configure(((ORBSingleton)orb).getConfiguration()); - } - catch(ConfigurationException e) - { - throw new INTERNAL(e.getMessage()); - } + this(orb, -1, false); } /** @@ -271,6 +274,31 @@ public class CDROutputStream } + private void shared_init (org.omg.CORBA.ORB orb, boolean no_deferred) + { + if (! (orb instanceof ORBSingleton)) + { + throw new BAD_PARAM("don't pass in a non JacORB ORB"); + } + + this.orb = (ORBSingleton) orb; + bufMgr = this.orb.getBufferManager(); + typeCodeCompactor = this.orb.getTypeCodeCompactor(); + + try + { + configure(((ORBSingleton)orb).getConfiguration()); + } + catch(ConfigurationException e) + { + throw new INTERNAL(e.getMessage()); + } + + if (no_deferred) + { + deferredArrayQueueSize = 0; + } + } /** * This stream is self-configuring, i.e. configure() is private @@ -711,6 +739,21 @@ public class CDROutputStream index = 0; } + /** + * Give up the buffer to the caller. It is up to the caller to + * eventually return the buffer to the manager, if appropriate. + */ + + public byte[] releaseBuffer () + { + byte [] retn = buffer; + buffer = null; + deferredArrayQueue = null; + pos = 0; + deferred_writes = 0; + index = 0; + return retn; + } /************************************************** * The following operations are from OutputStream *