if (schema == null) {
File schemaFile = new File(schemaDir, hash);
try {
schema = Schema.parse(new FileInputStream(schemaFile));
} catch (IOException ioe) {
throw new AvroBaseException("Failed to read schema for hash: " + hash + " row: " + row, ioe);
}
schemaCache.put(hash, schema);
hashCache.put(schema, hash);
}
try {
DecoderFactory decoderFactory = new DecoderFactory();
Decoder d;
switch (format) {
case JSON:
d = decoderFactory.jsonDecoder(schema, is);
break;
case BINARY:
default:
d = decoderFactory.binaryDecoder(is, null);
break;
}
// Read the data
SpecificDatumReader<T> sdr = new SpecificDatumReader<T>(schema);
sdr.setExpected(actualSchema);
return new Row<T, K>(sdr.read(null, d), row, version);
} catch (IOException e) {
throw new AvroBaseException("Failed to read file: " + schema, e);
} catch (AvroTypeException e) {
throw new AvroBaseException("Failed to read value: " + schema, e);
}
} finally {
channel.close();
is.close();
}