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());
90 if (storageNeeded > availableSize)
93 data =
static_cast<char*
> (externalData);
96 auto* writePointer = data + position;
98 size = jmax (size, position);
107 jassert (buffer !=
nullptr);
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;
164 position = jlimit ((
size_t) 0, size, (
size_t)
newPosition);
182 if (blockToUse !=
nullptr)
191 auto* d =
static_cast<const char*
> (
getData());
Holds a resizable array of primitive or copy-by-value objects.
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 ensureSize(const size_t minimumSize, bool initialiseNewSpaceToZero=false)
Increases the block's size only if it's smaller than a given size.
void setSize(const size_t newSize, bool initialiseNewSpaceToZero=false)
Resizes the memory block.
size_t getSize() const noexcept
Returns the block's current allocated size, in bytes.
void * getData() const noexcept
Returns a void pointer to the data.
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.