ObjFW
Public Member Functions | Protected Attributes | Properties
OFStream Class Reference

A base class for different types of streams. More...

#include <OFStream.h>

Inheritance diagram for OFStream:
OFObject <OFObject> OFSeekableStream OFStreamSocket OFFile OFTCPSocket

List of all members.

Public Member Functions

BOOL isAtEndOfStream ()
size_t readNBytes:intoBuffer: (size_t size,[intoBuffer] char *buf)
void readExactlyNBytes:intoBuffer: (size_t size,[intoBuffer] char *buf)
uint8_t readInt8 ()
uint16_t readBigEndianInt16 ()
uint32_t readBigEndianInt32 ()
uint64_t readBigEndianInt64 ()
uint16_t readLittleEndianInt16 ()
uint32_t readLittleEndianInt32 ()
uint64_t readLittleEndianInt64 ()
OFDataArrayreadDataArrayWithItemSize:andNItems: (size_t itemsize,[andNItems] size_t nitems)
OFDataArrayreadDataArrayTillEndOfStream ()
OFStringreadLine ()
OFStringreadLineWithEncoding: (of_string_encoding_t encoding)
OFStringreadTillDelimiter: (OFString *delimiter)
OFStringreadTillDelimiter:withEncoding: (OFString *delimiter,[withEncoding] of_string_encoding_t encoding)
BOOL buffersWrites ()
void setBuffersWrites: (BOOL enable)
void flushWriteBuffer ()
size_t writeNBytes:fromBuffer: (size_t size,[fromBuffer] const char *buf)
void writeInt8: (uint8_t int8)
void writeBigEndianInt16: (uint16_t int16)
void writeBigEndianInt32: (uint32_t int32)
void writeBigEndianInt64: (uint64_t int64)
void writeLittleEndianInt16: (uint16_t int16)
void writeLittleEndianInt32: (uint32_t int32)
void writeLittleEndianInt64: (uint64_t int64)
size_t writeDataArray: (OFDataArray *dataarray)
size_t writeString: (OFString *str)
size_t writeLine: (OFString *str)
size_t writeFormat: (OFString *fmt,[,]...)
size_t writeFormat:withArguments: (OFString *fmt,[withArguments] va_list args)
size_t pendingBytes ()
BOOL isBlocking ()
void setBlocking: (BOOL enable)
int fileDescriptor ()
void close ()

Protected Attributes

char * cache
char * wBuffer
size_t cacheLen
size_t wBufferLen
BOOL buffersWrites

Properties

BOOL isBlocking

Detailed Description

A base class for different types of streams.

IMPORTANT: If you want to subclass this, override _readNBytes:intoBuffer:, _writeNBytes:fromBuffer: and _isAtEndOfStream, but nothing else. Those are not defined in the headers, but do the actual work. OFStream uses those and does all the caching and other stuff. If you override these methods without the _ prefix, you *WILL* break caching and get broken results!


Member Function Documentation

BOOL OFStream::buffersWrites ( ) [virtual]
Returns:
A boolean whether writes are buffered
void OFStream::close ( ) [virtual]

Closes the stream.

int OFStream::fileDescriptor ( ) [virtual]
Returns:
The file descriptor for the stream.
void OFStream::flushWriteBuffer ( ) [virtual]

Writes everythig in the write buffer to the stream.

BOOL OFStream::isAtEndOfStream ( ) [virtual]

Returns a boolean whether the end of the stream has been reached.

Returns:
A boolean whether the end of the stream has been reached
BOOL OFStream::isBlocking ( ) [virtual]
Returns:
Whether the stream is in blocking mode
size_t OFStream::pendingBytes ( ) [virtual]
Returns:
The number of bytes still present in the internal cache.
uint16_t OFStream::readBigEndianInt16 ( ) [virtual]

Reads a uint16_t from the stream which is encoded in big endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint16_t from the stream in native endianess
uint32_t OFStream::readBigEndianInt32 ( ) [virtual]

Reads a uint32_t from the stream which is encoded in big endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint32_t from the stream in the native endianess
uint64_t OFStream::readBigEndianInt64 ( ) [virtual]

Reads a uint64_t from the stream which is encoded in big endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint64_t from the stream in the native endianess
OFDataArray * OFStream::readDataArrayTillEndOfStream ( ) [virtual]
Returns:
An OFDataArray with an item size of 1 with all the data of the stream until the end of the stream is reached.
OFDataArray * OFStream::readDataArrayWithItemSize:andNItems: ( size_t  itemsize,
[andNItems] size_t  nitems 
) [virtual]

Reads nitems items with the specified item size from the stream and returns them in an OFDataArray.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Parameters:
itemsizeThe size of each item
nitemsThe number of iteams to read
Returns:
An OFDataArray with at nitems items.
void OFStream::readExactlyNBytes:intoBuffer: ( size_t  size,
[intoBuffer] char*  buf 
) [virtual]

Reads exactly size bytes from the stream into a buffer. Unlike readNBytes:intoBuffer:, this method does not return when less than the specified size has been read - instead, it waits until it got exactly size bytes.

WARNING: Only call this when you know that specified amount of data is available! Otherwise you will get an exception!

Parameters:
bufThe buffer into which the data is read
sizeThe size of the data that should be read. The buffer MUST be EXACTLY this big!
uint8_t OFStream::readInt8 ( ) [virtual]

