Loading...
Searching...
No Matches
juce_MemoryOutputStream.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API MemoryOutputStream : public OutputStream
{
public:
//==============================================================================
MemoryOutputStream (size_t initialSize = 256);
MemoryOutputStream (MemoryBlock& memoryBlockToWriteTo,
bool appendToExistingBlockContent);
MemoryOutputStream (void* destBuffer, size_t destBufferSize);
~MemoryOutputStream() override;
//==============================================================================
const void* getData() const noexcept;
size_t getDataSize() const noexcept { return size; }
void reset() noexcept;
void preallocate (size_t bytesToPreallocate);
bool appendUTF8Char (juce_wchar character);
String toUTF8() const;
String toString() const;
MemoryBlock getMemoryBlock() const;
//==============================================================================
void flush() override;
bool write (const void*, size_t) override;
int64 getPosition() override { return (int64) position; }
bool setPosition (int64) override;
int64 writeFromInputStream (InputStream&, int64 maxNumBytesToWrite) override;
bool writeRepeatedByte (uint8 byte, size_t numTimesToRepeat) override;
private:
//==============================================================================
MemoryBlock* const blockToUse = nullptr;
MemoryBlock internalBlock;
void* externalData = nullptr;
size_t position = 0, size = 0, availableSize = 0;
void trimExternalBlockSize();
char* prepareToWrite (size_t);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryOutputStream)
};
OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead);
} // namespace juce
juce::InputStream
Definition juce_InputStream.h:37
juce::MemoryBlock
Definition juce_MemoryBlock.h:33
juce::MemoryOutputStream
Definition juce_MemoryOutputStream.h:36
juce::MemoryOutputStream::getData
const void * getData() const noexcept
Definition juce_MemoryOutputStream.cpp:148
juce::MemoryOutputStream::getDataSize
size_t getDataSize() const noexcept
Definition juce_MemoryOutputStream.h:80
juce::MemoryOutputStream::MemoryOutputStream
MemoryOutputStream(size_t initialSize=256)
Definition juce_MemoryOutputStream.cpp:26
juce::MemoryOutputStream::getPosition
int64 getPosition() override
Definition juce_MemoryOutputStream.h:112
juce::String
Definition juce_String.h:53