protected void _readAllWriteStreamingCompressed3(InputStream in0, OutputStream out,
byte[] copyBuffer, StreamyBytesMemBuffer offHeap)
throws IOException
{
final CountingInputStream counter = new CountingInputStream(in0);
InputStream in = Compressors.uncompressingStream(counter, _compression);
// First: anything to skip (only the case for range requests)?
if (_dataOffset > 0L) {
long skipped = 0L;
long toSkip = _dataOffset;
final long start = (_diagnostics == null) ? 0L : _timeMaster.nanosForDiagnostics();
while (toSkip > 0) {
long count = in.skip(toSkip);
if (count <= 0L) { // should not occur really...
throw new IOException("Failed to skip more than "+skipped+" bytes (needed to skip "+_dataOffset+")");
}
skipped += count;
toSkip -= count;
}
if (_diagnostics != null) {
// assume here skipping is "free" (i.e. no bytes read)
_diagnostics.addFileReadAccess(start, _timeMaster, 0L);
}
}
// Second: output the whole thing, or just subset?
// TODO: buffer
if (_dataLength < 0) { // all of it
long prevCount = 0L;
while (true) {
final long start = _timeMaster.nanosForDiagnostics();
int count = in.read(copyBuffer);
if (_diagnostics != null) {
long newCount = counter.readCount();
_diagnostics.addFileReadAccess(start, _timeMaster, newCount-prevCount);
prevCount = newCount;
}
if (count <= 0) {
break;
}
final long outputStart = _timeMaster.nanosForDiagnostics();
out.write(copyBuffer, 0, count);
if (_diagnostics != null) {
_diagnostics.addResponseWriteTime(outputStart, _timeMaster);
}
}
return;
}
// Just some of it
long left = _dataLength;
// TODO: buffer
long prevCount = 0L;
while (left > 0) {
final long start = (_diagnostics == null) ? 0L : _timeMaster.nanosForDiagnostics();
int count = in.read(copyBuffer, 0, (int) Math.min(copyBuffer.length, left));
if (_diagnostics != null) {
long newCount = counter.readCount();
_diagnostics.addFileReadAccess(start, _timeMaster, newCount-prevCount);
prevCount = newCount;
}
if (count <= 0) {
break;