ByteOutputStream Class Reference

ByteOutputStream defines an interface for writing to a stream of bytes. More...

#include <ByteOutputStream.h>

Inheritance diagram for ByteOutputStream:

ByteStream ClosableObject ByteArrayOutputStream SegOutputStream SpillOutputStream CrcSegOutputStream List of all members.

Public Member Functions

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.

Protected Member Functions

 ByteOutputStream ()
virtual void flushBuffer (uint cbRequested)=0
 Must be implemented by derived class to flush buffered data.
virtual void closeImpl ()
 Must be implemented by derived class to release any resources.
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 Attributes

PBuffer pNextByte
 Next position to write in output buffer.
uint cbWritable
 Number of writable bytes remaining in output buffer.

Detailed Description

ByteOutputStream defines an interface for writing to a stream of bytes.

Definition at line 35 of file ByteOutputStream.h.


Constructor & Destructor Documentation

ByteOutputStream::ByteOutputStream (  )  [explicit, protected]

Definition at line 29 of file ByteOutputStream.cpp.

References cbWritable, and pNextByte.

00030 {
00031     pNextByte = NULL;
00032     cbWritable = 0;
00033 }


Member Function Documentation

virtual void ByteOutputStream::flushBuffer ( uint  cbRequested  )  [protected, pure 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

Implemented in ByteArrayOutputStream, SegOutputStream, and SpillOutputStream.

Referenced by closeImpl(), getWritePointer(), hardPageBreak(), and writeBytes().

void ByteOutputStream::closeImpl (  )  [protected, virtual]

Must be implemented by derived class to release any resources.

Implements ClosableObject.

Reimplemented in ByteArrayOutputStream, SegOutputStream, and SpillOutputStream.

Definition at line 57 of file ByteOutputStream.cpp.

References flushBuffer().

Referenced by SegOutputStream::closeImpl().

00058 {
00059     flushBuffer(0);
00060 }

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

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 cbWritable, and pNextByte.

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

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

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

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

Definition at line 168 of file ByteOutputStream.h.

References 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 
)

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, cbWritable, flushBuffer(), and 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]

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 cbWritable, flushBuffer(), and 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]

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, cbWritable, and 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 (  ) 

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 cbWritable, flushBuffer(), and pNextByte.

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

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

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 writeLatency.

Referenced by SpillOutputStream::setWriteLatency().

00070 {
00071     writeLatency = writeLatencyInit;
00072 }

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

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 ByteOutputStream::pNextByte [private]

Next position to write in output buffer.

Definition at line 40 of file ByteOutputStream.h.

Referenced by ByteOutputStream(), consumeWritePointer(), getWritePointer(), hardPageBreak(), setBuffer(), and writeBytes().

uint ByteOutputStream::cbWritable [private]

Number of writable bytes remaining in output buffer.

Definition at line 45 of file ByteOutputStream.h.

Referenced by ByteOutputStream(), consumeWritePointer(), getBytesAvailable(), getWritePointer(), hardPageBreak(), setBuffer(), and writeBytes().

WriteLatency ByteOutputStream::writeLatency [protected]

Current write latency mode.

Definition at line 51 of file ByteOutputStream.h.

Referenced by SegOutputStream::flushBuffer(), SegOutputStream::SegOutputStream(), 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(), consumeWritePointer(), ByteStream::getOffset(), SegOutputStream::getSegPos(), SegInputStream::getSegPos(), ByteInputStream::readBytes(), ByteInputStream::reset(), ByteArrayInputStream::resetArray(), ByteInputStream::seekBackward(), SegInputStream::seekSegPos(), and 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