Cross-Platform C++

ot::io
class ByteArrayOutputStream

#include "ot/io/ByteArrayOutputStream.h"

ot::io::OutputStream ot::ManagedObject An output stream that stores the data in an internal buffer. When the ByteArrayOutputStream is constructed, an internal buffer is created. The size of the internal buffer can be specified by using the overloaded constructor.

When bytes are written to this output stream, they are copied into the internal buffer. The buffer is automatically expanded as additional bytes are written to it.

The buffered data may be retrieved at any time using the data() and size() methods.

See also:
ByteArrayInputStream



Constructor/Destructor Summary
ByteArrayOutputStream()
         Creates a ByteArrayOutputStream with a default initial buffer size.
ByteArrayOutputStream(size_t size)
         Creates a ByteArrayOutputStream with a specified initial buffer size.

Method Summary
 virtual void close()
         Closes the ByteArrayOutputStream.
 const Byte* data() const
         Returns a constant pointer to the start of the internal byte buffer.
 void reset()
         Resets the internal buffer to zero size.
 size_t size() const
         Returns the number of bytes written to the internal byte buffer.
 String toString() const
         Converts the bytes in the internal buffer into a Unicode character string using the default encoding.
 String toString(const String& encoding) const
         Converts the bytes in the internal buffer into a Unicode character string using the supplied encoding name.
 String toString(CodeConverter* pDecoder) const
         Converts the bytes in the internal buffer into a Unicode character string using the supplied CodeConverter.
 virtual void write(const Byte* pBuffer, size_t bufLen)
         Writes an array of bytes to this output stream.
 void writeTo(OutputStream* pOut) const
         Writes the contents of the internal buffer to the specified OutputStream.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Methods inherited from class ot::io::OutputStream
flush, flushBuffers, write

Constructor/Destructor Detail

ByteArrayOutputStream

 ByteArrayOutputStream()
Creates a ByteArrayOutputStream with a default initial buffer size. As bytes are written to the output stream the buffer is automatically extended as required.


ByteArrayOutputStream

 ByteArrayOutputStream(size_t size)
Creates a ByteArrayOutputStream with a specified initial buffer size. As bytes are written to the output stream the buffer is automatically extended as required.

Parameters:
size - the initial buffer size.

Method Detail

close

virtual void close()
Closes the ByteArrayOutputStream. The internal buffer is intentionally not released so that it remains available for subsequent calls to getData() and toString().


data

const Bytedata() const
Returns a constant pointer to the start of the internal byte buffer.

See also:
size()

reset

void reset()
Resets the internal buffer to zero size. This does not change the capacity of the internal buffer or free the resources used by the buffer.


size

size_t size() const
Returns the number of bytes written to the internal byte buffer.

See also:
data()

toString

String toString() const
Converts the bytes in the internal buffer into a Unicode character string using the default encoding.

Exceptions:
UnsupportedEncodingException - if enc is not a supported encoding

toString

String toString(const String& encoding) const
Converts the bytes in the internal buffer into a Unicode character string using the supplied encoding name.

Parameters:
enc - the name of the encoding.
Exceptions:
UnsupportedEncodingException - if enc is not a supported encoding

toString

String toString(CodeConverter* pDecoder) const
Converts the bytes in the internal buffer into a Unicode character string using the supplied CodeConverter.

Parameters:
pDecoder - the code converter to use for decoding bytes into Unicode characters

write

virtual void write(const Byte* pBuffer,
                   size_t bufLen)
Writes an array of bytes to this output stream.

Parameters:
pBuffer - pointer to the start of an array of bytes to be written
bufLen - length of the byte array
Exceptions:
NullPointerException - if pBuffer is null.
IOException - if an I/O error occurs.

writeTo

void writeTo(OutputStream* pOut) const
Writes the contents of the internal buffer to the specified OutputStream.

Parameters:
pOut - the OutputStream to write the contents of the buffer to.
Exceptions:
IOException - if an error occurs writing to the OutputStream.
NullPointerException - if pOut is null.


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements