/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// Notes about the class.
// Assumptions, the ByteBuffer's position is set by the constructor's
// index variable and the ByteBuffer's limit points to the end of the
// data. Also, since the index variable tracks the current empty
// position in the buffer, the ByteBuffer's position is updated
// any time there's a call to this class's position().
// Although, a ByteBuffer's length is it's capacity(), the context in
// which length is used in this object, this.buflen is actually the
// ByteBuffer limit().
public class ByteBufferWithInfo
{
private boolean debug;
// REVISIT - index should eventually be replaced with byteBuffer.position()
// REVISIT - CHANGE THESE TO PRIVATE
int index)
{
this.byteBuffer = byteBuffer;
if (byteBuffer != null)
{
}
this.needed = 0;
this.fragmented = false;
}
{
}
{
this(orb, bufferManager, true);
}
// Right now, EncapsOutputStream's do not use pooled byte buffers.
// EncapsOutputStream's is the only one that does not use pooled
// byte buffers. Hence, the reason for the boolean 'usePooledByteBuffers'.
// See EncapsOutputStream for additional information.
boolean usePooledByteBuffers)
{
if (usePooledByteBuffers)
{
if (debug)
{
// print address of ByteBuffer gotten from pool
.append(") from ByteBufferPool.");
}
}
else
{
// don't allocate from pool, allocate non-direct ByteBuffer
}
position(0);
this.buflen = bufferSize;
this.needed = 0;
this.fragmented = false;
}
// Shallow copy constructor
{
}
// So IIOPOutputStream seems more intuitive
public int getSize()
{
return position();
}
// accessor to buflen
public int getLength()
{
return buflen;
}
// get position in this buffer
public int position()
{
// 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;
}
// set position in this buffer
{
// 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().
index = newPosition;
}
// mutator to buflen
{
}
// Grow byteBuffer to a size larger than position() + needed
{
// This code used to live directly in CDROutputStream.grow.
// Recall that the byteBuffer size is 'really' the limit or
// buflen.
if (debug)
{
// print address of ByteBuffer just gotten
}
// return 'old' byteBuffer reference to the ByteBuffer pool
if (debug)
{
// print address of ByteBuffer being released
}
// update the byteBuffer with a larger ByteBuffer
byteBuffer = newBB;
// limit and buflen must be set to newLength.
}
{
}
{
}
}