jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
File based byte input stream, including named file descriptor. More...
#include <byte_stream.hpp>
Public Member Functions | |
ByteInStream_File (const ByteInStream_File &)=delete | |
ByteInStream_File (const int dirfd, const std::string &path) noexcept | |
Construct a stream based byte input stream from filesystem path and parent directory file descriptor. More... | |
ByteInStream_File (const int fd) noexcept | |
Construct a stream based byte input stream by duplicating given file descriptor. More... | |
ByteInStream_File (const std::string &path) noexcept | |
Construct a stream based byte input stream from filesystem path. More... | |
~ByteInStream_File () 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 | 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... | |
int | fd () const noexcept |
Returns the file descriptor if is_open(), otherwise -1 for no file descriptor. 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... | |
ByteInStream_File & | operator= (const ByteInStream_File &)=delete |
size_t | peek (void *, size_t, size_t) noexcept override |
Read from the source but do not modify the internal offset. More... | |
size_t | read (void *, size_t) noexcept override |
Read from the source. 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... | |
ByteInStream & | operator= (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_func & | operator= (const iostate_func &o) noexcept=default |
iostate_func & | operator= (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 |
File based byte input stream, including named file descriptor.
Implementation mimics std::ifstream via OS level file descriptor (FD) operations, giving more flexibility, allowing reusing existing FD and enabling openat() operations.
If source path denotes a named file descriptor, i.e. jau::fs::file_stats::is_fd() returns true, has_content_size() returns false and available() returns true as long the stream is open and EOS hasn't occurred.
Definition at line 385 of file byte_stream.hpp.
|
noexcept |
Construct a stream based byte input stream from filesystem path.
In case the given path is a local file URI starting with file://
, see jau::io::uri::is_local_file_protocol(), the leading file://
is cut off and the remainder being used.
path | the path to the file, maybe a local file URI |
Definition at line 310 of file byte_stream.cpp.
|
noexcept |
Construct a stream based byte input stream from filesystem path and parent directory file descriptor.
In case the given path is a local file URI starting with file://
, see jau::io::uri::is_local_file_protocol(), the leading file://
is cut off and the remainder being used.
dirfd | parent directory file descriptor |
path | the path to the file, maybe a local file URI |
Definition at line 274 of file byte_stream.cpp.
|
noexcept |
Construct a stream based byte input stream by duplicating given file descriptor.
In case the given path is a local file URI starting with file://
, see jau::io::uri::is_local_file_protocol(), the leading file://
is cut off and the remainder being used.
fd | file descriptor to duplicate leaving the given fd untouched |
Definition at line 256 of file byte_stream.cpp.
|
delete |
|
inlineoverridenoexcept |
Definition at line 449 of file byte_stream.hpp.
|
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.
out | the byte array to write the result to |
length | the length of the byte array out |
Implements jau::io::ByteInStream.
Definition at line 180 of file byte_stream.cpp.
|
overridevirtualnoexcept |
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.
out | the byte array to write the output to |
length | the length of the byte array out |
peek_offset | the offset into the stream to read at |
Implements jau::io::ByteInStream.
Definition at line 211 of file byte_stream.cpp.
|
overridevirtualnoexcept |
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.
n | byte count to wait for |
Implements jau::io::ByteInStream.
Definition at line 252 of file byte_stream.cpp.
|
inlineoverridevirtualnoexcept |
Checks if the stream has an associated file.
Implements jau::io::ByteInStream.
Definition at line 401 of file byte_stream.hpp.
|
inlineoverridevirtualnoexcept |
return the id of this data source
Reimplemented from jau::io::ByteInStream.
Definition at line 403 of file byte_stream.hpp.
|
inlinenoexcept |
Returns the file descriptor if is_open(), otherwise -1 for no file descriptor.
Definition at line 410 of file byte_stream.hpp.
|
delete |
|
overridevirtualnoexcept |
Close the stream if supported by the underlying mechanism.
Implements jau::io::ByteInStream.
Definition at line 313 of file byte_stream.cpp.
|
inlineoverridevirtualnoexcept |
Returns the input position indicator, similar to std::basic_istream.
Implements jau::io::ByteInStream.
Definition at line 451 of file byte_stream.hpp.
|
inlineoverridevirtualnoexcept |
Returns true if implementation is aware of content_size(), otherwise false.
Implements jau::io::ByteInStream.
Definition at line 453 of file byte_stream.hpp.
|
inlineoverridevirtualnoexcept |
Returns the content_size if known.
Implements jau::io::ByteInStream.
Definition at line 455 of file byte_stream.hpp.
|
overridevirtualnoexcept |
Implements jau::io::ByteInStream.
Definition at line 321 of file byte_stream.cpp.