jaulib v1.1.2-28-g30efb27-dirty
Jau Support Library (C++, Java, ..)
Public Member Functions | List of all members
jau::io::ByteInStream_Recorder Class Referencefinal

Wrapped byte input stream with the capability to record the read byte stream at will. More...

#include <byte_stream.hpp>

Inheritance diagram for jau::io::ByteInStream_Recorder:
Collaboration diagram for jau::io::ByteInStream_Recorder:

Public Member Functions

 ByteInStream_Recorder (ByteInStream &parent, io::secure_vector< uint8_t > &buffer) noexcept
 Construct a byte input stream wrapper using the given parent ByteInStream. More...
 
 ByteInStream_Recorder (const ByteInStream_Recorder &)=delete
 
 ~ByteInStream_Recorder () noexcept override
 
bool available (size_t n) noexcept override
 Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source. More...
 
void clear (const iostate state=iostate::goodbit) noexcept override
 Clears state flags by assignment to the given value. More...
 
void clear_recording () noexcept
 Clears the recording. More...
 
void close () noexcept override
 Close the stream if supported by the underlying mechanism. More...
 
uint64_t content_size () const noexcept override
 Returns the content_size if known. More...
 
size_t get_bytes_recorded () noexcept
 
io::secure_vector< uint8_t > & get_recording () noexcept
 Returns the reference of the recording buffer given by user. More...
 
uint64_t get_recording_start_pos () noexcept
 Returns the recording start position. More...
 
bool has_content_size () const noexcept override
 Returns true if implementation is aware of content_size(), otherwise false. More...
 
std::string id () const noexcept override
 return the id of this data source More...
 
bool is_open () const noexcept override
 Checks if the stream has an associated file. More...
 
bool is_recording () noexcept
 
ByteInStream_Recorderoperator= (const ByteInStream_Recorder &)=delete
 
size_t peek (void *out, size_t length, size_t peek_offset) noexcept override
 Read from the source but do not modify the internal offset. More...
 
iostate rdstate () const noexcept override
 Returns the current state flags. More...
 
size_t read (void *, size_t) noexcept override
 Read from the source. More...
 
void start_recording () noexcept
 Starts the recording. More...
 
void stop_recording () noexcept
 Stops the recording. More...
 
uint64_t tellg () const noexcept override
 Returns the input position indicator, similar to std::basic_istream. More...
 
std::string to_string () const noexcept override
 
- Public Member Functions inherited from jau::io::ByteInStream
 ByteInStream () noexcept
 
 ByteInStream (const ByteInStream &)=delete
 
 ~ByteInStream () noexcept override=default
 
virtual bool available (size_t n) noexcept=0
 Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source. More...
 
virtual void close () noexcept=0
 Close the stream if supported by the underlying mechanism. More...
 
virtual uint64_t content_size () const noexcept=0
 Returns the content_size if known. More...
 
size_t discard (size_t N) noexcept
 Discard the next N bytes of the data. More...
 
virtual bool has_content_size () const noexcept=0
 Returns true if implementation is aware of content_size(), otherwise false. More...
 
virtual std::string id () const noexcept
 return the id of this data source More...
 
virtual bool is_open () const noexcept=0
 Checks if the stream has an associated file. More...
 
ByteInStreamoperator= (const ByteInStream &)=delete
 
bool peek (uint8_t &out) noexcept
 Peek at one byte. More...
 
virtual size_t peek (void *out, size_t length, size_t peek_offset) noexcept=0
 Read from the source but do not modify the internal offset. More...
 
bool read (uint8_t &out) noexcept
 Read one byte. More...
 
virtual size_t read (void *out, size_t length) noexcept=0
 Read from the source. More...
 
virtual uint64_t tellg () const noexcept=0
 Returns the input position indicator, similar to std::basic_istream. More...
 
virtual std::string to_string () const noexcept=0
 
- Public Member Functions inherited from jau::io::iostate_func
 iostate_func () noexcept
 
 iostate_func (const iostate_func &o) noexcept=default
 
 iostate_func (iostate_func &&o) noexcept=default
 
virtual ~iostate_func () noexcept=default
 
bool bad () const noexcept
 Checks if a non-recoverable error has occurred. More...
 
