PLCnext API Documentation 25.0.2.69
Public Types | Public Member Functions | List of all members
Arp::System::Commons::Io::FileStream Class Reference

Exposes a Stream around a file, supporting read and write operations. More...

#include <FileStream.hpp>

Inheritance diagram for Arp::System::Commons::Io::FileStream:
Inheritance graph

Public Types

using IFileService = Arp::System::Ve::IFileService
 

Public Member Functions

 FileStream (const String &path, FileMode mode)
 Initializes a new instance of the FileStream class. More...
 
 FileStream (const String &path, FileMode mode, FileAccess access)
 Initializes a new instance of the FileStream class. After close operation, the synchronization of the file system will be enforced for this file. More...
 
 FileStream (const String &path, FileMode mode, FileAccess access, bool sync)
 Initializes a new instance of the FileStream class. More...
 
 FileStream (const FileStream &arg)=delete
 Copy constructor.
 
FileStreamoperator= (const FileStream &arg)=delete
 Assignment operator.
 
 ~FileStream (void) override
 Destructs this instance and frees all resources.
 
size_t GetLength (void)
 Returns the size of the opened file in bytes. More...
 
void SetLength (size_t length)
 Reserves a specific amount of bytes for the opened file. More...
 
size_t GetPosition (void) override
 Returns the byte offset of the internal stream pointer from the beginning of the file. More...
 
void SetPosition (size_t position) override
 Sets a new position of the internal stream pointer. More...
 
void Flush (void) override
 Forces a write of all possibly buffered data (input stream) or discards any buffered not yet read by the user (output stream). More...
 
size_t Seek (size_t offset, SeekOrigin origin) override
 Sets a new position if the internal stream pointer relative to a specific position. More...
 
size_t Read (byte *pBuffer, size_t bufferSize, size_t offset, size_t count) override
 Reads data from stream into assigned buffer at a specific offset. More...
 
void Write (const byte *pBuffer, size_t bufferSize, size_t offset, size_t count) override
 Writes data from assigned buffer to stream. More...
 
void Close (void)
 
- Public Member Functions inherited from Arp::Base::Commons::Io::Stream
 Stream (bool canRead=false, bool canWrite=false, bool canSeek=false)
 This constructor is used to constructs a base stream instance. More...
 
 Stream (const Stream &arg)
 Default copy constructor. More...
 
 Stream (Stream &&arg) noexcept
 Default move constructor. More...
 
Streamoperator= (const Stream &arg)
 Default copy-assignment operator. More...
 
Streamoperator= (Stream &&arg) noexcept
 Default move-assignment operator. More...
 
virtual ~Stream (void)
 Default destructor.
 
virtual bool CanRead (void)
 Determines if the derived stream can read. More...
 
virtual bool CanWrite (void)
 Determines if the derived stream can write. More...
 
virtual bool CanSeek (void)
 Determines if the derived stream can seek. More...
 
virtual void SetPosition (size_t value)
 Sets the position of the stream, if it can seek. More...
 
virtual size_t GetPosition (void)
 Gets the position of the stream, if it can seek. More...
 
virtual size_t Seek (size_t offset, SeekOrigin origin)=0
 
virtual size_t Read (byte *pBuffer, size_t bufferSize, size_t bufferOffset, size_t count)=0
 
virtual void Write (const byte *pBuffer, size_t bufferSize, size_t bufferOffset, size_t count)=0
 
virtual void Flush (void)=0
 
virtual byte ReadByte (void)
 Reads a single byte from the stream. More...
 
virtual void WriteByte (byte value)
 Writes a single byte to the stream. More...
 
virtual void WriteTo (Stream &other)
 Writes the data this stream to another stream entirely. More...
 
virtual void ReadFrom (Stream &other)
 Reads the entire data from another stream into this stream. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Arp::Base::Commons::Io::Stream
static StreamGetEmpty (void)
 Gets an empty stream. More...
 

Detailed Description

Exposes a Stream around a file, supporting read and write operations.

Constructor & Destructor Documentation

◆ FileStream() [1/3]

Arp::System::Commons::Io::FileStream::FileStream ( const String path,
FileMode  mode 
)

Initializes a new instance of the FileStream class.

The file is opened or created with read-write permissions.

Parameters
pathThe path of the file to open..
modeThe open mode.
Exceptions
Arp::System::Commons::ArgumentExceptionif path is an empty string.
Arp::System::Commons::Io::AlreadyExistsExceptionif #Arp::Syste::Commons::Io::FileMode::CreateNew is chosen and the file does already exists.
Arp::System::Commons::Io::NotExistExceptionif a file should be opened that does not exist.
Arp::System::Commons::Io::InvalidPathExceptionin case an error occured that is not already handled by the other exceptions.

◆ FileStream() [2/3]

Arp::System::Commons::Io::FileStream::FileStream ( const String path,
FileMode  mode,
FileAccess  access 
)

Initializes a new instance of the FileStream class. After close operation, the synchronization of the file system will be enforced for this file.

