boolean ignoreTestLevel = !allClassOutput && testId == 0;
try {
dataFile.seek(region.start);
long maxPos = region.stop - region.start;
KryoBackedDecoder decoder = new KryoBackedDecoder(new RandomAccessFileInputStream(dataFile));
while (decoder.getReadPosition() <= maxPos) {
boolean readStdout = decoder.readBoolean();
long readClassId = decoder.readSmallLong();
long readTestId = decoder.readSmallLong();
int readLength = decoder.readSmallInt();
boolean isClassLevel = readTestId == 0;
if (stdout != readStdout || classId != readClassId) {
decoder.skipBytes(readLength);
continue;
}
if (ignoreClassLevel && isClassLevel) {
decoder.skipBytes(readLength);
continue;
}
if (ignoreTestLevel && !isClassLevel) {
decoder.skipBytes(readLength);
continue;
}
if (testId == 0 || testId == readTestId) {
byte[] stringBytes = new byte[readLength];
decoder.readBytes(stringBytes);
String message;
try {
message = new String(stringBytes, messageStorageCharset.name());
} catch (UnsupportedEncodingException e) {
// shouldn't happen
throw UncheckedException.throwAsUncheckedException(e);
}
writer.write(message);
} else {
decoder.skipBytes(readLength);
}
}
} catch (IOException e1) {
throw new UncheckedIOException(e1);
}