#include <ByteArrayOutputStream.h>
Inheritance diagram for ByteArrayOutputStream:
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 |
| |
bool | isClosed () const |
| |
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 |
| |
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 |
Definition at line 35 of file ByteArrayOutputStream.h.
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 }
void ByteArrayOutputStream::flushBuffer | ( | uint | cbRequested | ) | [private, virtual] |
Must be implemented by derived class to flush buffered data.
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.
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.
SharedByteArrayOutputStream ByteArrayOutputStream::newByteArrayOutputStream | ( | PBuffer | pBuffer, | |
uint | cbBuffer | |||
) | [static] |
Creates a new ByteArrayOutputStream.
pBuffer | byte array to fill | |
cbBuffer | buffer capacity |
Definition at line 29 of file ByteArrayOutputStream.cpp.
References ByteArrayOutputStream().
00032 { 00033 return SharedByteArrayOutputStream( 00034 new ByteArrayOutputStream(pBuffer,cbBuffer), 00035 ClosableObjectDestructor()); 00036 }
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().
Sets the current buffer to be written.
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] |
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.
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).
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 |
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.
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.
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 }
void ByteOutputStream::writeValue | ( | T const & | value | ) | [inline, inherited] |
Writes a fixed-size type to the stream.
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] |
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] |
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 }
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().