#include <NonblockingReader.h>
Public Member Functions | |
NonblockingReader (Reader *in) | |
virtual void | close () |
virtual void | mark () |
virtual boolean | markSupported () |
virtual int | read () |
virtual int | read (char *cbuf, int length) |
virtual int | read (char *cbuf, int off, int length) |
virtual boolean | ready () |
virtual void | reset () |
virtual long | skip (long length) |
virtual CFREE char * | readLine () |
Private Member Functions | |
void | compactBuffer () |
boolean | fillNonblocking () |
void | expandBufferMemory () |
int | preRead (char *cbuf, int off, int length) |
int | nonblockingRead (char *cbuf, int off, int length) |
int | findLineInBuffer () |
Private Attributes | |
CDELETE Reader * | in |
char * | cb |
char * | tmp |
int | nChars |
int | nextChar |
One past the last index of the last char in the buffer. | |
int | maxChars |
The index of the first char in the buffer. | |
int | incrChars |
The total size of the buffer, i.e. nChars <= maxChars. | |
int | defaultCharBufferSize |
If the memory is to be increased, this is the increment. | |
int | defaultExpectedLineLength |
void jcpp::NonblockingReader::compactBuffer | ( | ) | [private] |
Move the start of the heap down to the start of the buffer. Actually doesn't compact anything, just kind of tamps it down.
boolean jcpp::NonblockingReader::fillNonblocking | ( | ) | [private] |
Fill buffer without blocking, returns TRUE if fill completed, returns FALSE if fill was truncated because it would block.
void jcpp::NonblockingReader::expandBufferMemory | ( | ) | [private] |
Add some more memory to the buffer. There is a chance that we may have an enormous buffer if we have an enormous line that we are reading in.
virtual void jcpp::NonblockingReader::close | ( | ) | [inline, virtual] |
virtual void jcpp::NonblockingReader::mark | ( | ) | [inline, virtual] |
virtual boolean jcpp::NonblockingReader::markSupported | ( | ) | [inline, virtual] |
virtual int jcpp::NonblockingReader::read | ( | ) | [virtual] |
Read a single character off the stream.
Implements jcpp::Reader.
virtual int jcpp::NonblockingReader::read | ( | char * | cbuf, | |
int | length | |||
) | [inline, virtual] |
Read length bytes into the buffer pointed to by cbuf.
Reimplemented from jcpp::Reader.
00065 { 00066 return read(cbuf, 0 , length); 00067 }
int jcpp::NonblockingReader::preRead | ( | char * | cbuf, | |
int | off, | |||
int | length | |||
) | [private] |
This reads a blob of characters, but does not necessarily fulfill the request. A negative return value means an error, EOF or block has occurred.
int jcpp::NonblockingReader::nonblockingRead | ( | char * | cbuf, | |
int | off, | |||
int | length | |||
) | [private] |
Does the same as read(char* cbuf, int off, int length), but never blocks.
virtual int jcpp::NonblockingReader::read | ( | char * | cbuf, | |
int | off, | |||
int | length | |||
) | [virtual] |
Read <em length /em> bytes into the buffer pointed to by <em cbuf /em> beginning at the offset <em off /em>. Returns the number of characters actually read or -1 if there is an error.
Implements jcpp::Reader.
virtual boolean jcpp::NonblockingReader::ready | ( | ) | [inline, virtual] |
Answers TRUE if the stream is ready to be read.
Implements jcpp::Reader.
00086 { 00087 return (nextChar < nChars) || in->ready(); 00088 }
virtual void jcpp::NonblockingReader::reset | ( | ) | [inline, virtual] |
Reset the stream back to the previously set mark, if supported, error otherwise.
Reimplemented from jcpp::Reader.
virtual long jcpp::NonblockingReader::skip | ( | long | length | ) | [virtual] |
Skip length bytes or to end-of-file whichever comes first.
Implements jcpp::Reader.
virtual CFREE char* jcpp::NonblockingReader::readLine | ( | ) | [virtual] |
Read a line, the terminating newline is replaced with a null, returning 0 if it would block or the line if it is available.
int jcpp::NonblockingReader::nextChar [private] |
One past the last index of the last char in the buffer.
int jcpp::NonblockingReader::maxChars [private] |
The index of the first char in the buffer.
int jcpp::NonblockingReader::incrChars [private] |
The total size of the buffer, i.e. nChars <= maxChars.
int jcpp::NonblockingReader::defaultCharBufferSize [private] |
If the memory is to be increased, this is the increment.