ByteArrayOutputStream Class Reference

ByteArrayOutputStream implements the ByteOutputStream interface by writing data to an existing fixed-size array of bytes. More...

#include <ByteArrayOutputStream.h>

Inheritance diagram for ByteArrayOutputStream:

ByteOutputStream ByteStream ClosableObject List of all members.

Public Member Functions

void clear ()
 Clears any data written to the buffer, leaving it in the same state as after construction.
void writeBytes (void const *pData, uint cbRequested)
 Writes bytes to the stream.
PBuffer getWritePointer (uint cbRequested, uint *pcbActual=NULL)
 Copyless alternative for writing bytes to the stream.
void consumeWritePointer (uint cbUsed)
 Advances stream position after a call to getWritePointer.
void hardPageBreak ()
 Marks the current buffer as complete regardless of how much data it contains.
virtual void setWriteLatency (WriteLatency writeLatency)
 Changes the write latency.
template<class T>
void writeValue (T const &value)
 Writes a fixed-size type to the stream.
FileSize getOffset () const
 
Returns:
current offset from beginning of stream

bool isClosed () const
 
Returns:
whether the object has been closed

void close ()
 Closes this object, releasing any unallocated resources.

Static Public Member Functions

static SharedByteArrayOutputStream newByteArrayOutputStream (PBuffer pBuffer, uint cbBuffer)
 Creates a new ByteArrayOutputStream.

Protected Member Functions

void setBuffer (PBuffer pBuffer, uint cbBuffer)
 Sets the current buffer to be written.
uint getBytesAvailable () const
 
Returns:
number of bytes remaining to be written in current buffer


Protected Attributes

WriteLatency writeLatency
 Current write latency mode.
FileSize cbOffset
 Byte position in stream.
bool needsClose

Private Member Functions

virtual void flushBuffer (uint cbRequested)
 Must be implemented by derived class to flush buffered data.
virtual void closeImpl ()
 Must be implemented by derived class to release any resources.
 ByteArrayOutputStream (PBuffer pBuffer, uint cbBuffer)

Private Attributes

PBuffer pBuffer
uint cbBuffer

Detailed Description

ByteArrayOutputStream implements the ByteOutputStream interface by writing data to an existing fixed-size array of bytes.

Definition at line 35 of file ByteArrayOutputStream.h.


Constructor & Destructor Documentation

ByteArrayOutputStream::ByteArrayOutputStream ( PBuffer  pBuffer,
uint  cbBuffer 
) [explicit, private]

Definition at line 38 of file ByteArrayOutputStream.cpp.

References cbBuffer, pBuffer, and ByteOutputStream::setBuffer().

Referenced by newByteArrayOutputStream().

00041 {
00042     pBuffer = pBufferInit;
00043     cbBuffer = cbBufferInit;
00044     setBuffer(pBuffer,cbBuffer);
00045 }


Member Function Documentation

void ByteArrayOutputStream::flushBuffer ( uint  cbRequested  )  [private, virtual]

Must be implemented by derived class to flush buffered data.

Parameters:
cbRequested if non-zero, the derived class should allocate a new buffer with at least the requested size and call setBuffer

Implements ByteOutputStream.

Definition at line 47 of file ByteArrayOutputStream.cpp.

00048 {
00049     permAssert(false);
00050 }

void ByteArrayOutputStream::closeImpl (  )  [private, virtual]

Must be implemented by derived class to release any resources.

Reimplemented from ByteOutputStream.

Definition at line 52 of file ByteArrayOutputStream.cpp.

00053 {
00054     // nothing to do
00055 }

SharedByteArrayOutputStream ByteArrayOutputStream::newByteArrayOutputStream ( PBuffer  pBuffer,
uint  cbBuffer 
) [static]

Creates a new ByteArrayOutputStream.

Parameters:
pBuffer byte array to fill
cbBuffer buffer capacity
Returns:
shared_ptr to new ByteArrayOutputStream

Definition at line 29 of file ByteArrayOutputStream.cpp.

References ByteArrayOutputStream().

void ByteArrayOutputStream::clear (  ) 

Clears any data written to the buffer, leaving it in the same state as after construction.

Definition at line 57 of file ByteArrayOutputStream.cpp.

