Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/main/java/org/mtransit/parser/gtfs/GReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,17 @@ private static boolean readFiles(
final File gtfsFile = FileUtils.findFileCaseInsensitive(gtfsDir, fileNames);
if (gtfsFile == null || !gtfsFile.exists()) {
if (fileRequired) {
throw new MTLog.Fatal("'%s' file does not exist!", fileNames);
throw new MTLog.Fatal("'%s' required file does not exist!", fileNames);
} else {
MTLog.log("Reading file(s) '%s'... SKIP (non-existing).", fileNames);
return false;
}
}
try (BufferedReader br = Files.newBufferedReader(gtfsFile.toPath())) {
readCsv(gtfsFile.getName(), br, lineProcessor, onColumnNamesFoundCallback);
final int linesProcessedCount = readCsv(gtfsFile.getName(), br, lineProcessor, onColumnNamesFoundCallback);
if (fileRequired && linesProcessedCount <= 0) {
throw new MTLog.Fatal("'%s' required file is empty!", gtfsFile);
}
} catch (IOException ioe) {
throw new MTLog.Fatal(ioe, "I/O Error while reading GTFS file %s!", gtfsFile);
}
Expand All @@ -266,13 +269,8 @@ private static boolean readFiles(

private static final Pattern QUOTE_ = Pattern.compile("\"");

@SuppressWarnings("unused")
private static void readCsv(String filename, BufferedReader reader, LineProcessor lineProcessor) throws IOException {
readCsv(filename, reader, lineProcessor, null);
}

@SuppressWarnings("resource")
private static void readCsv(
private static int readCsv(
String filename,
BufferedReader reader,
LineProcessor lineProcessor,
Expand All @@ -282,9 +280,9 @@ private static void readCsv(
String line;
String[] columnNames;
line = reader.readLine();
if (line == null || line.isEmpty()) return;
if (line == null || line.isEmpty()) return 0;
if (line.charAt(0) == '\uFEFF') { // remove 1st empty char
MTLog.log("Reading file '%s'... > remove 1st empty car", filename);
MTLog.log("Reading file '%s'... > remove 1st empty char", filename);
line = String.copyValueOf(line.toCharArray(), 1, line.length() - 1);
}
CSVRecord lineRecordColumns = CSVParser.parse(line, CSV_FORMAT).getRecords().get(0);
Expand All @@ -295,7 +293,7 @@ private static void readCsv(
if (onColumnNamesFoundCallback != null) {
onColumnNamesFoundCallback.processColumnNames(Arrays.asList(columnNames));
}
if (columnNames.length == 0) return;
if (columnNames.length == 0) return 0;
List<CSVRecord> lineRecords;
final HashMap<String, String> map = new HashMap<>();
int l = 0;
Expand Down Expand Up @@ -346,6 +344,7 @@ private static void readCsv(
} // LOG
}
MTLog.log("Reading file '%s' (lines: %s)... DONE", filename, l);
return l;
}

private static void processStopTime(
Expand Down