34 : m_sContent(content) {
36 GetHeaders().Add(
"Content-Type",
"text/plain; charset=utf-8");
40 : m_sContent(content) {
42 String contentType = mediaType;
43 if (!contentType.
Contains(
"charset")) {
44 contentType = contentType +
"; charset=utf-8";
72 int len = m_sContent.GetLength();
74 stream->Write(m_sContent.GetRawString(), 0, len);
80 return m_sContent.GetLength();
86 : m_arrContent(content), m_iOffset(0), m_iCount(content.
GetLength()) {
88 GetHeaders().Add(
"Content-Type",
"application/octet-stream");
92 : m_arrContent(content), m_iOffset(offset), m_iCount(count) {
94 if (offset < 0 || count < 0 || offset + count > content.
GetLength()) {
95 throw ArgumentOutOfRangeException(
"Offset or count is out of range.");
97 GetHeaders().Add(
"Content-Type",
"application/octet-stream");
104 std::string temp(m_arrContent.GetData() + m_iOffset, m_iCount);
112 if (m_iOffset == 0 && m_iCount == m_arrContent.GetLength()) {
117 std::memcpy(arr.
GetData(), m_arrContent.GetData() + m_iOffset, m_iCount);
134 stream->Write(m_arrContent.GetData(), m_iOffset, m_iCount);
146 : m_pStream(stream) {
149 throw ArgumentNullException(
"stream");
151 GetHeaders().Add(
"Content-Type",
"application/octet-stream");
169 std::vector<char> vecData;
172 while ((iRead = m_pStream->Read(buf, 0,
sizeof(buf))) > 0) {
173 vecData.insert(vecData.end(), buf, buf + iRead);
176 if (!vecData.empty()) {
177 std::memcpy(arr.
GetData(), vecData.data(), vecData.size());
192 if (m_pStream.IsNull())
return;
196 while ((iRead = m_pStream->Read(buf, 0,
sizeof(buf))) > 0) {
197 stream->Write(buf, 0, iRead);
203 if (!m_pStream.IsNull() && m_pStream->CanSeek()) {
205 return m_pStream->GetLength();
Defines the exception thrown when a null reference is passed to a method that does not accept it.
Defines the exception thrown when an argument value is outside the acceptable range of values.
Represents an HTTP entity body and associated content headers.
ArgumentNullException(const String &sMessage)
Initializes a new instance of the ArgumentNullException class with a specified error message.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
T * GetData()
Gets a pointer to the contiguous internal element buffer.
Represents errors that occur during application execution.
Creates a stream whose backing store is memory.
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Copies the byte buffer into the target stream.
long GetLength() const override
Returns the byte count of the buffer slice.
String ReadAsString() override
Reads the byte buffer decoded as a string.
SmartPointer< IO::Stream > ReadAsStream() override
Reads the content as a MemoryStream.
ByteArrayContent(const Array< char > &content)
Initializes a new instance of ByteArrayContent with full byte buffer.
Array< char > ReadAsByteArray() override
Reads the content byte buffer.
virtual void CopyTo(const SmartPointer< IO::Stream > &stream)
Serializes the HTTP content to a stream.
virtual long GetLength() const
Gets the length in bytes of the HHTP content, or -1 if indeterminate.
virtual Array< char > ReadAsByteArray()=0
Serializes the HTTP content to a byte array.
Collections::Generic::Dictionary< String, String > & GetHeaders()
Gets the HTTP content headers defined in RFC 9110.
StreamContent(const SmartPointer< IO::Stream > &stream)
Initializes a new instance of StreamContent wrapping an existing Stream.
SmartPointer< IO::Stream > ReadAsStream() override
Returns the underlying stream.
Array< char > ReadAsByteArray() override
Reads the remaining bytes in the stream into a byte array.
long GetLength() const override
Gets the length of the underlying stream if seekable, or -1.
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Copies the underlying stream into the destination stream.
String ReadAsString() override
Reads the remaining bytes in the stream into a string.
Array< char > ReadAsByteArray() override
Reads the content payload as a byte array.
SmartPointer< IO::Stream > ReadAsStream() override
Reads the content payload as a readable MemoryStream.
String ReadAsString() override
Reads the content payload as a string.
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Writes the content string directly to the destination stream.
long GetLength() const override
Gets the length in bytes of the UTF-8 content string.
StringContent(const String &content)
Creates a new instance of StringContent with text/plain default media type.
A unified smart pointer that supports both unique and shared ownership semantics.
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String()
Initializes a new instance of the String class to an empty string.
bool Contains(char ch) const