ObjectiveLib  1.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes
OLBufferingOutStream Class Reference

A layered out stream that filters its data through a buffer. More...

#import <BufferingOutStream.h>

Inheritance diagram for OLBufferingOutStream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

(void) - flush
 Flush the stream.
(void) - writeByte:
 Write a byte.
(unsigned) - writeBytes:count:
 Write a sequence of bytes to the stream.
Initializers and Deallocators
(id) - initWithOutStream:
 Initialize the stream.
(id) - initWithOutStream:bufferSize:
 Initialize the stream.
(void) - dealloc
 Finalize the stream and deallocate any allocated memory.

Static Public Member Functions

(id) + streamWithOutStream:
 Create and return a new stream.

Protected Attributes

uint8_t * buffer
 The buffer that temporarily holds data written to the stream.
unsigned capacity
 The capacity of the buffer.
unsigned count
 The number of bytes currently in the buffer.

Detailed Description

A layered out stream that filters its data through a buffer.

This concrete class channels all written data through a buffer, which in some cases can dramatically improve performance, for example when the layer below the buffering stream performs a very time-consuming task. The buffer will be cleared on any call to flush (OLBufferingOutStream) or close (OLLayeredOutStream).

See also:
OLBufferingInStream

Member Function Documentation

- (void) dealloc

Finalize the stream and deallocate any allocated memory.

Reimplemented from OLLayeredOutStream.

- (void) flush

Flush the stream.

Any data that is pending or buffered will be written and the stream will be restored to a pristine state.

Exceptions:
OLInputOutputExceptionif there is an error flushing the stream

Reimplemented from OLLayeredOutStream.

- (id) initWithOutStream: (OLOutStream *)  underStream

Initialize the stream.

The new stream uses underStream as the next lower layer in the stream stack and uses the default buffer size of 32K.

Parameters:
underStreamthe stream to which this stream ultimately forwards its data
Returns:
a reference to this stream

Reimplemented from OLLayeredOutStream.

- (id) initWithOutStream: (OLOutStream *)  underStream
bufferSize: (unsigned)  size 

Initialize the stream.

The new stream uses underStream as the next lower layer in the stream stack and uses size as the buffer size.

Parameters:
underStreamthe stream to which this stream ultimately forwards its data
sizethe size of the buffer
Returns:
a reference to this stream
+ (id) streamWithOutStream: (OLOutStream *)  underStream

Create and return a new stream.

The new stream uses underStream as the next lower layer in the stream stack and uses the default buffer size of 32K.

Parameters:
underStreamthe stream to which this stream ultimately forwards its data
Returns:
a reference to the newly created stream
- (void) writeByte: (uint8_t)  byte

Write a byte.

This is an optimized version of writing a byte that is very fast if the buffer is not full.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
bytethe byte to write

Reimplemented from OLOutStream.

- (unsigned) writeBytes: (const uint8_t *)  bytes
count: (unsigned)  num 

Write a sequence of bytes to the stream.

Bytes are copied into the buffer, which is flushed as needed. For cases where num is larger than the size of the buffer, the buffer is flushed and then ignored, thus eliminating the needless overhead of using it.

Exceptions:
OLInputOutputExceptionif there is an error writing to the stream
Parameters:
bytesthe bytes to write
numthe number of bytes to write
Returns:
the number of bytes written

Reimplemented from OLLayeredOutStream.


Member Data Documentation

- (uint8_t*) buffer [protected]

The buffer that temporarily holds data written to the stream.

- (unsigned) capacity [protected]

The capacity of the buffer.

- (unsigned) count [protected]

The number of bytes currently in the buffer.


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

ObjectiveLibGenerated Sat Feb 15 2014 07:45:34, © 2004-2007 Will Mason