27 : blockToUse (&internalBlock)
43 jassert (externalData !=
nullptr);
48 trimExternalBlockSize();
53 trimExternalBlockSize();
56void MemoryOutputStream::trimExternalBlockSize()
58 if (blockToUse != &internalBlock && blockToUse !=
nullptr)
59 blockToUse->
setSize (size,
false);
64 if (blockToUse !=
nullptr)
74char* MemoryOutputStream::prepareToWrite (
size_t numBytes)
76 jassert ((ssize_t) numBytes >= 0);
81 if (blockToUse !=
nullptr)
86 data =
static_cast<char*
> (blockToUse->
getData());
93 data =
static_cast<char*
> (externalData);
98 size =
jmax (size, position);
109 if (
auto* dest = prepareToWrite (
howMany))
123 if (
auto* dest = prepareToWrite (
howMany))
150 if (blockToUse ==
nullptr)
153 if (blockToUse->
getSize() > size)
154 static_cast<char*
> (blockToUse->
getData()) [size] = 0;
182 if (blockToUse !=
nullptr)
191 auto* d =
static_cast<const char*
> (
getData());
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
static size_t getBytesRequiredFor(const juce_wchar charToWrite) noexcept
Returns the number of bytes that would be needed to represent the given unicode character in this enc...
void write(const juce_wchar charToWrite) noexcept
Writes a unicode character to this string, and advances this pointer to point to the next position.
A class to hold a resizable block of raw data.
void * getData() noexcept
Returns a void pointer to the data.
size_t getSize() const noexcept
Returns the block's current allocated size, in bytes.
void setSize(size_t newSize, bool initialiseNewSpaceToZero=false)
Resizes the memory block.
void ensureSize(size_t minimumSize, bool initialiseNewSpaceToZero=false)
Increases the block's size only if it's smaller than a given size.
Writes data to an internal memory buffer, which grows as required.
const void * getData() const noexcept
Returns a pointer to the data that has been written to the stream.
~MemoryOutputStream() override
Destructor.
bool setPosition(int64) override
Tries to move the stream's output position.
String toUTF8() const
Returns a String created from the (UTF8) data that has been written to the stream.
String toString() const
Attempts to detect the encoding of the data and convert it to a string.
void flush() override
If the stream is writing to a user-supplied MemoryBlock, this will trim any excess capacity off the b...
size_t getDataSize() const noexcept
Returns the number of bytes of data that have been written to the stream.
bool writeRepeatedByte(uint8 byte, size_t numTimesToRepeat) override
Writes a byte to the output stream a given number of times.
void preallocate(size_t bytesToPreallocate)
Increases the internal storage capacity to be able to contain at least the specified amount of data w...
int64 writeFromInputStream(InputStream &, int64 maxNumBytesToWrite) override
Reads data from an input stream and writes it to this stream.
MemoryOutputStream(size_t initialSize=256)
Creates an empty memory stream, ready to be written into.
void reset() noexcept
Resets the stream, clearing any data that has been written to it so far.
bool write(const void *, size_t) override
Writes a block of data to the stream.
bool appendUTF8Char(juce_wchar character)
Appends the utf-8 bytes for a unicode character.
MemoryBlock getMemoryBlock() const
Returns a copy of the stream's data as a memory block.
The base class for streams that write data to some kind of destination.
virtual bool write(const void *dataToWrite, size_t numberOfBytes)=0
Writes a block of data to the stream.
virtual int64 writeFromInputStream(InputStream &source, int64 maxNumBytesToWrite)
Reads data from an input stream and writes it to this stream.
static String createStringFromData(const void *data, int size)
Creates a string from data in an unknown format.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
OutputStream &JUCE_CALLTYPE operator<<(OutputStream &stream, const BigInteger &value)
Writes a BigInteger to an OutputStream as a UTF8 decimal string.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.