Skip to content

Commit

Permalink
Fix for CUTR-at-USF#25
Browse files Browse the repository at this point in the history
Fix for CUTR-at-USF#25
- When obtaining data from OSM non-ASCII characters might be mishandled
- When reading data from GTFS files non-ASCII characters might be
mishandled
- When writing output non-ASCII characters might be mishandled
  • Loading branch information
james2432 committed May 13, 2016
1 parent 3cf856c commit 1cd8f56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions GO_Sync/src/main/java/edu/usf/cutr/go_sync/io/GTFSReadIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import edu.usf.cutr.go_sync.object.Route;
import edu.usf.cutr.go_sync.object.Stop;
import edu.usf.cutr.go_sync.tools.OsmFormatter;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class GTFSReadIn {
private List<Stop> stops;
Expand Down Expand Up @@ -127,7 +129,7 @@ public List<Stop> readBusStop(String fName, String agencyName, String routes_fNa
String [] elements;
int stopIdKey=-1, stopNameKey=-1, stopLatKey=-1, stopLonKey=-1;
try {
BufferedReader br = new BufferedReader(new FileReader(fName));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fName),"UTF-8"));
boolean isFirstLine = true;
Hashtable keysIndex = new Hashtable();
while ((thisLine = br.readLine()) != null)
Expand Down Expand Up @@ -242,7 +244,7 @@ public Hashtable<String, Route> readRoutes(String routes_fName){
String [] elements;
int routeIdKey=-1, routeShortNameKey=-1;
try {
BufferedReader br = new BufferedReader(new FileReader(routes_fName));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(routes_fName),"UTF-8"));
boolean isFirstLine = true;
Hashtable keysIndex = new Hashtable();
while ((thisLine = br.readLine()) != null) {
Expand Down Expand Up @@ -314,7 +316,7 @@ public Hashtable<String, HashSet<Route>> matchRouteToStop(String routes_fName, S
// trips.txt read-in
try {
int tripIdKey=-1, routeIdKey=-1;
BufferedReader br = new BufferedReader(new FileReader(trips_fName));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(trips_fName),"UTF-8"));
boolean isFirstLine = true;
while ((thisLine = br.readLine()) != null) {
if (isFirstLine) {
Expand Down Expand Up @@ -355,7 +357,7 @@ public Hashtable<String, HashSet<Route>> matchRouteToStop(String routes_fName, S
// stop_times.txt read-in
int stopIdKey=-1, tripIdKey = -1;
try {
BufferedReader br = new BufferedReader(new FileReader(stop_times_fName));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(stop_times_fName),"UTF-8"));
boolean isFirstLine = true;
while ((thisLine = br.readLine()) != null) {
if (isFirstLine) {
Expand Down
8 changes: 4 additions & 4 deletions GO_Sync/src/main/java/edu/usf/cutr/go_sync/io/WriteFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public WriteFile(String fname, String contents) {
Writer output = null;
File file = new File(fname);
try {
output = new BufferedWriter(new FileWriter(file));
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
output.write(contents);
output.close();
System.out.println("Your file: "+fname+" has been written");
Expand All @@ -64,7 +64,7 @@ public WriteFile(String fname, Hashtable r) {
Writer output = null;
File file = new File(fname);
try {
output = new BufferedWriter(new FileWriter(file));
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
reportKeys.addAll(report.keySet());
Iterator it = reportKeys.iterator();
int count = 1;
Expand Down Expand Up @@ -223,7 +223,7 @@ public static void exportStops(String fname, Hashtable<String, Stop> r, boolean
Writer output = null;
File file = new File(fname);
try {
output = new BufferedWriter(new FileWriter(file));
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
//print key (first line)
output.write(OperatorInfo.getGtfsFields());
if(!isGtfsFormat) output.write(",OSM_TAGs");
Expand Down Expand Up @@ -299,7 +299,7 @@ public void writeStopToFile(String fname, List<Stop> st){
Writer output = null;
File file = new File(fname);
try {
output = new BufferedWriter(new FileWriter(file));
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
output.write("stop_id,stop_name,stop_lat,stop_lon\n");
for(int i=0; i<stops.size(); i++){
output.write(stops.get(i).getStopID()+","+stops.get(i).getStopName()+","+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public String sendRequest(String[] hosts, String urlSuffix, String method, Strin
BufferedReader response;
String s;
if(responseCode==HttpURLConnection.HTTP_OK) {
response = new BufferedReader(new InputStreamReader (conn.getInputStream()));
response = new BufferedReader(new InputStreamReader (conn.getInputStream(),"UTF-8"));
char[] cbuf = new char[]{};
response.read(cbuf);
s = response.readLine();
Expand Down

0 comments on commit 1cd8f56

Please sign in to comment.