References cbBuffer, pBuffer, and ByteOutputStream::setBuffer().

00058 {
00059     setBuffer(pBuffer,cbBuffer);
00060 }

void ByteOutputStream::setBuffer ( PBuffer  pBuffer,
uint  cbBuffer 
) [inline, protected, inherited]

Sets the current buffer to be written.

Parameters:
pBuffer receives start address of new buffer
cbBuffer number of bytes in buffer

Definition at line 162 of file ByteOutputStream.h.

References ByteOutputStream::cbWritable, and ByteOutputStream::pNextByte.

Referenced by ByteArrayOutputStream(), clear(), SpillOutputStream::flushBuffer(), SegOutputStream::flushBuffer(), and SpillOutputStream::SpillOutputStream().

00163 {
00164     pNextByte = pBuffer;
00165     cbWritable = cbBuffer;
00166 }

uint ByteOutputStream::getBytesAvailable (  )  const [inline, protected, inherited]

Returns:
number of bytes remaining to be written in current buffer

Definition at line 168 of file ByteOutputStream.h.

References ByteOutputStream::cbWritable.

Referenced by SpillOutputStream::closeImpl(), SpillOutputStream::flushBuffer(), SegOutputStream::getBytesWrittenThisPage(), SegOutputStream::getSegPos(), SpillOutputStream::spill(), and SpillOutputStream::updatePage().

00169 {
00170     return cbWritable;
00171 }

void ByteOutputStream::writeBytes ( void const *  pData,
uint  cbRequested 
) [inherited]

Writes bytes to the stream.

Parameters:
pData source buffer containing bytes to be written
cbRequested number of bytes to write

Definition at line 35 of file ByteOutputStream.cpp.

References ByteStream::cbOffset, ByteOutputStream::cbWritable, ByteOutputStream::flushBuffer(), and ByteOutputStream::pNextByte.

Referenced by FtrsTableWriter::execute().

00036 {
00037     cbOffset += cb;
00038     if (!cbWritable) {
00039         flushBuffer(1);
00040     }
00041     for (;;) {
00042         assert(cbWritable);
00043         if (cb <= cbWritable) {
00044             memcpy(pNextByte,pData,cb);
00045             cbWritable -= cb;
00046             pNextByte += cb;
00047             return;
00048         }
00049         memcpy(pNextByte,pData,cbWritable);
00050         pData = static_cast<char const *>(pData) + cbWritable;
00051         cb -= cbWritable;
00052         cbWritable = 0;
00053         flushBuffer(1);
00054     }
00055 }

PBuffer ByteOutputStream::getWritePointer ( uint  cbRequested,
uint pcbActual = NULL 
) [inline, inherited]

Copyless alternative for writing bytes to the stream.

Provides direct access to the stream's internal buffer, but doesn't move the stream position (see consumeWritePointer).

Parameters:
cbRequested number of contiguous bytes to access; if fewer bytes are currently available in the buffer, the buffer is flushed and a new buffer is returned
pcbActual if non-NULL, receives actual number of contiguous writable bytes, which will always be greater than or equal to cbRequested
Returns:
pointer to cbActual bytes of writable buffer space

Definition at line 141 of file ByteOutputStream.h.

References ByteOutputStream::cbWritable, ByteOutputStream::flushBuffer(), and ByteOutputStream::pNextByte.

Referenced by BTreeWriter::deleteCurrent(), BTreeWriter::insertTupleFromBuffer(), and SegOutputStream::SegOutputStream().

00143 {
00144     if (cbWritable < cbRequested) {
00145         flushBuffer(cbRequested);
00146         assert(cbWritable >= cbRequested);
00147     }
00148     if (pcbActual) {
00149         *pcbActual = cbWritable;
00150     }
00151     return pNextByte;
00152 }

void ByteOutputStream::consumeWritePointer ( uint  cbUsed  )  [inline, inherited]

Advances stream position after a call to getWritePointer.

Parameters:
cbUsed number of bytes to advance; must be less than or equal to the value of cbActual returned by the last call to getWritePointer

Definition at line 154 of file ByteOutputStream.h.

References ByteStream::cbOffset, ByteOutputStream::cbWritable, and ByteOutputStream::pNextByte.

