BaseStreamInterface Class Reference

#include <iostreams.h>

Inheritance diagram for BaseStreamInterface:

Detailed Description

Interface is the base interface for all stream interfaces. It contains the general functions to work with streams (e.g. error handling).

Public Member Functions

MAXON_METHOD Result< Int64GetStreamLength () const
 
MAXON_METHOD Result< Int64GetPosition () const
 
MAXON_METHOD Result< void > Close ()
 
 MAXON_ADD_TO_REFERENCE_CLASS (Result< void > ResetMaybeClose() { Result< void > res=OK;if(this->GetPointer()) { if(System::GetReferenceCounter(this->GetPointer())==1) res=this->Close();this->ResetReference();} return res;})
 
MAXON_METHOD Bool SeekSupported () const
 
MAXON_METHOD Result< void > Seek (Int64 position)
 
MAXON_METHOD void DisableBuffering ()
 

Private Member Functions

 MAXON_INTERFACE (BaseStreamInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.basestream")
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( BaseStreamInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.basestream"   
)
private

◆ GetStreamLength()

MAXON_METHOD Result<Int64> GetStreamLength ( ) const

Returns the length of the stream/file. Be aware that some streams cannot return the file size (e.g. http streams with gzip+chunked transfer encoding). With this example code you can handle both cases correctly. In most cases it's better to not use GetStreamLength() and better use ReadEOS() to read as much as available.

iferr (Int size = stream.GetStreamLength())
{
if (!err.IsInstanceOf<UnknownFileSizeError>())
return err;
... handle unknown size case ...
}
else
{
... handle known size case ...
}
PyObject * stream
Definition: codecs.h:186
Py_ssize_t size
Definition: bytesobject.h:86
maxon::Int Int
Definition: ge_sys_math.h:64
#define iferr(...)
Definition: errorbase.h:388
Returns
Returns the length in bytes. UnknownFileSizeError is returned if the size is unknown.

◆ GetPosition()

MAXON_METHOD Result<Int64> GetPosition ( ) const

Returns the current stream position. This is the position where the next bytes will be read to or written from.

Returns
The current stream position.

◆ Close()

MAXON_METHOD Result<void> Close ( )

Closes the stream.

Returns
OK on success.

◆ MAXON_ADD_TO_REFERENCE_CLASS()

MAXON_ADD_TO_REFERENCE_CLASS ( Result< void > ResetMaybeClose() { Result< void > res=OK;if(this->GetPointer()) { if(System::GetReferenceCounter(this->GetPointer())==1) res=this->Close();this->ResetReference();} return res;}  )

◆ SeekSupported()

MAXON_METHOD Bool SeekSupported ( ) const

Returns if the stream supports Seek(). Please note that seeking in stream may effect performance because the caches will be flushed.

Returns
True if the output stream supports Seek().

◆ Seek()

MAXON_METHOD Result<void> Seek ( Int64  position)

Sets the read/write position to this absolute position from the beginning of the stream. For InputStreamInterface: If you want to Seek() forward Skip() is the preferred method to call from the performance perspective.

Parameters
[in]positionPosition to jump to within the stream.
Returns
OK on success.

◆ DisableBuffering()

MAXON_METHOD void DisableBuffering ( )

The stream may disable buffering when this routine is called (if it supports it). This method is typically used when the buffering is done from the outside.