CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
http_content.h
1
2#pragma once
3
4#include <cstdint>
5#include <system/array.h>
6#include <system/exceptions.h>
7#include <system/idisposable.h>
8#include <system/io/memory_stream.h>
9#include <system/io/stream.h>
10#include <system/nullable.h>
11#include <system/object.h>
12#include <system/shared_ptr.h>
13#include <system/string.h>
14#include <system/text/encoding.h>
15
16#include <net/http/headers/http_content_headers.h>
17
18namespace System { namespace Net { namespace Http {
19
24class ABSTRACT ASPOSECPP_SHARED_CLASS HttpContent : public System::IDisposable
25{
27 typedef HttpContent ThisType;
30
32 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
34 ASPOSECPP_SHARED_RTTI_INFO_DECL();
35
36private:
38 class LimitMemoryStream : public System::IO::MemoryStream
39 {
41 typedef LimitMemoryStream ThisType;
44
46 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
48 ASPOSECPP_SHARED_RTTI_INFO_DECL();
49
50 public:
54 LimitMemoryStream(int32_t maxSize, int32_t capacity);
55
57 void Write(const ArrayPtr<uint8_t>& buffer, int32_t offset, int32_t count) override;
59 void Write(const System::Details::ArrayView<uint8_t>& buffer, int32_t offset, int32_t count) override;
61 void WriteByte(uint8_t value) override;
62
63 private:
65 int32_t _maxSize;
66
68 void CheckSize(int32_t countToAdd);
69 };
70
71public:
73 static const int64_t MaxBufferSize;
76
85 ASPOSECPP_SHARED_API String ReadAsString();
90 ASPOSECPP_SHARED_API void LoadIntoBuffer();
93 ASPOSECPP_SHARED_API void LoadIntoBuffer(int64_t maxBufferSize);
94
98 ASPOSECPP_SHARED_API virtual bool TryComputeLength(int64_t& length) = 0;
101 ASPOSECPP_SHARED_API void Dispose() override;
102
103protected:
112 virtual void Dispose(bool disposing);
113
114private:
120 bool _disposed;
122 System::SharedPtr<IO::Stream> _contentReadStream;
124 bool _canCalculateLength;
126 static const int32_t UTF8CodePage;
128 static const int32_t UTF8PreambleLength;
130 static const uint8_t UTF8PreambleByte0;
132 static const uint8_t UTF8PreambleByte1;
134 static const uint8_t UTF8PreambleByte2;
136 static const int32_t UTF8PreambleFirst2Bytes;
138 static const int32_t UTF32CodePage;
140 static const int32_t UTF32PreambleLength;
142 static const uint8_t UTF32PreambleByte0;
144 static const uint8_t UTF32PreambleByte1;
146 static const uint8_t UTF32PreambleByte2;
148 static const uint8_t UTF32PreambleByte3;
150 static const int32_t UTF32OrUnicodePreambleFirst2Bytes;
152 static const int32_t UnicodeCodePage;
154 static const int32_t UnicodePreambleLength;
156 static const uint8_t UnicodePreambleByte0;
158 static const uint8_t UnicodePreambleByte1;
160 static const int32_t BigEndianUnicodeCodePage;
162 static const int32_t BigEndianUnicodePreambleLength;
164 static const uint8_t BigEndianUnicodePreambleByte0;
166 static const uint8_t BigEndianUnicodePreambleByte1;
168 static const int32_t BigEndianUnicodePreambleFirst2Bytes;
169
171 bool get_IsBuffered();
172
175 Nullable<int64_t> GetComputedOrBufferLength();
177 virtual System::SharedPtr<IO::Stream> CreateContentReadStream();
178
181 System::SharedPtr<IO::MemoryStream> CreateMemoryStream(int64_t maxBufferSize);
187 void CheckDisposed();
191 static Exception GetStreamCopyException(Exception originalException);
197 static int32_t GetPreambleLength(System::ArrayPtr<uint8_t> data, int32_t dataLength,
205 static bool TryDetectEncoding(System::ArrayPtr<uint8_t> data, int32_t dataLength,
206 System::SharedPtr<Text::Encoding>& encoding, int32_t& preambleLength);
212 static bool ByteArrayHasPrefix(System::ArrayPtr<uint8_t> byteArray, int32_t dataLength,
214};
215
216}}} // namespace System::Net::Http
Template that represents wrapper of exceptions that are derived from Exception class.
Definition: exception.h:113
Defines method that releases resources owned by the current object. Objects of this class should only...
Definition: idisposable.h:30
Represents a stream that reads from and writes to memory. Objects of this class should only be alloca...
Definition: memory_stream.h:19
Represents content of an HTTP entity. Object of this class should only be allocated using System::Mak...
Definition: http_content.h:25
void LoadIntoBuffer()
Serializes content to a memory buffer.
System::SharedPtr< Headers::HttpContentHeaders > get_Headers()
Returns the HTTP content headers.
virtual void Dispose(bool disposing)
Disposes the current instance. This method also disposes the stream that is returned by 'ReadAsStream...
static System::SharedPtr< Text::Encoding > DefaultStringEncoding
The default encoding.
Definition: http_content.h:75
virtual void SerializeToStream(System::SharedPtr< IO::Stream > stream)=0
Serializes content to a stream.
void Dispose() override
Disposes the current instance. This method also disposes the stream that is returned by 'ReadAsStream...
virtual bool TryComputeLength(int64_t &length)=0
Tries to calculate the content size.
void LoadIntoBuffer(int64_t maxBufferSize)
Serializes content to a memory buffer.
String ReadAsString()
Serializes content and returns a string.
System::SharedPtr< IO::Stream > ReadAsStream()
Serializes content and returns a stream.
System::ArrayPtr< uint8_t > ReadAsByteArray()
Serializes content and returns a byte array.
static const int64_t MaxBufferSize
The maximum number of bytes.
Definition: http_content.h:73
HttpContent()
Constructs a new instance.
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
Definition: db_command.h:9