Search in sources :

Example 1 with UnexpectedEndOfInputException

use of org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException in project neo4j by neo4j.

the class InputEntityDeserializer method deserializeNextFromSource.

private boolean deserializeNextFromSource() throws IOException {
    Header.Entry[] entries = header.entries();
    if (entries.length == 0) {
        return false;
    }
    int fieldIndex = 0;
    try {
        for (; fieldIndex < entries.length; fieldIndex++) {
            // Seek the next value
            if (!data.seek(mark, delimiter)) {
                if (fieldIndex > 0) {
                    throw new UnexpectedEndOfInputException("Near " + mark);
                }
                // We're just at the end
                return false;
            }
            // Extract it, type according to our header
            Header.Entry entry = entries[fieldIndex];
            if (entry.type() != Type.IGNORE) {
                Object value = data.tryExtract(mark, entry.extractor()) ? entry.extractor().value() : null;
                deserialization.handle(entry, value);
            }
            if (mark.isEndOfLine()) {
                // We're at the end of the line, break and return an entity with what we have.
                break;
            }
        }
        return true;
    } catch (final RuntimeException e) {
        String stringValue = null;
        try {
            Extractors extractors = new Extractors('?');
            if (data.tryExtract(mark, extractors.string())) {
                stringValue = extractors.string().value();
            }
        } catch (Exception e1) {
        // OK
        }
        String message = format("ERROR in input" + "%n  data source: %s" + "%n  in field: %s" + "%n  for header: %s" + "%n  raw field value: %s" + "%n  original error: %s", data, entries[fieldIndex] + ":" + (fieldIndex + 1), header, stringValue != null ? stringValue : "??", e.getMessage());
        if (e instanceof InputException) {
            throw Exceptions.withMessage(e, message);
        }
        throw new InputException(message, e);
    }
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) UnexpectedEndOfInputException(org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException) UnexpectedEndOfInputException(org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) UnexpectedEndOfInputException(org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Extractors (org.neo4j.csv.reader.Extractors)1 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)1 UnexpectedEndOfInputException (org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException)1