for (TarReader reader : readers) {
try {
ByteBuffer buffer = reader.readEntry(msb, lsb);
if (buffer != null) {
return new Segment(tracker, id, buffer);
}
} catch (IOException e) {
log.warn("Failed to read from tar file " + reader, e);
}
}
synchronized (this) {
try {
ByteBuffer buffer = writer.readEntry(msb, lsb);
if (buffer != null) {
return new Segment(tracker, id, buffer);
}
} catch (IOException e) {
log.warn("Failed to read from tar file " + writer, e);
}
}
// the writer might have switched to a new file,
// so we need to re-check the readers
for (TarReader reader : readers) {
try {
ByteBuffer buffer = reader.readEntry(msb, lsb);
if (buffer != null) {
return new Segment(tracker, id, buffer);
}
} catch (IOException e) {
log.warn("Failed to read from tar file " + reader, e);
}
}