use of com.amazon.tools.errorReport.ErrorDescription in project ion-java by amzn.
the class IonJavaCli method processFiles.
//
//
// functions for processing
//
//
private static void processFiles(IonWriter ionWriterForErrorReport, CommandArgs args, ProcessContext processContext) throws IOException {
boolean finish = false;
for (String path : args.getInputFiles()) {
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(path));
IonReader ionReader = IonReaderBuilder.standard().build(inputStream)) {
processContext.setFileName(path);
ReadContext readContext = new ReadContext(new ArrayList<>());
try {
getEventStream(ionReader, CommandType.PROCESS, readContext);
} catch (IonException | NullPointerException e) {
new ErrorDescription(readContext.getState(), e.getMessage(), processContext.getFileName(), processContext.getEventIndex()).writeOutput(ionWriterForErrorReport);
finish = true;
} catch (Exception e) {
new ErrorDescription(ErrorType.STATE, e.getMessage(), processContext.getFileName(), processContext.getEventIndex()).writeOutput(ionWriterForErrorReport);
finish = true;
}
processContext.setEventStream(readContext.getEventStream());
processContext.setEventIndex(0);
if (args.getOutputFormat() == OutputFormat.EVENTS) {
processContext.getIonWriter().writeSymbol(EVENT_STREAM);
processToEventStream(ionWriterForErrorReport, processContext);
} else {
processToIonStream(processContext, args);
}
if (finish)
System.exit(IO_ERROR_EXIT_CODE);
processContext.getIonWriter().finish();
ionWriterForErrorReport.finish();
} catch (IonException | NullPointerException e) {
new ErrorDescription(processContext.getState(), e.getMessage(), processContext.getFileName(), processContext.getEventIndex()).writeOutput(ionWriterForErrorReport);
System.exit(IO_ERROR_EXIT_CODE);
} catch (Exception e) {
new ErrorDescription(ErrorType.STATE, e.getMessage(), processContext.getFileName(), processContext.getEventIndex()).writeOutput(ionWriterForErrorReport);
System.exit(IO_ERROR_EXIT_CODE);
}
}
}
use of com.amazon.tools.errorReport.ErrorDescription 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