@Override
public RecordReader<Void, ObjectWritable> getRecordReader(final InputSplit split, JobConf jobConf, Reporter reporter)
throws IOException {
final RecordScannable recordScannable = DatasetAccessor.getRecordScannable(jobConf);
if (!(split instanceof DatasetInputSplit)) {
throw new IOException("Invalid type for InputSplit: " + split.getClass().getName());
}
final DatasetInputSplit datasetInputSplit = (DatasetInputSplit) split;
final RecordScanner recordScanner = recordScannable.createSplitRecordScanner(
new Split() {
@Override
public long getLength() {
try {
return split.getLength();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
);
return new RecordReader<Void, ObjectWritable>() {
private final AtomicBoolean initialized = new AtomicBoolean(false);
private void initialize() throws IOException {
try {
recordScanner.initialize(datasetInputSplit.getDataSetSplit());
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted while initializing reader", ie);
}
initialized.set(true);
}
@Override
public boolean next(Void key, ObjectWritable value) throws IOException {
if (!initialized.get()) {
initialize();
}
try {
boolean retVal = recordScanner.nextRecord();
if (retVal) {
value.set(recordScanner.getCurrentRecord());
}
return retVal;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
}
@Override
public Void createKey() {
return null;
}
@Override
public ObjectWritable createValue() {
return new ObjectWritable();
}
@Override
public long getPos() throws IOException {
// Not required.
return 0;
}
@Override
public void close() throws IOException {
try {
recordScanner.close();
} finally {
recordScannable.close();
}
}
@Override
public float getProgress() throws IOException {