Referenced by BTreeWriter::deleteCurrent(), and BTreeWriter::insertTupleFromBuffer().

00155 {
00156     assert(cbUsed <= cbWritable);
00157     cbWritable -= cbUsed;
00158     pNextByte += cbUsed;
00159     cbOffset += cbUsed;
00160 }

void ByteOutputStream::hardPageBreak (  )  [inherited]

Marks the current buffer as complete regardless of how much data it contains.

The exact semantics are dependent on the buffering implementation.

Definition at line 62 of file ByteOutputStream.cpp.

References ByteOutputStream::cbWritable, ByteOutputStream::flushBuffer(), and ByteOutputStream::pNextByte.

00063 {
00064     flushBuffer(0);
00065     cbWritable = 0;
00066     pNextByte = NULL;
00067 }

void ByteOutputStream::setWriteLatency ( WriteLatency  writeLatency  )  [virtual, inherited]

Changes the write latency.

May not be meaningful for all stream implementations.

Parameters:
writeLatency new WriteLatency setting

Reimplemented in SpillOutputStream.

Definition at line 69 of file ByteOutputStream.cpp.

References ByteOutputStream::writeLatency.

Referenced by SpillOutputStream::setWriteLatency().

00070 {
00071     writeLatency = writeLatencyInit;
00072 }

template<class T>
void ByteOutputStream::writeValue ( T const &  value  )  [inline, inherited]

Writes a fixed-size type to the stream.

Parameters:
value value to read; type must be memcpy-safe

Definition at line 135 of file ByteOutputStream.h.

Referenced by FtrsTableWriter::describeIndex(), LogicalTxnTest::describeParticipant(), FtrsTableWriter::describeParticipant(), BTreeWriter::describeParticipant(), DatabaseTest::executeIncrementAction(), TupleProjection::writePersistent(), and TupleDescriptor::writePersistent().

00136     {
00137         writeBytes(&value,sizeof(value));
00138     }

FileSize ByteStream::getOffset (  )  const [inline, inherited]

Returns:
current offset from beginning of stream

Definition at line 110 of file ByteStream.h.

References ByteStream::cbOffset.

Referenced by SpillOutputStream::getInputStream(), and ByteInputStream::mark().

00111 {
00112     return cbOffset;
00113 }

bool ClosableObject::isClosed (  )  const [inline, inherited]

Returns:
whether the object has been closed

Definition at line 58 of file ClosableObject.h.

00059     {
00060         return !needsClose;
00061     }

void ClosableObject::close (  )  [inherited]

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

References ClosableObject::closeImpl(), and ClosableObject::needsClose.

Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().

00040 {
00041     if (!needsClose) {
00042         return;
00043     }
00044     needsClose = false;
00045     closeImpl();
00046 }


Member Data Documentation

PBuffer ByteArrayOutputStream::pBuffer [private]

Definition at line 37 of file ByteArrayOutputStream.h.

Referenced by ByteArrayOutputStream(), and clear().

uint ByteArrayOutputStream::cbBuffer [private]

Definition at line 38 of file ByteArrayOutputStream.h.

Referenced by ByteArrayOutputStream(), and clear().

WriteLatency ByteOutputStream::writeLatency [protected, inherited]

Current write latency mode.

Definition at line 51 of file ByteOutputStream.h.

Referenced by SegOutputStream::flushBuffer(), SegOutputStream::SegOutputStream(), ByteOutputStream::setWriteLatency(), and SpillOutputStream::spill().

FileSize ByteStream::cbOffset [protected, inherited]

Byte position in stream.

Definition at line 41 of file ByteStream.h.

Referenced by ByteStream::ByteStream(), ByteInputStream::consumeReadPointer(), ByteOutputStream::consumeWritePointer(), ByteStream::getOffset(), SegOutputStream::getSegPos(), SegInputStream::getSegPos(), ByteInputStream::readBytes(), ByteInputStream::reset(), ByteArrayInputStream::resetArray(), ByteInputStream::seekBackward(), SegInputStream::seekSegPos(), and ByteOutputStream::writeBytes().

bool ClosableObject::needsClose [protected, inherited]

Definition at line 44 of file ClosableObject.h.

Referenced by SegStreamAllocation::beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:26 2009 for Fennel by  doxygen 1.5.1