4#include <system/io/stream.h>
5#include <system/io/file_mode.h>
6#include <system/io/file_access.h>
7#include <system/io/file_share.h>
8#include <system/io/file_options.h>
9#include <system/io/seekorigin.h>
10#include <system/reflection.h>
11#include <system/nullable.h>
15namespace System {
namespace IO {
17namespace Details {
class FileWrapper; }
28 static constexpr int32_t DefaultBufferSize = 4096;
46 int32_t buffer_size = DefaultBufferSize,
68 ASPOSECPP_SHARED_API int64_t
get_Length()
const override;
81 ASPOSECPP_SHARED_API
void Close()
override;
84 ASPOSECPP_SHARED_API
void Flush()
override;
89 ASPOSECPP_SHARED_API
void Flush(
bool flush_to_disk);
93 ASPOSECPP_SHARED_API int32_t
ReadByte()
override;
110 ASPOSECPP_SHARED_API
void SetLength(int64_t value)
override;
114 ASPOSECPP_SHARED_API
void WriteByte(uint8_t value)
override;
127 ASPOSECPP_SHARED_API int32_t
Read(
const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count)
override;
133 ASPOSECPP_SHARED_API
void Write(
const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count)
override;
137 std::unique_ptr<Details::FileWrapper> m_file;
155 std::vector<uint8_t> m_buffer;
158 const int32_t m_buffer_size;
161 int32_t m_write_pos = 0;
164 int32_t m_read_pos = 0;
167 int32_t m_read_length = 0;
170 int64_t m_file_pos = 0;
173 int64_t m_file_start_pos = 0;
175 void VerifyIntegrity()
const;
176 void VerifyOpen()
const;
177 void VerifyReadable()
const;
178 void VerifyWriteable()
const;
179 void VerifySeekable()
const;
182 void FlushReadBuffer();
185 void FlushWriteBuffer();
188 void FlushInternalBuffers();
191 void FillReadBuffer();
194 void CloseInternal();
Represents a file stream supporting synchronous and asynchronous read and write operations....
Definition: file_stream.h:24
void set_Position(int64_t value) override
Flushes the stream and then sets the stream's position.
String get_Name() const
Returns the name of the file encapsulated by the current FileStream object.
int32_t ReadByte() override
Reads a single byte from the stream and returns a 32-bit integer value equivalent to the value of the...
bool get_CanRead() const override
Determines if the stream is readable.
FileStream(const FileStream &)=delete
void Flush() override
Clears this stream's buffers and writes all buffered data to the underlying file.
void Write(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
void Flush(bool flush_to_disk)
Clears this stream's buffers and writes all buffered data to the underlying file. Synonym for method ...
int64_t Seek(int64_t offset, SeekOrigin origin) override
Sets the position of the stream represented by the current object.
void Close() override
Closes the current FileStream object.
FileStream & operator=(const FileStream &)=delete
void Write(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Writes the specified subrange of bytes from the specified byte array to the stream.
bool get_CanSeek() const override
Determines if the stream supports seeking.
int64_t get_Length() const override
Returns the length of the stream in bytes.
void WriteByte(uint8_t value) override
Writes the specified unsigned 8-bit integer value to the stream.
int32_t Read(const ArrayPtr< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
int64_t get_Position() const override
Returns the current position of the stream.
bool get_CanWrite() const override
Determines if the stream is writable.
int32_t Read(const System::Details::ArrayView< uint8_t > &buffer, int32_t offset, int32_t count) override
Reads the specified number of bytes from the stream and writes them to the specified byte array.
FileStream(const String &path, FileMode mode)
Constructs a new instance of FileStream class and initializes it with the specified parameters.
FileStream(const String &path, FileMode mode, FileAccess access, FileShare share=FileShare::Read, int32_t buffer_size=DefaultBufferSize, FileOptions options=FileOptions::SequentialScan)
Constructs a new instance of FileStream class and initializes it with the specified parameters.
void SetLength(int64_t value) override
Sets the length of the stream represented by the current object.
A base class for a variety of stream implementations. Objects of this class should only be allocated ...
Definition: stream.h:24
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
FileOptions
Represents advanced options for creating FileStream object.
Definition: file_options.h:12
@ SequentialScan
The file shoud be accesses sequentially.
FileAccess
Specifies the type of access when opening the file.
Definition: file_access.h:11
FileShare
Specifies what kind of access other FileStream objects can have to a file being opened.
Definition: file_share.h:11
FileMode
Specifies how a file should be opened.
Definition: file_mode.h:10
SeekOrigin
Specifies the reference position in the stream relative to which the position to seek to is specified...
Definition: seekorigin.h:11
Definition: db_command.h:9