Public Member Functions | Protected Attributes | Properties

OFStream Class Reference

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

#import <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:
(void) - readExactlyNBytes:intoBuffer:
(uint8_t) - readInt8
(uint16_t) - readBigEndianInt16
(uint32_t) - readBigEndianInt32
(uint64_t) - readBigEndianInt64
(uint16_t) - readLittleEndianInt16
(uint32_t) - readLittleEndianInt32
(uint64_t) - readLittleEndianInt64
(OFDataArray *) - readDataArrayWithItemSize:andNItems:
(OFDataArray *) - readDataArrayTillEndOfStream
(OFString *) - readLine
(OFString *) - readLineWithEncoding:
(OFString *) - readTillDelimiter:
(OFString *) - readTillDelimiter:withEncoding:
(BOOL) - buffersWrites
(void) - setBuffersWrites:
(void) - flushWriteBuffer
(size_t) - writeNBytes:fromBuffer:
(void) - writeInt8:
(void) - writeBigEndianInt16:
(void) - writeBigEndianInt32:
(void) - writeBigEndianInt64:
(void) - writeLittleEndianInt16:
(void) - writeLittleEndianInt32:
(void) - writeLittleEndianInt64:
(size_t) - writeDataArray:
(size_t) - writeString:
(size_t) - writeLine:
(size_t) - writeFormat:
(size_t) - writeFormat:withArguments:
(size_t) - pendingBytes
(BOOL) - isBlocking
(void) - setBlocking:
(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) buffersWrites  
Returns:
A boolean whether writes are buffered
- (void) close  

Closes the stream.

- (int) fileDescriptor  
Returns:
The file descriptor for the stream.
- (void) flushWriteBuffer  

Writes everythig in the write buffer to the stream.

- (BOOL) isAtEndOfStream  

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) isBlocking  
Returns:
Whether the stream is in blocking mode
- (size_t) pendingBytes  
Returns:
The number of bytes still present in the internal cache.
- (uint16_t) readBigEndianInt16  

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) readBigEndianInt32  

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) readBigEndianInt64  

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 *) readDataArrayTillEndOfStream  
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 *) readDataArrayWithItemSize: (size_t)  itemsize
andNItems: (size_t)  nitems 

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:
itemsize The size of each item
nitems The number of iteams to read
Returns:
An OFDataArray with at nitems items.
- (void) readExactlyNBytes: (size_t)  size
intoBuffer: (char*)  buf 

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:
buf The buffer into which the data is read
size The size of the data that should be read. The buffer MUST be EXACTLY this big!
- (uint8_t) readInt8  

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 *) readLine  

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 *) readLineWithEncoding: (of_string_encoding_t)  encoding  

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

Parameters:
encoding The 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) readLittleEndianInt16  

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) readLittleEndianInt32  

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) readLittleEndianInt64  

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) readNBytes: (size_t)  size
intoBuffer: (char*)  buf 

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

Parameters:
buf The buffer into which the data is read
size The 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 *) readTillDelimiter: (OFString*)  delimiter  

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

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

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

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

Enables or disables non-blocking I/O.

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

Parameters:
enable Whether the stream should be blocking
- (void) setBuffersWrites: (BOOL)  enable  

Enables or disables the write buffer.

Parameters:
enable Whether the write buffer should be enabled or disabled
- (void) writeBigEndianInt16: (uint16_t)  int16  

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

Parameters:
int16 A uint16_t
- (void) writeBigEndianInt32: (uint32_t)  int32  

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

Parameters:
int32 A uint32_t
- (void) writeBigEndianInt64: (uint64_t)  int64  

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

Parameters:
int64 A uint64_t
- (size_t) writeDataArray: (OFDataArray*)  dataarray  

Writes from an OFDataArray into the stream.

Parameters:
dataarray The OFDataArray to write into the stream
Returns:
The number of bytes written
- (size_t) writeFormat: (OFString*)  fmt
,   ... 

Writes a formatted string into the stream.

Parameters:
fmt A string used as format
Returns:
The number of bytes written
- (size_t) writeFormat: (OFString*)  fmt
withArguments: (va_list)  args 

Writes a formatted string into the stream.

Parameters:
fmt A string used as format
args The arguments used in the format string
Returns:
The number of bytes written
- (void) writeInt8: (uint8_t)  int8  

Writes a uint8_t into the stream.

Parameters:
int8 A uint8_t
- (size_t) writeLine: (OFString*)  str  

Writes a string into the stream with a trailing newline.

Parameters:
str The string from which the data is written to the stream
Returns:
The number of bytes written
- (void) writeLittleEndianInt16: (uint16_t)  int16  

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

Parameters:
int16 A uint16_t
- (void) writeLittleEndianInt32: (uint32_t)  int32  

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

Parameters:
int32 A uint32_t
- (void) writeLittleEndianInt64: (uint64_t)  int64  

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

Parameters:
int64 A uint64_t
- (size_t) writeNBytes: (size_t)  size
fromBuffer: (const char*)  buf 

Writes from a buffer into the stream.

Parameters:
buf The buffer from which the data is written to the stream
size The size of the data that should be written
Returns:
The number of bytes written
- (size_t) writeString: (OFString*)  str  

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

Parameters:
str The 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