28 dataSize (sourceDataSize)
32 internalCopy =
MemoryBlock (sourceData, sourceDataSize);
39 dataSize (sourceData.getSize())
43 internalCopy = sourceData;
49 : internalCopy (
std::move (source))
60 return (int64) dataSize;
65 jassert (buffer !=
nullptr && howMany >= 0);
67 if (howMany <= 0 || position >= dataSize)
70 auto num = jmin ((
size_t) howMany, dataSize - position);
74 memcpy (buffer, addBytesToPointer (data, position), num);
83 return position >= dataSize;
88 position = (size_t) jlimit ((int64) 0, (int64) dataSize, pos);
94 return (int64) position;
99 if (numBytesToSkip > 0)
108 class MemoryStreamTests :
public UnitTest 112 :
UnitTest (
"MemoryInputStream & MemoryOutputStream", UnitTestCategories::streams)
115 void runTest()
override 117 beginTest (
"Basics");
123 String randomString (createRandomWideCharString (r));
136 expect (mi.readInt() == randomInt);
137 expect (mi.readIntBigEndian() == randomInt);
138 expect (mi.readCompressedInt() == randomInt);
139 expectEquals (mi.readString(), randomString);
140 expect (mi.readInt64() == randomInt64);
141 expect (mi.readInt64BigEndian() == randomInt64);
142 expect (mi.readDouble() == randomDouble);
143 expect (mi.readDoubleBigEndian() == randomDouble);
145 const MemoryBlock data (
"abcdefghijklmnopqrstuvwxyz", 26);
155 size_t numBytesRead = 0;
158 while (numBytesRead < data.getSize())
160 numBytesRead += (size_t) stream.
read (&readBuffer[numBytesRead], 3);
162 expectEquals (stream.
getPosition(), (int64) numBytesRead);
164 expect (stream.
isExhausted() == (numBytesRead == data.getSize()));
167 expectEquals (stream.
getPosition(), (int64) data.getSize());
171 expect (readBuffer == data);
182 const int numBytesToSkip = 5;
184 while (numBytesRead < data.getSize())
187 numBytesRead += numBytesToSkip;
188 numBytesRead = std::min (numBytesRead, data.getSize());
190 expectEquals (stream.
getPosition(), (int64) numBytesRead);
192 expect (stream.
isExhausted() == (numBytesRead == data.getSize()));
195 expectEquals (stream.
getPosition(), (int64) data.getSize());
202 juce_wchar buffer [50] = { 0 };
204 for (
int i = 0; i < numElementsInArray (buffer) - 1; ++i)
210 buffer[i] = (juce_wchar) (1 + r.
nextInt (0x10ffff - 1));
215 buffer[i] = (juce_wchar) (1 + r.
nextInt (0xff));
222 static MemoryStreamTests memoryInputStreamUnitTests;
virtual bool writeDoubleBigEndian(double value)
static bool canRepresent(juce_wchar character) noexcept
int64 nextInt64() noexcept
virtual bool writeInt64BigEndian(int64 value)
const void * getData() const noexcept
void * getData() noexcept
virtual bool writeIntBigEndian(int value)
double nextDouble() noexcept
virtual bool writeInt64(int64 value)
size_t getDataSize() const noexcept
virtual bool writeDouble(double value)
virtual bool writeInt(int value)
virtual bool writeCompressedInt(int value)
virtual bool writeString(const String &text)