# CheckedArrayByteSink Class Reference

Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not write more than capacity bytes to outbuf. More...

`#include <bytestream.h>`

Inheritance diagram for CheckedArrayByteSink:

## Public Member Functions
| CheckedArrayByteSink (char *outbuf, int32_t capacity)
| Constructs a ByteSink that will write to outbuf[0.
virtual void | Append (const char *bytes, int32_t n)
| Append "bytes[0,n-1]" to this.
virtual char * | GetAppendBuffer (int32_t min_capacity, int32_t desired_capacity_hint, char *scratch, int32_t scratch_capacity, int32_t *result_capacity)
| Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity.
int32_t | NumberOfBytesWritten () const
| Returns the number of bytes actually written to the sink.
UBool | Overflowed () const
| Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity' bytes.

## Detailed Description

Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not write more than capacity bytes to outbuf.

If more than capacity bytes are Append()ed, then excess bytes are ignored, and Overflowed() will return true. Overflow does not cause a runtime error.

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 142 of file bytestream.h.

## Constructor & Destructor Documentation

CheckedArrayByteSink::CheckedArrayByteSink | ( | char * | outbuf,
|  | int32_t | capacity |
| ) |  |  |

Constructs a ByteSink that will write to outbuf[0.

.capacity-1].

Parameters:

  | outbuf | buffer to write to
  | capacity | size of the buffer

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

## Member Function Documentation

virtual void CheckedArrayByteSink::Append | ( | const char * | bytes,
|  | int32_t | n |
| ) |  |  | `[virtual]`

Append "bytes[0,n-1]" to this.

Parameters:

  | bytes | the pointer to the bytes
  | n | the number of bytes; must be non-negative

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

Implements ByteSink.

virtual char* CheckedArrayByteSink::GetAppendBuffer | ( | int32_t | min_capacity,
|  | int32_t | desired_capacity_hint,
|  | char * | scratch,
|  | int32_t | scratch_capacity,
|  | int32_t * | result_capacity |
| ) |  |  | `[virtual]`

Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity.

For details see the base class documentation.

Parameters:

  | min_capacity | required minimum capacity of the returned buffer; must be non-negative
  | desired_capacity_hint | desired capacity of the returned buffer; must be non-negative
  | scratch | default caller-owned buffer
  | scratch_capacity | capacity of the scratch buffer
  | result_capacity | pointer to an integer which will be set to the capacity of the returned buffer

Returns:
  a buffer with *result_capacity>=min_capacity

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

Reimplemented from ByteSink.

int32_t CheckedArrayByteSink::NumberOfBytesWritten | ( |  | ) | const`[inline]`

Returns the number of bytes actually written to the sink.

Returns:
  number of bytes written to the buffer

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 181 of file bytestream.h.

UBool CheckedArrayByteSink::Overflowed | ( |  | ) | const`[inline]`

Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity' bytes.

Returns:
  TRUE if more than 'capacity' bytes were Append()ed

Draft:
  This API may be changed in the future versions and was introduced in ICU 4.2

Definition at line 188 of file bytestream.h.

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

- bytestream.h