ObjFW
|
A base class for different types of streams. More...
#import <OFStream.h>
Public Member Functions | |
(BOOL) | - isAtEndOfStream |
Returns a boolean whether the end of the stream has been reached. | |
(size_t) | - readNBytes:intoBuffer: |
Reads at most size bytes from the stream into a buffer. | |
(void) | - readExactlyNBytes:intoBuffer: |
Reads exactly the specified length bytes from the stream into a buffer. | |
(uint8_t) | - readInt8 |
Reads a uint8_t from the stream. | |
(uint16_t) | - readBigEndianInt16 |
Reads a uint16_t from the stream which is encoded in big endian. | |
(uint32_t) | - readBigEndianInt32 |
Reads a uint32_t from the stream which is encoded in big endian. | |
(uint64_t) | - readBigEndianInt64 |
Reads a uint64_t from the stream which is encoded in big endian. | |
(float) | - readBigEndianFloat |
Reads a float from the stream which is encoded in big endian. | |
(double) | - readBigEndianDouble |
Reads a double from the stream which is encoded in big endian. | |
(size_t) | - readNBigEndianInt16s:intoBuffer: |
Reads the specified number of uint16_ts from the stream which are encoded in big endian. | |
(size_t) | - readNBigEndianInt32s:intoBuffer: |
Reads the specified number of uint32_ts from the stream which are encoded in big endian. | |
(size_t) | - readNBigEndianInt64s:intoBuffer: |
Reads the specified number of uint64_ts from the stream which are encoded in big endian. | |
(size_t) | - readNBigEndianFloats:intoBuffer: |
Reads the specified number of floats from the stream which are encoded in big endian. | |
(size_t) | - readNBigEndianDoubles:intoBuffer: |
Reads the specified number of doubles from the stream which are encoded in big endian. | |
(uint16_t) | - readLittleEndianInt16 |
Reads a uint16_t from the stream which is encoded in little endian. | |
(uint32_t) | - readLittleEndianInt32 |
Reads a uint32_t from the stream which is encoded in little endian. | |
(uint64_t) | - readLittleEndianInt64 |
Reads a uint64_t from the stream which is encoded in little endian. | |
(float) | - readLittleEndianFloat |
Reads a float from the stream which is encoded in little endian. | |
(double) | - readLittleEndianDouble |
Reads a double from the stream which is encoded in little endian. | |
(size_t) | - readNLittleEndianInt16s:intoBuffer: |
Reads the specified number of uint16_ts from the stream which are encoded in little endian. | |
(size_t) | - readNLittleEndianInt32s:intoBuffer: |
Reads the specified number of uint32_ts from the stream which are encoded in little endian. | |
(size_t) | - readNLittleEndianInt64s:intoBuffer: |
Reads the specified number of uint64_ts from the stream which are encoded in little endian. | |
(size_t) | - readNLittleEndianFloats:intoBuffer: |
Reads the specified number of floats from the stream which are encoded in little endian. | |
(size_t) | - readNLittleEndianDoubles:intoBuffer: |
Reads the specified number of doubles from the stream which are encoded in little endian. | |
(OFDataArray *) | - readDataArrayWithNItems: |
Reads the specified number of items with an item size of 1 from the stream and returns them in an OFDataArray. | |
(OFDataArray *) | - readDataArrayWithItemSize:andNItems: |
Reads the specified number of items with the specified item size from the stream and returns them in an OFDataArray. | |
(OFDataArray *) | - readDataArrayTillEndOfStream |
Returns an OFDataArray with all the remaining data of the stream. | |
(OFString *) | - readStringWithLength: |
Reads a string with the specified length from the stream. | |
(OFString *) | - readStringWithEncoding:length: |
Reads a string with the specified encoding and length from the stream. | |
(OFString *) | - readLine |
Reads until a newline, \0 or end of stream occurs. | |
(OFString *) | - readLineWithEncoding: |
Reads with the specified encoding until a newline, \0 or end of stream occurs. | |
(OFString *) | - tryReadLine |
Tries to read a line from the stream (see readLine) and returns nil if no complete line has been received yet. | |
(OFString *) | - tryReadLineWithEncoding: |
Tries to read a line from the stream with the specified encoding (see readLineWithEncoding:) and returns nil if no complete line has been received yet. | |
(OFString *) | - readTillDelimiter: |
Reads until the specified string or \0 is found or the end of stream occurs. | |
(OFString *) | - readTillDelimiter:withEncoding: |
Reads until the specified string or \0 is found or the end of stream occurs. | |
(OFString *) | - tryReadTillDelimiter: |
Tries to reads until the specified string or \0 is found or the end of stream (see readTillDelimiter:) and returns nil if not enough data has been received yet. | |
(OFString *) | - tryReadTillDelimiter:withEncoding: |
Tries to read until the specified string or \0 is found or the end of stream occurs (see readTIllDelimiterWithEncoding:) and returns nil if not enough data has been received yet. | |
(BOOL) | - buffersWrites |
Returns a boolen whether writes are buffered. | |
(void) | - setBuffersWrites: |
Enables or disables the write buffer. | |
(void) | - flushWriteBuffer |
Writes everythig in the write buffer to the stream. | |
(void) | - writeNBytes:fromBuffer: |
Writes from a buffer into the stream. | |
(void) | - writeInt8: |
Writes a uint8_t into the stream. | |
(void) | - writeBigEndianInt16: |
Writes a uint16_t into the stream, encoded in big endian. | |
(void) | - writeBigEndianInt32: |
Writes a uint32_t into the stream, encoded in big endian. | |
(void) | - writeBigEndianInt64: |
Writes a uint64_t into the stream, encoded in big endian. | |
(void) | - writeBigEndianFloat: |
Writes a float into the stream, encoded in big endian. | |
(void) | - writeBigEndianDouble: |
Writes a double into the stream, encoded in big endian. | |
(size_t) | - writeNBigEndianInt16s:fromBuffer: |
Writes the specified number of uint16_ts into the stream, encoded in big endian. | |
(size_t) | - writeNBigEndianInt32s:fromBuffer: |
Writes the specified number of uint32_ts into the stream, encoded in big endian. | |
(size_t) | - writeNBigEndianInt64s:fromBuffer: |
Writes the specified number of uint64_ts into the stream, encoded in big endian. | |
(size_t) | - writeNBigEndianFloats:fromBuffer: |
Writes the specified number of floats into the stream, encoded in big endian. | |
(size_t) | - writeNBigEndianDoubles:fromBuffer: |
Writes the specified number of doubles into the stream, encoded in big endian. | |
(void) | - writeLittleEndianInt16: |
Writes a uint16_t into the stream, encoded in little endian. | |
(void) | - writeLittleEndianInt32: |
Writes a uint32_t into the stream, encoded in little endian. | |
(void) | - writeLittleEndianInt64: |
Writes a uint64_t into the stream, encoded in little endian. | |
(void) | - writeLittleEndianFloat: |
Writes a float into the stream, encoded in little endian. | |
(void) | - writeLittleEndianDouble: |
Writes a double into the stream, encoded in little endian. | |
(size_t) | - writeNLittleEndianInt16s:fromBuffer: |
Writes the specified number of uint16_ts into the stream, encoded in little endian. | |
(size_t) | - writeNLittleEndianInt32s:fromBuffer: |
Writes the specified number of uint32_ts into the stream, encoded in little endian. | |
(size_t) | - writeNLittleEndianInt64s:fromBuffer: |
Writes the specified number of uint64_ts into the stream, encoded in little endian. | |
(size_t) | - writeNLittleEndianFloats:fromBuffer: |
Writes the specified number of floats into the stream, encoded in little endian. | |
(size_t) | - writeNLittleEndianDoubles:fromBuffer: |
Writes the specified number of doubles into the stream, encoded in little endian. | |
(size_t) | - writeDataArray: |
Writes from an OFDataArray into the stream. | |
(size_t) | - writeString: |
Writes a string into the stream, without the trailing zero. | |
(size_t) | - writeLine: |
Writes a string into the stream with a trailing newline. | |
(size_t) | - writeFormat: |
Writes a formatted string into the stream. | |
(size_t) | - writeFormat:withArguments: |
Writes a formatted string into the stream. | |
(size_t) | - pendingBytes |
Returns the number of bytes still present in the internal cache. | |
(BOOL) | - isBlocking |
Returns whether the stream is in blocking mode. | |
(void) | - setBlocking: |
Enables or disables non-blocking I/O. | |
(int) | - fileDescriptor |
Returns the file descriptor for the stream. | |
(void) | - close |
Closes the stream. |
A base class for different types of streams.
- (BOOL) buffersWrites |
Returns a boolen whether writes are buffered.
- (int) fileDescriptor |
Returns the file descriptor for the stream.
- (BOOL) isAtEndOfStream |
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.
- (double) readBigEndianDouble |
Reads a double from the stream which is encoded in big endian.
- (float) readBigEndianFloat |
Reads a float from the stream which is encoded in big endian.
- (uint16_t) readBigEndianInt16 |
Reads a uint16_t from the stream which is encoded in big endian.
- (uint32_t) readBigEndianInt32 |
Reads a uint32_t from the stream which is encoded in big endian.
- (uint64_t) readBigEndianInt64 |
Reads a uint64_t from the stream which is encoded in big endian.
- (OFDataArray *) readDataArrayTillEndOfStream |
Returns an OFDataArray with all the remaining data of the stream.
- (OFDataArray *) readDataArrayWithItemSize: | (size_t) | itemSize | |
andNItems: | (size_t) | nItems | |
Reads the specified number of items with the specified item size from the stream and returns them in an OFDataArray.
itemSize | The size of each item |
nItems | The number of items to read |
- (OFDataArray *) readDataArrayWithNItems: | (size_t) | nItems |
Reads the specified number of items with an item size of 1 from the stream and returns them in an OFDataArray.
nItems | The number of items to read |
- (void) readExactlyNBytes: | (size_t) | length | |
intoBuffer: | (void*) | buffer | |
Reads exactly the specified length bytes from the stream into a buffer.
Unlike readNBytes:intoBuffer:, this method does not return when less than the specified length has been read - instead, it waits until it got exactly the specified length.
buffer | The buffer into which the data is read |
length | The length of the data that should be read. The buffer MUST be EXACTLY this big! |
- (uint8_t) readInt8 |
Reads a uint8_t from the stream.
- (OFString *) readLine |
Reads until a newline, \0 or end of stream occurs.
- (OFString *) readLineWithEncoding: | (of_string_encoding_t) | encoding |
Reads with the specified encoding until a newline, \0 or end of stream occurs.
encoding | The encoding used by the stream |
- (double) readLittleEndianDouble |
Reads a double from the stream which is encoded in little endian.
- (float) readLittleEndianFloat |
Reads a float from the stream which is encoded in little endian.
- (uint16_t) readLittleEndianInt16 |
Reads a uint16_t from the stream which is encoded in little endian.
- (uint32_t) readLittleEndianInt32 |
Reads a uint32_t from the stream which is encoded in little endian.
- (uint64_t) readLittleEndianInt64 |
Reads a uint64_t from the stream which is encoded in little endian.
- (size_t) readNBigEndianDoubles: | (size_t) | nDoubles | |
intoBuffer: | (double*) | buffer | |
Reads the specified number of doubles from the stream which are encoded in big endian.
nDoubles | The number of doubles to read |
buffer | A buffer of sufficient size to store the specified number of doubles |
- (size_t) readNBigEndianFloats: | (size_t) | nFloats | |
intoBuffer: | (float*) | buffer | |
Reads the specified number of floats from the stream which are encoded in big endian.
nFloatss | The number of floats to read |
buffer | A buffer of sufficient size to store the specified number of floats |
- (size_t) readNBigEndianInt16s: | (size_t) | nInt16s | |
intoBuffer: | (uint16_t*) | buffer | |
Reads the specified number of uint16_ts from the stream which are encoded in big endian.
nInt16s | The number of uint16_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint16_ts |
- (size_t) readNBigEndianInt32s: | (size_t) | nInt32s | |
intoBuffer: | (uint32_t*) | buffer | |
Reads the specified number of uint32_ts from the stream which are encoded in big endian.
nInt32s | The number of uint32_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint32_ts |
- (size_t) readNBigEndianInt64s: | (size_t) | nInt64s | |
intoBuffer: | (uint64_t*) | buffer | |
Reads the specified number of uint64_ts from the stream which are encoded in big endian.
nInt64s | The number of uint64_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint64_ts |
- (size_t) readNBytes: | (size_t) | size | |
intoBuffer: | (void*) | buffer | |
Reads at most size bytes from the stream into a buffer.
On network streams, this might read less than the specified number of bytes. If you want to read exactly the specified number of bytes, use -[readExactlyNBytes:intoBuffer:].
buffer | The buffer into which the data is read |
length | The length of the data that should be read at most. The buffer MUST be at least this big! |
- (size_t) readNLittleEndianDoubles: | (size_t) | nDoubles | |
intoBuffer: | (double*) | buffer | |
Reads the specified number of doubles from the stream which are encoded in little endian.
nDoubles | The number of doubles to read |
buffer | A buffer of sufficient size to store the specified number of doubles |
- (size_t) readNLittleEndianFloats: | (size_t) | nFloats | |
intoBuffer: | (float*) | buffer | |
Reads the specified number of floats from the stream which are encoded in little endian.
nFloats | The number of floats to read |
buffer | A buffer of sufficient size to store the specified number of floats |
- (size_t) readNLittleEndianInt16s: | (size_t) | nInt16s | |
intoBuffer: | (uint16_t*) | buffer | |
Reads the specified number of uint16_ts from the stream which are encoded in little endian.
nInt16s | The number of uint16_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint16_ts |
- (size_t) readNLittleEndianInt32s: | (size_t) | nInt32s | |
intoBuffer: | (uint32_t*) | buffer | |
Reads the specified number of uint32_ts from the stream which are encoded in little endian.
nInt32s | The number of uint32_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint32_ts |
- (size_t) readNLittleEndianInt64s: | (size_t) | nInt64s | |
intoBuffer: | (uint64_t*) | buffer | |
Reads the specified number of uint64_ts from the stream which are encoded in little endian.
nInt64s | The number of uint64_ts to read |
buffer | A buffer of sufficient size to store the specified number of uint64_ts |
- (OFString *) readStringWithEncoding: | (of_string_encoding_t) | encoding | |
length: | (size_t) | length | |
Reads a string with the specified encoding and length from the stream.
If a \0 appears in the stream, the string will be truncated at the \0 and the rest of the bytes of the string will be lost. This way, reading from the stream will not break because of a \0 because the specified number of bytes is still being read and only the string gets truncated.
encoding | The encoding of the string to read from the stream |
length | The length (in bytes) of the string to read from the stream |
- (OFString *) readStringWithLength: | (size_t) | length |
Reads a string with the specified length from the stream.
If a \0 appears in the stream, the string will be truncated at the \0 and the rest of the bytes of the string will be lost. This way, reading from the stream will not break because of a \0 because the specified number of bytes is still being read and only the string gets truncated.
length | The length (in bytes) of the string to read from the stream |
Reads until the specified string or \0 is found or the end of stream occurs.
delimiter | The delimiter |
- (OFString *) readTillDelimiter: | (OFString*) | delimiter | |
withEncoding: | (of_string_encoding_t) | encoding | |
Reads until the specified string or \0 is found or the end of stream occurs.
delimiter | The delimiter |
encoding | The encoding used by the stream |
- (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!
enable | Whether the stream should be blocking |
- (void) setBuffersWrites: | (BOOL) | enable |
Enables or disables the write buffer.
enable | Whether the write buffer should be enabled or disabled |
- (OFString *) tryReadLine |
Tries to read a line from the stream (see readLine) and returns nil if no complete line has been received yet.
- (OFString *) tryReadLineWithEncoding: | (of_string_encoding_t) | encoding |
Tries to read a line from the stream with the specified encoding (see readLineWithEncoding:) and returns nil if no complete line has been received yet.
encoding | The encoding used by the stream |
Tries to reads until the specified string or \0 is found or the end of stream (see readTillDelimiter:) and returns nil if not enough data has been received yet.
delimiter | The delimiter |
- (OFString *) tryReadTillDelimiter: | (OFString*) | delimiter | |
withEncoding: | (of_string_encoding_t) | encoding | |
Tries to read until the specified string or \0 is found or the end of stream occurs (see readTIllDelimiterWithEncoding:) and returns nil if not enough data has been received yet.
delimiter | The delimiter |
encoding | The encoding used by the stream |
- (void) writeBigEndianDouble: | (double) | double_ |
Writes a double into the stream, encoded in big endian.
double_ | A double |
- (void) writeBigEndianFloat: | (float) | float_ |
Writes a float into the stream, encoded in big endian.
float_ | A float |
- (void) writeBigEndianInt16: | (uint16_t) | int16 |
Writes a uint16_t into the stream, encoded in big endian.
int16 | A uint16_t |
- (void) writeBigEndianInt32: | (uint32_t) | int32 |
Writes a uint32_t into the stream, encoded in big endian.
int32 | A uint32_t |
- (void) writeBigEndianInt64: | (uint64_t) | int64 |
Writes a uint64_t into the stream, encoded in big endian.
int64 | A uint64_t |
- (size_t) writeDataArray: | (OFDataArray*) | dataArray |
Writes from an OFDataArray into the stream.
dataArray | The OFDataArray to write into the stream |
- (size_t) writeFormat: | (OFConstantString*) | format | |
, | ... | ||
Writes a formatted string into the stream.
See printf for the format syntax. As an addition, %@ is available as format specifier for objects.
format | A string used as format |
- (size_t) writeFormat: | (OFConstantString*) | format | |
withArguments: | (va_list) | arguments | |
Writes a formatted string into the stream.
See printf for the format syntax. As an addition, %@ is available as format specifier for objects.
format | A string used as format |
arguments | The arguments used in the format string |
- (void) writeInt8: | (uint8_t) | int8 |
Writes a uint8_t into the stream.
int8 | A uint8_t |
- (size_t) writeLine: | (OFString*) | string |
Writes a string into the stream with a trailing newline.
string | The string from which the data is written to the stream |
- (void) writeLittleEndianDouble: | (double) | double_ |
Writes a double into the stream, encoded in little endian.
double_ | A double |
- (void) writeLittleEndianFloat: | (float) | float_ |
Writes a float into the stream, encoded in little endian.
float_ | A float |
- (void) writeLittleEndianInt16: | (uint16_t) | int16 |
Writes a uint16_t into the stream, encoded in little endian.
int16 | A uint16_t |
- (void) writeLittleEndianInt32: | (uint32_t) | int32 |
Writes a uint32_t into the stream, encoded in little endian.
int32 | A uint32_t |
- (void) writeLittleEndianInt64: | (uint64_t) | int64 |
Writes a uint64_t into the stream, encoded in little endian.
int64 | A uint64_t |
- (size_t) writeNBigEndianDoubles: | (size_t) | nDoubles | |
fromBuffer: | (const double*) | buffer | |
Writes the specified number of doubles into the stream, encoded in big endian.
nDoubles | The number of doubles to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNBigEndianFloats: | (size_t) | nFloats | |
fromBuffer: | (const float*) | buffer | |
Writes the specified number of floats into the stream, encoded in big endian.
nFloats | The number of floats to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNBigEndianInt16s: | (size_t) | nInt16s | |
fromBuffer: | (const uint16_t*) | buffer | |
Writes the specified number of uint16_ts into the stream, encoded in big endian.
nInt16 | The number of uint16_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNBigEndianInt32s: | (size_t) | nInt32s | |
fromBuffer: | (const uint32_t*) | buffer | |
Writes the specified number of uint32_ts into the stream, encoded in big endian.
nInt32 | The number of uint32_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNBigEndianInt64s: | (size_t) | nInt64s | |
fromBuffer: | (const uint64_t*) | buffer | |
Writes the specified number of uint64_ts into the stream, encoded in big endian.
nInt64 | The number of uint64_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (void) writeNBytes: | (size_t) | length | |
fromBuffer: | (const void*) | buffer | |
Writes from a buffer into the stream.
buffer | The buffer from which the data is written to the stream |
length | The length of the data that should be written |
- (size_t) writeNLittleEndianDoubles: | (size_t) | nDoubles | |
fromBuffer: | (const double*) | buffer | |
Writes the specified number of doubles into the stream, encoded in little endian.
nDoubles | The number of doubles to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNLittleEndianFloats: | (size_t) | nFloats | |
fromBuffer: | (const float*) | buffer | |
Writes the specified number of floats into the stream, encoded in little endian.
nFloats | The number of floats to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNLittleEndianInt16s: | (size_t) | nInt16s | |
fromBuffer: | (const uint16_t*) | buffer | |
Writes the specified number of uint16_ts into the stream, encoded in little endian.
nInt16 | The number of uint16_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNLittleEndianInt32s: | (size_t) | nInt32s | |
fromBuffer: | (const uint32_t*) | buffer | |
Writes the specified number of uint32_ts into the stream, encoded in little endian.
nInt32 | The number of uint32_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeNLittleEndianInt64s: | (size_t) | nInt64s | |
fromBuffer: | (const uint64_t*) | buffer | |
Writes the specified number of uint64_ts into the stream, encoded in little endian.
nInt64 | The number of uint64_ts to write |
buffer | The buffer from which the data is written to the stream after it has been byte swapped if necessary |
- (size_t) writeString: | (OFString*) | string |
Writes a string into the stream, without the trailing zero.
string | The string from which the data is written to the stream |