30 startPositionInSourceStream (start),
31 lengthOfSourceStream (length)
42 auto srcLen = source->getTotalLength() - startPositionInSourceStream;
44 return lengthOfSourceStream >= 0 ?
jmin (lengthOfSourceStream,
srcLen)
50 return source->getPosition() - startPositionInSourceStream;
62 if (lengthOfSourceStream < 0)
75 if (lengthOfSourceStream >= 0 &&
getPosition() >= lengthOfSourceStream)
78 return source->isExhausted();
92 void runTest()
override
94 const MemoryBlock data (
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52);
95 MemoryInputStream
mi (data,
true);
97 const int offset = getRandom().nextInt ((
int) data.getSize());
104 expectEquals (stream.getPosition(), (
int64) 0);
106 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
107 expect (! stream.isExhausted());
122 expectEquals (stream.getNumBytesRemaining(), (
int64) 0);
123 expect (stream.isExhausted());
130 stream.setPosition (0);
131 expectEquals (stream.getPosition(), (
int64) 0);
133 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
134 expect (! stream.isExhausted());
151 expectEquals (stream.getNumBytesRemaining(), (
int64) 0);
152 expect (stream.isExhausted());
SubregionStream(InputStream *sourceStream, int64 startPositionInSourceStream, int64 lengthOfSourceStream, bool deleteSourceWhenDestroyed)
Creates a SubregionStream from an input source.
int64 getPosition() override
Returns the offset of the next byte that will be read from the stream.
bool setPosition(int64 newPosition) override
Tries to move the current read position of the stream.
bool isExhausted() override
Returns true if the stream has no more data to read.
int read(void *destBuffer, int maxBytesToRead) override
Reads some data from the stream into a memory buffer.
int64 getTotalLength() override
Returns the total number of bytes available for reading in this stream.
~SubregionStream() override
Destructor.
This is a base class for classes that perform a unit test.
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 unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
long long int64
A platform-independent 64-bit integer type.