* @param <V> the type of class
* @return an object
*/
public static <V> V read(ByteSource source, Class<V> cls, boolean returnNull) {
V object;
Closer closer = Closer.create();
try {
object = mapper.readValue(closer.register(source.openBufferedStream()), cls);
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
log.log(Level.INFO, "Failed to load" + cls.getCanonicalName(), e);
}
if (returnNull) {
return null;
}
try {
object = cls.newInstance();
} catch (InstantiationException e1) {
throw new RuntimeException(
"Failed to construct object with no-arg constructor", e1);
} catch (IllegalAccessException e1) {
throw new RuntimeException(
"Failed to construct object with no-arg constructor", e1);
}
} finally {
try {
closer.close();
} catch (IOException e) {
}
}
return object;