Base Framework
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
BufferedInputStream Class Reference

Buffered input stream. More...

#include <base/io/BufferedInputStream.h>

Inherits FilterInputStream.

Public Member Functions

 BufferedInputStream ()
 
 BufferedInputStream (InputStream &in, unsigned int size=DEFAULT_BUFFER_SIZE)
 
void fill ()
 
const uint8 * getElements () const noexcept
 
unsigned int getNumberOfBytes () const noexcept
 
bool isEmpty () const noexcept
 
unsigned int available () const
 
unsigned int read (uint8 *buffer, unsigned int size, bool nonblocking=false)
 
unsigned int skip (unsigned int count)
 
void wait () const
 
bool wait (unsigned int timeout) const
 
unsigned int peek (unsigned int count)
 
 ~BufferedInputStream ()
 
- Public Member Functions inherited from FilterInputStream
 FilterInputStream (InputStream &in)
 
unsigned int available () const
 
void close ()
 
unsigned int read (uint8 *buffer, unsigned int size, bool nonblocking=false)
 
unsigned int skip (unsigned int count)
 
void wait () const
 
bool wait (unsigned int timeout) const
 
- Public Member Functions inherited from Stream
virtual ~Stream () noexcept(false)
 
- Public Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject () noexcept
 
 ReferenceCountedObject (const ReferenceCountedObject &copy) noexcept
 
 ReferenceCountedObject (ReferenceCountedObject &&move) noexcept
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &copy) noexcept
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&move) noexcept
 
MemorySize getNumberOfReferences_INTERNAL () const noexcept
 
virtual bool useGarbageCollector () const noexcept
 
- Public Member Functions inherited from DynamicObject
 DynamicObject () noexcept
 
bool isValidObject () const noexcept
 
virtual ~DynamicObject () noexcept(false)
 
 _COM_AZURE_DEV__BASE__OVERRIDE_ALLOC ()
 

Static Public Attributes

static const unsigned int DEFAULT_BUFFER_SIZE = 4096
 
static const unsigned int MINIMUM_BUFFER_SIZE = 1024
 

Protected Attributes

Allocator< uint8 > buffer
 
unsigned int count = 0
 
unsigned int position = 0
 
- Protected Attributes inherited from FilterInputStream
InputStreamin
 

Detailed Description

Buffered input stream.

A FilterInputStream that adds buffer functionality to an InputStream for added performance. MT-unsafe implementation.

Version
1.0

Constructor & Destructor Documentation

◆ BufferedInputStream() [1/2]

BufferedInputStream::BufferedInputStream ( )

Initializes the buffered input stream.

◆ BufferedInputStream() [2/2]

BufferedInputStream::BufferedInputStream ( InputStream in,
unsigned int  size = DEFAULT_BUFFER_SIZE 
)

Initializes the buffered input stream.

Parameters
inThe input stream.
sizeThe size of the buffer. Default is given by DEFAULT_BUFFER_SIZE.

◆ ~BufferedInputStream()

BufferedInputStream::~BufferedInputStream ( )

Destroy buffered input stream.

Member Function Documentation

◆ available()

unsigned int BufferedInputStream::available ( ) const
virtual

Returns the number of bytes that can be read or skipped over without blocking.

Returns
Available number of bytes in stream.

Implements InputStream.

◆ fill()

void BufferedInputStream::fill ( )

Requests buffer to be filled.

◆ getElements()

const uint8* BufferedInputStream::getElements ( ) const
inlinenoexcept

Returns the unread bytes of the internal buffer as sequence. The size of the sequence is returned by getNumberOfBytes() or peek().

◆ getNumberOfBytes()

unsigned int BufferedInputStream::getNumberOfBytes ( ) const
inlinenoexcept

Returns the number of bytes currently available in the internal buffer. This is not the same as available() which also includes buffered bytes of the linked input stream.

◆ isEmpty()

bool BufferedInputStream::isEmpty ( ) const
inlinenoexcept

Returns true if the internal buffer is empty.

◆ peek()

unsigned int BufferedInputStream::peek ( unsigned int  count)

This function ensures that the requested number of bytes is available in the internal buffer. Use getElements() afterwards to examine the content of the buffer.

Parameters
countThe number of bytes to peek ahead.
Returns
The number of bytes in the internal buffer (only less than the requested number of bytes if EOF is hit).

◆ read()

unsigned int BufferedInputStream::read ( uint8 *  buffer,
unsigned int  size,
bool  nonblocking = false 
)
virtual

Fills the specified buffer with bytes from the stream. Blocks if asked to read more bytes than available.

Parameters
bufferThe buffer to receive the bytes.
sizeThe size of the buffer.
nonblockingSpecifies that the method may not block. Default is false.
Returns
The actual number of bytes read from the stream.

Implements InputStream.

◆ skip()

unsigned int BufferedInputStream::skip ( unsigned int  count)
virtual

Skips a specified number of bytes. Blocks if asked to skip more bytes than available.

Parameters
countThe number of bytes to skip.
Returns
The actual number of bytes skipped.

Implements InputStream.

◆ wait() [1/2]

void BufferedInputStream::wait ( ) const
virtual

Blocking wait for input to become available.

Implements InputStream.

◆ wait() [2/2]

bool BufferedInputStream::wait ( unsigned int  timeout) const
virtual

Blocking wait for input to become available.

Parameters
timeoutThe timeout periode in microseconds.
Returns
True, if data is available. False, if the timeout periode expired.

Implements InputStream.

Member Data Documentation

◆ buffer

Allocator<uint8> BufferedInputStream::buffer
protected

The internal buffer used to store data temporarily.

◆ count

unsigned int BufferedInputStream::count = 0
protected

The current number of bytes in the buffer.

◆ DEFAULT_BUFFER_SIZE

const unsigned int BufferedInputStream::DEFAULT_BUFFER_SIZE = 4096
static

The default size of the buffer.

◆ MINIMUM_BUFFER_SIZE

const unsigned int BufferedInputStream::MINIMUM_BUFFER_SIZE = 1024
static

The minimum buffer size.

◆ position

unsigned int BufferedInputStream::position = 0
protected

The current position in the buffer.