in spanner-data-validator-java/src/main/java/com/google/migration/dto/session/SessionFileReader.java [39:66]
private static Schema readFileIntoMemory(String filePath) {
try (InputStream stream =
Channels.newInputStream(FileSystems.open(FileSystems.matchNewResource(filePath, false)))) {
String result = IOUtils.toString(stream, StandardCharsets.UTF_8);
JsonParser parser = new JsonParser();
JsonObject sessionJSON = parser.parseString(result).getAsJsonObject();
validateSessionFields(sessionJSON);
Schema schema =
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create()
.fromJson(result, Schema.class);
schema.setEmpty(false);
schema.generateMappings();
LOG.debug("Read session file: " + schema.toString());
return schema;
} catch (IOException e) {
LOG.error(
"Failed to read session file. Make sure it is ASCII or UTF-8 encoded and contains a"
+ " well-formed JSON string.",
e);
throw new RuntimeException(
"Failed to read session file. Make sure it is ASCII or UTF-8 encoded and contains a"
+ " well-formed JSON string.",
e);
}
}