Skip to content

Commit

Permalink
0003127: Add logging to the DBFRouter to log failed line number and
Browse files Browse the repository at this point in the history
field
  • Loading branch information
chenson42 committed May 25, 2017
1 parent 2b042b6 commit 27722ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Expand Up @@ -28,13 +28,11 @@
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.model.FileSnapshot;
import org.jumpmind.symmetric.model.FileTrigger;
import org.jumpmind.symmetric.model.FileSnapshot.LastEventType;
import org.jumpmind.symmetric.model.ProcessInfo.Status;
import org.jumpmind.symmetric.model.FileTriggerRouter;
import org.jumpmind.symmetric.model.ProcessInfo;
import org.jumpmind.symmetric.model.ProcessInfo.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.model.FileSnapshot;
import org.jumpmind.symmetric.model.FileSnapshot.LastEventType;
import org.jumpmind.symmetric.model.FileTriggerRouter;
Expand Down
Expand Up @@ -31,15 +31,16 @@ public List<String> parse(File file, int lineNumber) {
List<String> rows = new ArrayList<String>();

InputStream fileInputStream = null;
int currentLine = 1;
try {
boolean validateHeader = engine.getParameterService()
.is(ParameterConstants.DBF_ROUTER_VALIDATE_HEADER, true);

fileInputStream = Files.newInputStream(file.toPath(), StandardOpenOption.READ);
dbfReader = new DBFReader(fileInputStream, validateHeader);
int currentLine = 1;

while (dbfReader.hasNextRecord()) {
StringBuffer row = new StringBuffer();
StringBuilder row = new StringBuilder();
Object[] record = dbfReader.nextRecord();
if (currentLine > lineNumber) {
for (int i = 0; i < record.length; i++) {
Expand All @@ -53,7 +54,7 @@ public List<String> parse(File file, int lineNumber) {
}
}
catch (Exception e) {
log.error("Unable to parse DBF file " + file.getName(), e);
log.error("Unable to parse DBF file " + file.getName() + " line number " + currentLine, e);
}
finally {
if (fileInputStream != null) {
Expand Down
Expand Up @@ -3,13 +3,19 @@
import java.io.*;
import java.nio.charset.Charset;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DBFReader {

static final Logger log = LoggerFactory.getLogger(DBFReader.class);

private DataInputStream stream;
private DBFField fields[];
private byte nextRecord[];
private int nFieldCount;
private boolean validate;
private int lineNumber;

public DBFReader(String s, boolean validate) throws DBFException {
stream = null;
Expand Down Expand Up @@ -153,13 +159,19 @@ public boolean hasNextRecord() {
public Object[] nextRecord() throws DBFException {
if (!hasNextRecord())
throw new DBFException("No more records available.");
lineNumber++;
Object aobj[] = new Object[nFieldCount];
int i = 1;
for (int j = 0; j < aobj.length; j++) {
int k = fields[j].getLength();
StringBuffer stringbuffer = new StringBuffer(k);
stringbuffer.append(new String(nextRecord, i, k));
aobj[j] = fields[j].parse(stringbuffer.toString());
try {
aobj[j] = fields[j].parse(stringbuffer.toString());
} catch (DBFException e) {
log.error("Failed to parse field " + (j+1) + " on line " + lineNumber + " with that had a value of " + stringbuffer);
throw e;
}
i += fields[j].getLength();
}

Expand Down

0 comments on commit 27722ef

Please sign in to comment.