Parameters
pathThe path of the file to open..
modeThe open mode.
accessThe access mode.
Exceptions
Arp::System::Commons::ArgumentExceptionif path is an empty string.
Arp::System::Commons::Io::AlreadyExistsExceptionif #Arp::Syste::Commons::Io::FileMode::CreateNew is chosen and the file does already exists.
Arp::System::Commons::Io::NotExistExceptionif a file should be opened that does not exist.
Arp::System::Commons::Io::InvalidPathExceptionin case an error occured that is not already handled by the other exceptions.

◆ FileStream() [3/3]

Arp::System::Commons::Io::FileStream::FileStream ( const String path,
FileMode  mode,
FileAccess  access,
bool  sync 
)

Initializes a new instance of the FileStream class.

Parameters
pathThe path of the file to open..
modeThe open mode.
accessThe access mode.
syncIf set to true, the synchronization of the file system is enforced after close operation for this file.
Exceptions
Arp::System::Commons::ArgumentExceptionif path is an empty string.
Arp::System::Commons::Io::AlreadyExistsExceptionif #Arp::Syste::Commons::Io::FileMode::CreateNew is chosen and the file does already exists.
Arp::System::Commons::Io::NotExistExceptionif a file should be opened that does not exist.
Arp::System::Commons::Io::InvalidPathExceptionin case an error occured that is not already handled by the other exceptions.

Member Function Documentation

◆ Flush()

void Arp::System::Commons::Io::FileStream::Flush ( void  )
overridevirtual

Forces a write of all possibly buffered data (input stream) or discards any buffered not yet read by the user (output stream).

Exceptions
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.

Implements Arp::Base::Commons::Io::Stream.

◆ GetLength()

size_t Arp::System::Commons::Io::FileStream::GetLength ( void  )

Returns the size of the opened file in bytes.

Exceptions
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Returns
Byte size of opened file.

◆ GetPosition()

size_t Arp::System::Commons::Io::FileStream::GetPosition ( void  )
overridevirtual

Returns the byte offset of the internal stream pointer from the beginning of the file.

The next read or write operation will be performed from this byte offset on.

Exceptions
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Returns
Byte offset from file beginning of internal stream pointer.

Reimplemented from Arp::Base::Commons::Io::Stream.

◆ Read()

size_t Arp::System::Commons::Io::FileStream::Read ( byte *  pBuffer,
size_t  bufferSize,
size_t  offset,
size_t  count 
)
overridevirtual

Reads data from stream into assigned buffer at a specific offset.

Parameters
pBufferBuffer where read data can be stored.
bufferSizeMaximal capacity of buffer pBuffer.
offsetOffset in pBuffer where read data should be stored.
countAmount of bytes to read from stream.
Exceptions
Arp::System::Commons::ArgumentNullExceptionif pBuffer is nullptr.
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Arp::System::Commons::ArgumentOutOfRangeExceptionif offset plus count is greater than bufferSize.
Arp::System::Commons::NotSupportedExceptionif this stream is not readable.
Returns
The number of bytes read from stream and stored in assigned buffer.

Implements Arp::Base::Commons::Io::Stream.

◆ Seek()

size_t Arp::System::Commons::Io::FileStream::Seek ( size_t  offset,
SeekOrigin  origin 
)
override

Sets a new position if the internal stream pointer relative to a specific position.

Parameters
offsetOffset in byte from the reference position, can also be negativ.
originReference from where the offset is added to calculate the new position of the file stream pointer.
Exceptions
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Returns
The new offset in bytes from the beginning of the stream.

◆ SetLength()

void Arp::System::Commons::Io::FileStream::SetLength ( size_t  length)

Reserves a specific amount of bytes for the opened file.

This method is not supported for FileStream class instances.

Exceptions
Arp::System::Commons::NotSupportedException
Parameters
lengthDesired byte-size of opened file.

◆ SetPosition()

void Arp::System::Commons::Io::FileStream::SetPosition ( size_t  position)
overridevirtual

Sets a new position of the internal stream pointer.

The assigned position value is interpreted as a byte offset from the beginning of the opened file.

Exceptions
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Parameters
positionByte-offset for the internal stream pointer from the beginning of the file.

Reimplemented from Arp::Base::Commons::Io::Stream.

◆ Write()

void Arp::System::Commons::Io::FileStream::Write ( const byte *  pBuffer,
size_t  bufferSize,
size_t  offset,
size_t  count 
)
overridevirtual

Writes data from assigned buffer to stream.

Parameters
pBufferPointer to data-location.
bufferSizeAmount of bytes stored inpBuffer
offsetByte offset from location pBuffer where storing of data starts.
countAmount of bytes to be store via FileStream. Data from offset to offset + count will be stored.
Exceptions
Arp::System::Commons::ArgumentNullExceptionif pBuffer is nullptr.
Arp::System::Commons::ObjectDisposedExceptionif the stream was already disposed.
Arp::System::Commons::ArgumentOutOfRangeExceptionif offset plus count is greater than bufferSize.
Arp::System::Commons::NotSupportedExceptionif this stream is not writeable.
Returns
The number of bytes written to streamed file.

Implements Arp::Base::Commons::Io::Stream.


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