jcpp::NonblockingReader Class Reference

#include <NonblockingReader.h>

Inheritance diagram for jcpp::NonblockingReader:

Inheritance graph
[legend]
Collaboration diagram for jcpp::NonblockingReader:

Collaboration graph
[legend]

List of all members.

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 Readerin
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


Detailed Description

A class that has similar features to BufferedReader but never blocks on read, instead it will return a zero read indication or error, if it would have blocked.

Member Function Documentation

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]

Close the underlying file descriptor.

Implements jcpp::Reader.

00051                        {
00052     in->close();
00053   }

virtual void jcpp::NonblockingReader::mark (  )  [inline, virtual]

Mark this point in the read stream.

Reimplemented from jcpp::Reader.

00055                       {
00056     en((char *)"not allowed to use mark() in Reader");
00057   }

virtual boolean jcpp::NonblockingReader::markSupported (  )  [inline, virtual]

Determine if this stream supports marking the stream.

Reimplemented from jcpp::Reader.

00059                                   {
00060     return FALSE;
00061   }

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.

00091                        {
00092     en((char *)":-( Reader::reset() not supported");
00093   }

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.


Member Data Documentation

One past the last index of the last char in the buffer.

The index of the first char in the buffer.

The total size of the buffer, i.e. nChars <= maxChars.

If the memory is to be increased, this is the increment.


The documentation for this class was generated from the following file:

Generated on Thu Sep 17 08:21:29 2009 for CCAFFEINE by  doxygen 1.5.9