FileDocCategorySizeDatePackage
ByteBufferWithInfo.javaAPI DocJava SE 5 API8070Fri Aug 26 14:54:20 BST 2005com.sun.corba.se.impl.encoding

ByteBufferWithInfo

public class ByteBufferWithInfo extends Object

Fields Summary
private com.sun.corba.se.spi.orb.ORB
orb
private boolean
debug
private int
index
public ByteBuffer
byteBuffer
public int
buflen
public int
needed
public boolean
fragmented
Constructors Summary
public ByteBufferWithInfo(org.omg.CORBA.ORB orb, ByteBuffer byteBuffer, int index)

        this.orb = (com.sun.corba.se.spi.orb.ORB)orb;
        debug = this.orb.transportDebugFlag;
	this.byteBuffer = byteBuffer;
        if (byteBuffer != null)
        {
            this.buflen = byteBuffer.limit();
        }
        position(index);
	this.needed = 0;
        this.fragmented = false;
    
public ByteBufferWithInfo(org.omg.CORBA.ORB orb, ByteBuffer byteBuffer)

	this(orb, byteBuffer, 0);
    
public ByteBufferWithInfo(org.omg.CORBA.ORB orb, com.sun.corba.se.impl.encoding.BufferManagerWrite bufferManager)

        this(orb, bufferManager, true);
    
public ByteBufferWithInfo(org.omg.CORBA.ORB orb, com.sun.corba.se.impl.encoding.BufferManagerWrite bufferManager, boolean usePooledByteBuffers)

        this.orb = (com.sun.corba.se.spi.orb.ORB)orb;
        debug = this.orb.transportDebugFlag;

        int bufferSize = bufferManager.getBufferSize();

        if (usePooledByteBuffers)
        {
            ByteBufferPool byteBufferPool = this.orb.getByteBufferPool();
            this.byteBuffer = byteBufferPool.getByteBuffer(bufferSize);

            if (debug)
            {
                // print address of ByteBuffer gotten from pool
                int bbAddress = System.identityHashCode(byteBuffer);
                StringBuffer sb = new StringBuffer(80);
                sb.append("constructor (ORB, BufferManagerWrite) - got ")
                  .append("ByteBuffer id (").append(bbAddress)
                  .append(") from ByteBufferPool.");
                String msgStr = sb.toString();
                dprint(msgStr);
            }
        }
        else
        {
             // don't allocate from pool, allocate non-direct ByteBuffer
             this.byteBuffer = ByteBuffer.allocate(bufferSize);
        }

        position(0);
        this.buflen = bufferSize;
        this.byteBuffer.limit(this.buflen);
        this.needed = 0;
        this.fragmented = false;
    
public ByteBufferWithInfo(ByteBufferWithInfo bbwi)

        this.orb = bbwi.orb;
        this.debug = bbwi.debug;
        this.byteBuffer = bbwi.byteBuffer;
        this.buflen = bbwi.buflen;
        this.byteBuffer.limit(this.buflen);
        position(bbwi.position());
        this.needed = bbwi.needed;
        this.fragmented = bbwi.fragmented;
    
Methods Summary
protected voiddprint(java.lang.String msg)

        ORBUtility.dprint("ByteBufferWithInfo", msg);
    
public intgetLength()

         return buflen;
    
public intgetSize()

        return position();
    
public voidgrowBuffer(com.sun.corba.se.spi.orb.ORB orb)

        // This code used to live directly in CDROutputStream.grow.

        // Recall that the byteBuffer size is 'really' the limit or
        // buflen.

        int newLength = byteBuffer.limit() * 2;

        while (position() + needed >= newLength)
            newLength = newLength * 2;

        ByteBufferPool byteBufferPool = orb.getByteBufferPool();
        ByteBuffer newBB = byteBufferPool.getByteBuffer(newLength);

        if (debug)
        {
            // print address of ByteBuffer just gotten
            int newbbAddress = System.identityHashCode(newBB);
            StringBuffer sb = new StringBuffer(80);
            sb.append("growBuffer() - got ByteBuffer id (");
            sb.append(newbbAddress).append(") from ByteBufferPool.");
            String msgStr = sb.toString();
            dprint(msgStr);
        }

        byteBuffer.position(0);
        newBB.put(byteBuffer);

        // return 'old' byteBuffer reference to the ByteBuffer pool
        if (debug)
        {
            // print address of ByteBuffer being released
            int bbAddress = System.identityHashCode(byteBuffer);
            StringBuffer sb = new StringBuffer(80);
            sb.append("growBuffer() - releasing ByteBuffer id (");
            sb.append(bbAddress).append(") to ByteBufferPool.");
            String msgStr2 = sb.toString();
            dprint(msgStr2);
        }
        byteBufferPool.releaseByteBuffer(byteBuffer);

        // update the byteBuffer with a larger ByteBuffer
        byteBuffer = newBB;

        // limit and buflen must be set to newLength.
        buflen = newLength;
        byteBuffer.limit(buflen);
    
public intposition()

        // REVISIT - This should be changed to return the
        //           value of byteBuffer.position() rather
        //           than this.index. But, byteBuffer.position
        //           is manipulated via ByteBuffer writes, reads,
        //           gets and puts. These locations need to be
        //           investigated and updated before
        //           byteBuffer.position() can be returned here.
        // return byteBuffer.position();
        return index;
    
public voidposition(int newPosition)

        // REVISIT - This should be changed to set only the
        //           value of byteBuffer.position rather
        //           than this.index. This change should be made
        //           in conjunction with the change to this.position().
        byteBuffer.position(newPosition);
        index = newPosition;
    
public voidsetLength(int theLength)

        buflen = theLength;
        byteBuffer.limit(buflen);
    
public java.lang.StringtoString()

        StringBuffer str = new StringBuffer("ByteBufferWithInfo:");

        str.append(" buflen = " + buflen);
        str.append(" byteBuffer.limit = " + byteBuffer.limit());
        str.append(" index = " + index);
        str.append(" position = " + position());
        str.append(" needed = " + needed);
        str.append(" byteBuffer = " + (byteBuffer == null ? "null" : "not null"));
        str.append(" fragmented = " + fragmented);

        return str.toString();