Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 1aee1fc

Browse files
authored
Support BOM files (#61)
1 parent ef46354 commit 1aee1fc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

GO_Sync/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>commons-csv</artifactId>
4141
<version>1.7</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>commons-io</groupId>
45+
<artifactId>commons-io</artifactId>
46+
<version>2.11.0</version>
47+
</dependency>
4348

4449

4550
</dependencies>

GO_Sync/src/main/java/edu/usf/cutr/go_sync/io/GTFSReadIn.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
import org.apache.commons.csv.CSVFormat;
2929
import org.apache.commons.csv.CSVParser;
3030
import org.apache.commons.csv.CSVRecord;
31+
import org.apache.commons.io.input.BOMInputStream;
3132

3233
public class GTFSReadIn {
3334
private static Hashtable<String, Route> allRoutes;
3435
private static final String ROUTE_KEY = "route_ref";
3536
private static final String NTD_ID_KEY = "ntd_id";
36-
private static final String UTF8_BOM = "\uFEFF";
3737

3838
private List<Stop> stops;
3939

@@ -79,7 +79,7 @@ public List<Stop> readBusStop(String fName, String agencyName, String routes_fNa
7979
String [] elements;
8080
int stopIdKey=-1, stopNameKey=-1, stopLatKey=-1, stopLonKey=-1;
8181
try {
82-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fName),"UTF-8"));
82+
BufferedReader br = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(fName)),"UTF-8"));
8383
HashMap<String,Integer> keysIndex = new HashMap<String,Integer> ();
8484
thisLine = br.readLine();
8585
StringReader sr = new StringReader(thisLine);
@@ -224,7 +224,7 @@ public Hashtable<String, Route> readRoutes(String routes_fName){
224224
int routeIdKey=-1, routeShortNameKey=-1,routeLongNameKey=-1;
225225

226226
try {
227-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(routes_fName),"UTF-8"));
227+
BufferedReader br = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(routes_fName)), "UTF-8"));
228228
HashMap<String,Integer> keysIndex = new HashMap<String,Integer> ();
229229
thisLine = br.readLine();
230230
StringReader sr = new StringReader(thisLine);
@@ -341,7 +341,7 @@ public Hashtable<String, HashSet<Route>> matchRouteToStop(String routes_fName, S
341341

342342
// trips.txt read-in
343343
try {
344-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(trips_fName),"UTF-8"));
344+
BufferedReader br = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(trips_fName)),"UTF-8"));
345345
CSVParser parser = CSVParser.parse(br, CSVFormat.DEFAULT.withHeader());
346346
for (CSVRecord csvRecord : parser) {
347347

@@ -361,7 +361,7 @@ public Hashtable<String, HashSet<Route>> matchRouteToStop(String routes_fName, S
361361
Hashtable<String, HashSet<Route>> stopIDs = new Hashtable<String, HashSet<Route>>();
362362
// stop_times.txt read-in
363363
try {
364-
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(stop_times_fName), "UTF-8"));
364+
BufferedReader br = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(stop_times_fName)), "UTF-8"));
365365

366366
CSVParser parser = CSVParser.parse(br, CSVFormat.DEFAULT.withHeader());
367367

0 commit comments

Comments
 (0)