virtual void clear (const iostate state=iostate::goodbit) noexcept
 Clears state flags by assignment to the given value. More...
 
bool eof () const noexcept
 Checks if end-of-file has been reached. More...
 
bool fail () const noexcept
 Checks if an error has occurred. More...
 
bool good () const noexcept
 Checks if no error nor eof() has occurred i.e. More...
 
 operator bool () const noexcept
 Checks if no error has occurred, synonym of !fail(). More...
 
bool operator! () const noexcept
 Checks if an error has occurred, synonym of fail(). More...
 
iostate_funcoperator= (const iostate_func &o) noexcept=default
 
iostate_funcoperator= (iostate_func &&o) noexcept=default
 
virtual iostate rdstate () const noexcept
 Returns the current state flags. More...
 
void setstate (const iostate state) noexcept
 Sets state flags, by keeping its previous bits. More...
 
bool timeout () const noexcept
 Checks if a timeout (non-recoverable) has occurred. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jau::io::iostate_func
constexpr iostate rdstate_impl () const noexcept
 
constexpr void setstate_impl (iostate state) const noexcept
 

Detailed Description

Wrapped byte input stream with the capability to record the read byte stream at will.

Peek'ed bytes won't be recorded, only read bytes.

Definition at line 713 of file byte_stream.hpp.

Constructor & Destructor Documentation

◆ ByteInStream_Recorder() [1/2]

jau::io::ByteInStream_Recorder::ByteInStream_Recorder ( ByteInStream parent,
io::secure_vector< uint8_t > &  buffer 
)
inlinenoexcept

Construct a byte input stream wrapper using the given parent ByteInStream.

Parameters
parentthe parent ByteInStream
buffera user defined buffer for the recording

Definition at line 735 of file byte_stream.hpp.

◆ ByteInStream_Recorder() [2/2]

jau::io::ByteInStream_Recorder::ByteInStream_Recorder ( const ByteInStream_Recorder )
delete

◆ ~ByteInStream_Recorder()

jau::io::ByteInStream_Recorder::~ByteInStream_Recorder ( )
inlineoverridenoexcept

Definition at line 746 of file byte_stream.hpp.

Member Function Documentation

◆ read()

size_t ByteInStream_Recorder::read ( void *  out,
size_t  length 
)
overridevirtualnoexcept

Read from the source.

Moves the internal offset so that every call to read will return a new portion of the source.

Use available() to try to wait for a certain amount of bytes available.

This method shall only block until min(available, length) bytes are transfered.

See details of the implementing class.

Parameters
outthe byte array to write the result to
lengththe length of the byte array out
Returns
length in bytes that was actually read and put into out
See also
available()
ByteInStream Properties

Implements jau::io::ByteInStream.

Definition at line 613 of file byte_stream.cpp.

◆ peek()

size_t jau::io::ByteInStream_Recorder::peek ( void *  out,
size_t  length,
size_t  peek_offset 
)
inlineoverridevirtualnoexcept

Read from the source but do not modify the internal offset.

Consecutive calls to peek() will return portions of the source starting at the same position.

Parameters
outthe byte array to write the output to
lengththe length of the byte array out
peek_offsetthe offset into the stream to read at
Returns
length in bytes that was actually read and put into out

Implements jau::io::ByteInStream.

Definition at line 717 of file byte_stream.hpp.

◆ available()

bool jau::io::ByteInStream_Recorder::available ( size_t  n)
inlineoverridevirtualnoexcept

Return whether n bytes are available in the input stream, if has_content_size() or using an asynchronous source.

If !has_content_size() and not being an asynchronous source, !end_of_data() is returned.

Method may be blocking when using an asynchronous source up until the requested bytes are available.

A subsequent call to read() shall return immediately with at least the requested numbers of bytes available, if has_content_size() or using an asynchronous source.

See details of the implementing class.

Parameters
nbyte count to wait for
Returns
true if n bytes are available, otherwise false
See also
has_content_size()
read()
ByteInStream Properties

Implements jau::io::ByteInStream.

Definition at line 721 of file byte_stream.hpp.

◆ clear()

void jau::io::ByteInStream_Recorder::clear ( const iostate  state = iostate::goodbit)
inlineoverridevirtualnoexcept

