use of com.amazon.tools.comparisonReport.ComparisonResultType in project ion-java by amzn.
the class IonJavaCli method compareFiles.
//
//
// functions for comparing
//
//
private static void compareFiles(IonWriter ionWriterForOutput, IonWriter ionWriterForErrorReport, CommandArgs args, ComparisonType comparisonType) throws IOException {
List<String> files = args.getInputFiles();
CompareContext compareContext = new CompareContext(null, null);
compareContext.setType(args.getComparisonType());
for (String path : files) {
for (String compareToPath : files) {
compareContext.reset(path, compareToPath);
try (InputStream inputFirst = new BufferedInputStream(new FileInputStream(path));
IonReader ionReaderFirst = IonReaderBuilder.standard().build(inputFirst);
InputStream inputSecond = new BufferedInputStream(new FileInputStream(compareToPath));
IonReader ionReaderSecond = IonReaderBuilder.standard().build(inputSecond)) {
if (comparisonType == ComparisonType.BASIC) {
if (path.equals(compareToPath)) {
continue;
}
}
ReadContext readContextFirst = new ReadContext(new ArrayList<>());
ReadContext readContextSecond = new ReadContext(new ArrayList<>());
getEventStream(ionReaderFirst, CommandType.COMPARE, readContextFirst);
getEventStream(ionReaderSecond, CommandType.COMPARE, readContextSecond);
compareContext.setEventStreamFirst(readContextFirst.getEventStream());
compareContext.setEventStreamSecond(readContextSecond.getEventStream());
if (comparisonType != ComparisonType.BASIC) {
if (compareEquivs(compareContext) ^ (comparisonType == ComparisonType.EQUIVS || comparisonType == ComparisonType.EQUIVS_TIMELINE)) {
ComparisonResultType type = comparisonType == ComparisonType.NON_EQUIVS ? ComparisonResultType.EQUAL : ComparisonResultType.NOT_EQUAL;
writeReport(compareContext, ionWriterForOutput, type);
}
} else {
if (!compare(compareContext, 0, readContextFirst.getEventStream().size() - 1, 0, readContextSecond.getEventStream().size() - 1)) {
writeReport(compareContext, ionWriterForOutput, ComparisonResultType.NOT_EQUAL);
}
}
} catch (Exception e) {
new ErrorDescription(ErrorType.STATE, e.getMessage(), path + ';' + compareToPath, -1).writeOutput(ionWriterForErrorReport);
System.exit(IO_ERROR_EXIT_CODE);
}
}
}
}
Aggregations