Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jm::Stream Class Referenceabstract

The Stream class is an abstraction class for manipulating data streams through a unified interface. The stream itself can be a file, a byte array, a network interface, or anything else. More...

Inheritance diagram for jm::Stream:
jm::Object jm::File jm::MemoryStream jm::Resource

Public Member Functions

 Stream ()
 Constructor.
 
virtual size_t size () const =0
 Returns the length of the stream.
 
virtual Status open (FileMode mode)=0
 Opens the stream for read or write operations.
 
virtual bool isOpen ()=0
 Returns whether the file is open or not.
 
virtual bool canRead () const =0
 Checks if the file/stream can be read.
 
virtual void close ()=0
 Closes the stream if it was previously opened and releases any system resources.
 
virtual size_t read (uint8 *buffer, size_t length)=0
 Reads a maximum of length bytes into the array.
 
virtual size_t readFully (ByteArray &buffer, size_t length)=0
 Reads a maximum of length bytes into the array.
 
size_t readFully (ByteArray &buffer)
 Reads a maximum of length bytes into the array.
 
virtual void seek (size_t position)=0
 Moves the file cursor to the desired position, counted from the beginning of the file (0-based index).
 
virtual void move (ssize_t offset)=0
 Moves the file cursor to the desired position, counted from the current position.
 
virtual size_t position ()=0
 Returns the current cursor position in the file.
 
virtual size_t write (const uint8 *buffer, size_t length)=0
 Writes a buffer to the output file.
 
size_t write (const int8 *buffer, size_t length)
 Writes a buffer to the output file.
 
size_t write (const String &string)
 Writes a string to the output file. The encoding is the default encoding (UTF-8). NOT AS A C-STRING!
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 

Detailed Description

The Stream class is an abstraction class for manipulating data streams through a unified interface. The stream itself can be a file, a byte array, a network interface, or anything else.

The Stream class provides methods for reading and writing data, as well as managing the stream's state.

Constructor & Destructor Documentation

◆ Stream()

jm::Stream::Stream ( )

Constructor.

Member Function Documentation

◆ canRead()

virtual bool jm::Stream::canRead ( ) const
pure virtual

Checks if the file/stream can be read.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ close()

virtual void jm::Stream::close ( )
pure virtual

Closes the stream if it was previously opened and releases any system resources.

This method closes the stream if it was previously opened and releases any system resources associated with it.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ isOpen()

virtual bool jm::Stream::isOpen ( )
pure virtual

Returns whether the file is open or not.

This method returns a boolean value indicating whether the file is currently open or not.

Returns
true if the file is open, false otherwise.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ move()

virtual void jm::Stream::move ( ssize_t  offset)
pure virtual

Moves the file cursor to the desired position, counted from the current position.

This method moves the file cursor to the specified position, counted from the current position.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ open()

virtual Status jm::Stream::open ( FileMode  mode)
pure virtual

Opens the stream for read or write operations.

Parameters
modeThe mode to open the stream.

This method opens the stream for read or write operations based on the specified mode.

Returns
The status of the operation.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ position()

virtual size_t jm::Stream::position ( )
pure virtual

Returns the current cursor position in the file.

Note
Not every stream supports this method.

This method returns the current cursor position in the file.

Returns
The current cursor position.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ read()

virtual size_t jm::Stream::read ( uint8 *  buffer,
size_t  length 
)
pure virtual

Reads a maximum of length bytes into the array.

For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call readFully().

Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implemented in jm::MemoryStream, jm::Resource, and jm::File.

◆ readFully() [1/2]

size_t jm::Stream::readFully ( ByteArray buffer)

Reads a maximum of length bytes into the array.

Parameters
bufferThe buffer to read the data from.
Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

◆ readFully() [2/2]

virtual size_t jm::Stream::readFully ( ByteArray buffer,
size_t  length 
)
pure virtual

Reads a maximum of length bytes into the array.

For large blocks, it is possible that not all bytes are read because it is still waiting for data. In this case, only a portion may be returned. If you want to ensure that all data is read, you should call readFully().

Parameters
bufferThe buffer to read the data from.
lengthThe maximum number of bytes to read.
Returns
The actual number of bytes read, or 0 if no bytes were read (EOF).

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ seek()

virtual void jm::Stream::seek ( size_t  position)
pure virtual

Moves the file cursor to the desired position, counted from the beginning of the file (0-based index).

Note
Not every stream supports this method.

This method moves the file cursor to the specified position, counted from the beginning of the file.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ size()

virtual size_t jm::Stream::size ( ) const
pure virtual

Returns the length of the stream.

This method returns the length of the stream in bytes.

Returns
The length of the stream.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.

◆ write() [1/3]

size_t jm::Stream::write ( const int8 *  buffer,
size_t  length 
)

Writes a buffer to the output file.

This method writes the contents of the buffer to the output file.

Parameters
bufferThe buffer containing the data to be written.
lengthThe number of bytes to write from the buffer.
Returns
The actual number of bytes written.

◆ write() [2/3]

size_t jm::Stream::write ( const String string)

Writes a string to the output file. The encoding is the default encoding (UTF-8). NOT AS A C-STRING!

This method writes the specified string to the output file using the default encoding, which is UTF-8. The string should not be passed as a C-string.

◆ write() [3/3]

virtual size_t jm::Stream::write ( const uint8 *  buffer,
size_t  length 
)
pure virtual

Writes a buffer to the output file.

This method writes the contents of the buffer to the output file.

Parameters
bufferThe buffer containing the data to be written.
lengthThe number of bytes to write from the buffer.
Returns
The actual number of bytes written.

Implemented in jm::File, jm::MemoryStream, and jm::Resource.