27 int64 start, int64 length,
30 startPositionInSourceStream (start),
31 lengthOfSourceStream (length)
42 auto srcLen = source->getTotalLength() - startPositionInSourceStream;
44 return lengthOfSourceStream >= 0 ? jmin (lengthOfSourceStream,
srcLen)
50 return source->getPosition() - startPositionInSourceStream;
55 return source->setPosition (jmax ((int64) 0,
newPosition + startPositionInSourceStream));
62 if (lengthOfSourceStream < 0)
75 if (lengthOfSourceStream >= 0 &&
getPosition() >= lengthOfSourceStream)
78 return source->isExhausted();
87 :
UnitTest (
"SubregionInputStream",
"Streams")
90 void runTest()
override
92 const MemoryBlock
data (
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", 52);
93 MemoryInputStream
mi (
data,
true);
95 const int offset = getRandom().nextInt ((
int)
data.getSize());
102 expectEquals (stream.getPosition(), (int64) 0);
103 expectEquals (stream.getTotalLength(), (int64)
subregionSize);
104 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
105 expect (! stream.isExhausted());
114 expectEquals (stream.getPosition(), (int64)
numBytesRead);
120 expectEquals (stream.getNumBytesRemaining(), (int64) 0);
121 expect (stream.isExhausted());
128 stream.setPosition (0);
129 expectEquals (stream.getPosition(), (int64) 0);
130 expectEquals (stream.getTotalLength(), (int64)
subregionSize);
131 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
132 expect (! stream.isExhausted());
143 expectEquals (stream.getPosition(), (int64)
numBytesRead);
149 expectEquals (stream.getNumBytesRemaining(), (int64) 0);
150 expect (stream.isExhausted());
154static SubregionInputStreamTests subregionInputStreamTests;
Holds a resizable array of primitive or copy-by-value objects.
ElementType * begin() const noexcept
Returns a pointer to the first element in the array.
Array()=default
Creates an empty array.
ElementType * data() const noexcept
Returns a pointer to the first element in the array.
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.