Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/gtfs/GtfsDataParser.java
/* | |||||
BusTO - Backend components | |||||
Copyright (C) 2021 Fabio Mazza | |||||
This program is free software: you can redistribute it and/or modify | |||||
it under the terms of the GNU General Public License as published by | |||||
the Free Software Foundation, either version 3 of the License, or | |||||
(at your option) any later version. | |||||
This program is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
GNU General Public License for more details. | |||||
You should have received a copy of the GNU General Public License | |||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
package it.reyboz.bustorino.backend.gtfs; | package it.reyboz.bustorino.backend.gtfs; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.util.Log; | import android.util.Log; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import de.siegmar.fastcsv.reader.CloseableIterator; | import de.siegmar.fastcsv.reader.CloseableIterator; | ||||
import de.siegmar.fastcsv.reader.NamedCsvReader; | import de.siegmar.fastcsv.reader.NamedCsvReader; | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | public static void readGtfsZipEntry(ZipEntry entry, ZipFile zipFile, Context con) throws IOException{ | ||||
entry.getSize() | entry.getSize() | ||||
); | ); | ||||
Log.d(DEBUG_TAG, s); | Log.d(DEBUG_TAG, s); | ||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | ||||
GtfsDataParser.readCSVWithColumns(reader, tableName, con); | GtfsDataParser.readCSVWithColumns(reader, tableName, con); | ||||
stream.close(); | stream.close(); | ||||
} | } | ||||
public static void readCSVWithColumns(BufferedReader reader, String tableName, Context con) throws IOException { | public static void readCSVWithColumns(BufferedReader reader, String tableName, Context con) { | ||||
//String[] elements; | //String[] elements; | ||||
List<String> lineElements; | List<String> lineElements; | ||||
String line; | String line; | ||||
/*final String header = reader.readLine(); | /*final String header = reader.readLine(); | ||||
if (header == null){ | if (header == null){ | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | private static String fixStringIfItHasQuotes(String item) { | ||||
return elements[0]; | return elements[0]; | ||||
else | else | ||||
return item; | return item; | ||||
} | } | ||||
//https://stackoverflow.com/questions/7800494/parse-csv-with-double-quote-in-some-cases#7800519 | //https://stackoverflow.com/questions/7800494/parse-csv-with-double-quote-in-some-cases#7800519 | ||||
public static List<String> readCsvLine(String line) throws IllegalArgumentException | public static List<String> readCsvLine(String line) throws IllegalArgumentException | ||||
{ | { | ||||
List<String> list = new ArrayList<String>(); | List<String> list = new ArrayList<>(); | ||||
line += ","; | line += ","; | ||||
for (int x = 0; x < line.length(); x++) | for (int x = 0; x < line.length(); x++) | ||||
{ | { | ||||
String s = line.substring(x); | String s = line.substring(x); | ||||
if (s.trim().startsWith("\"")) | if (s.trim().startsWith("\"")) | ||||
{ | { | ||||
Matcher m = quotePattern.matcher(s); | Matcher m = quotePattern.matcher(s); | ||||
Show All 19 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register