Clears state flags by assignment to the given value.

Reimplemented from jau::io::iostate_func.

Definition at line 725 of file byte_stream.hpp.

◆ rdstate()

iostate jau::io::ByteInStream_Recorder::rdstate ( ) const
inlineoverridevirtualnoexcept

Returns the current state flags.

Method is marked virtual to allow implementations with asynchronous resources to determine or update the current iostate.

Method is used throughout all query members and setstate(), hence they all will use the updated state from a potential override implementation.

Reimplemented from jau::io::iostate_func.

Definition at line 726 of file byte_stream.hpp.

Here is the caller graph for this function:

◆ id()

std::string jau::io::ByteInStream_Recorder::id ( ) const
inlineoverridevirtualnoexcept

return the id of this data source

Returns
std::string representing the id of this data source

Reimplemented from jau::io::ByteInStream.

Definition at line 728 of file byte_stream.hpp.

◆ operator=()

ByteInStream_Recorder & jau::io::ByteInStream_Recorder::operator= ( const ByteInStream_Recorder )
delete

◆ is_open()

bool jau::io::ByteInStream_Recorder::is_open ( ) const
inlineoverridevirtualnoexcept

Checks if the stream has an associated file.

Implements jau::io::ByteInStream.

Definition at line 742 of file byte_stream.hpp.

◆ close()

void ByteInStream_Recorder::close ( )
overridevirtualnoexcept

Close the stream if supported by the underlying mechanism.

Implements jau::io::ByteInStream.

Definition at line 591 of file byte_stream.cpp.

◆ tellg()

uint64_t jau::io::ByteInStream_Recorder::tellg ( ) const
inlineoverridevirtualnoexcept

Returns the input position indicator, similar to std::basic_istream.

Returns
number of bytes read so far.

Implements jau::io::ByteInStream.

Definition at line 748 of file byte_stream.hpp.

◆ has_content_size()

bool jau::io::ByteInStream_Recorder::has_content_size ( ) const
inlineoverridevirtualnoexcept

Returns true if implementation is aware of content_size(), otherwise false.

See also
content_size()

Implements jau::io::ByteInStream.

Definition at line 750 of file byte_stream.hpp.

◆ content_size()

uint64_t jau::io::ByteInStream_Recorder::content_size ( ) const
inlineoverridevirtualnoexcept

Returns the content_size if known.

See also
has_content_size()

Implements jau::io::ByteInStream.

Definition at line 752 of file byte_stream.hpp.

◆ start_recording()

void ByteInStream_Recorder::start_recording ( )
noexcept

Starts the recording.

A potential previous recording will be cleared.

Definition at line 597 of file byte_stream.cpp.

◆ stop_recording()

void ByteInStream_Recorder::stop_recording ( )
noexcept

Stops the recording.

The recording persists.

Definition at line 603 of file byte_stream.cpp.

◆ clear_recording()

void ByteInStream_Recorder::clear_recording ( )
noexcept

Clears the recording.

If the recording was ongoing, also stops the recording.

Definition at line 607 of file byte_stream.cpp.

Here is the caller graph for this function:

◆ get_recording()

io::secure_vector< uint8_t > & jau::io::ByteInStream_Recorder::get_recording ( )
inlinenoexcept

Returns the reference of the recording buffer given by user.

Definition at line 779 of file byte_stream.hpp.

◆ get_bytes_recorded()

size_t jau::io::ByteInStream_Recorder::get_bytes_recorded ( )
inlinenoexcept

Definition at line 781 of file byte_stream.hpp.

◆ get_recording_start_pos()

uint64_t jau::io::ByteInStream_Recorder::get_recording_start_pos ( )
inlinenoexcept

Returns the recording start position.

Definition at line 784 of file byte_stream.hpp.

◆ is_recording()

bool jau::io::ByteInStream_Recorder::is_recording ( )
inlinenoexcept

Definition at line 786 of file byte_stream.hpp.

◆ to_string()

std::string ByteInStream_Recorder::to_string ( ) const
overridevirtualnoexcept

Implements jau::io::ByteInStream.

Definition at line 623 of file byte_stream.cpp.


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