Reads a uint8_t from the stream.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint8_t from the stream
OFString * OFStream::readLine ( ) [virtual]

Read until a newline, \0 or end of stream occurs.

Returns:
The line that was read, autoreleased, or nil if the end of the stream has been reached.
OFString * OFStream::readLineWithEncoding: ( of_string_encoding_t  encoding) [virtual]

Read with the specified encoding until a newline, \0 or end of stream occurs.

Parameters:
encodingThe encoding used by the stream
Returns:
The line that was read, autoreleased, or nil if the end of the stream has been reached.
uint16_t OFStream::readLittleEndianInt16 ( ) [virtual]

Reads a uint16_t from the stream which is encoded in little endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint16_t from the stream in native endianess
uint32_t OFStream::readLittleEndianInt32 ( ) [virtual]

Reads a uint32_t from the stream which is encoded in little endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint32_t from the stream in the native endianess
uint64_t OFStream::readLittleEndianInt64 ( ) [virtual]

Reads a uint64_t from the stream which is encoded in little endian.

WARNING: Only call this when you know that enough data is available! Otherwise you will get an exception!

Returns:
A uint64_t from the stream in the native endianess
size_t OFStream::readNBytes:intoBuffer: ( size_t  size,
[intoBuffer] char*  buf 
) [virtual]

Reads at most size bytes from the stream into a buffer.

Parameters:
bufThe buffer into which the data is read
sizeThe size of the data that should be read at most. The buffer MUST be at least size big!
Returns:
The number of bytes read
OFString * OFStream::readTillDelimiter: ( OFString delimiter) [virtual]

Read until the specified string or \0 is found or the end of stream occurs.

Parameters:
delimiterThe delimiter
Returns:
The line that was read, autoreleased, or nil if the end of the stream has been reached.
OFString * OFStream::readTillDelimiter:withEncoding: ( OFString delimiter,
[withEncoding] of_string_encoding_t  encoding 
) [virtual]

Read until the specified string or \0 is found or the end of stream occurs.

Parameters:
delimiterThe delimiter
encodingThe encoding used by the stream
Returns:
The line that was read, autoreleased, or nil if the end of the stream has been reached.
void OFStream::setBlocking: ( BOOL  enable) [virtual]

Enables or disables non-blocking I/O.

By default, a stream is in blocking mode. On Win32, this currently only works for sockets!

Parameters:
enableWhether the stream should be blocking
void OFStream::setBuffersWrites: ( BOOL  enable) [virtual]

Enables or disables the write buffer.

Parameters:
enableWhether the write buffer should be enabled or disabled
void OFStream::writeBigEndianInt16: ( uint16_t  int16) [virtual]

Writes a uint16_t into the stream, encoded in big endian.

Parameters:
int16A uint16_t
void OFStream::writeBigEndianInt32: ( uint32_t  int32) [virtual]

Writes a uint32_t into the stream, encoded in big endian.

Parameters:
int32A uint32_t
void OFStream::writeBigEndianInt64: ( uint64_t  int64) [virtual]

Writes a uint64_t into the stream, encoded in big endian.

Parameters:
int64A uint64_t
size_t OFStream::writeDataArray: ( OFDataArray dataarray) [virtual]

Writes from an OFDataArray into the stream.

Parameters:
dataarrayThe OFDataArray to write into the stream
Returns:
The number of bytes written
size_t OFStream::writeFormat: ( OFString fmt,
[,]   ... 
) [virtual]

Writes a formatted string into the stream.

Parameters:
fmtA string used as format
Returns:
The number of bytes written
size_t OFStream::writeFormat:withArguments: ( OFString fmt,
[withArguments] va_list  args 
) [virtual]

Writes a formatted string into the stream.

Parameters:
fmtA string used as format
argsThe arguments used in the format string
Returns:
The number of bytes written
void OFStream::writeInt8: ( uint8_t  int8) [virtual]

Writes a uint8_t into the stream.

Parameters:
int8A uint8_t
size_t OFStream::writeLine: ( OFString str) [virtual]

Writes a string into the stream with a trailing newline.

Parameters:
strThe string from which the data is written to the stream
Returns:
The number of bytes written
void OFStream::writeLittleEndianInt16: ( uint16_t  int16) [virtual]

Writes a uint16_t into the stream, encoded in little endian.

Parameters:
int16A uint16_t
void OFStream::writeLittleEndianInt32: ( uint32_t  int32) [virtual]

Writes a uint32_t into the stream, encoded in little endian.

Parameters:
int32A uint32_t
void OFStream::writeLittleEndianInt64: ( uint64_t  int64) [virtual]

Writes a uint64_t into the stream, encoded in little endian.

Parameters:
int64A uint64_t
size_t OFStream::writeNBytes:fromBuffer: ( size_t  size,
[fromBuffer] const char*  buf 
) [virtual]

Writes from a buffer into the stream.

Parameters:
bufThe buffer from which the data is written to the stream
sizeThe size of the data that should be written
Returns:
The number of bytes written
size_t OFStream::writeString: ( OFString str) [virtual]

Writes a string into the stream, without the trailing zero.

Parameters:
strThe string from which the data is written to the stream
Returns:
The number of bytes written

The documentation for this class was generated from the following files:
 All Classes Functions Variables