Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityExperiments.java
Show All 30 Lines | |||||
import it.reyboz.bustorino.backend.gtfs.GtfsDataParser; | import it.reyboz.bustorino.backend.gtfs.GtfsDataParser; | ||||
import it.reyboz.bustorino.backend.networkTools; | import it.reyboz.bustorino.backend.networkTools; | ||||
import it.reyboz.bustorino.backend.utils; | import it.reyboz.bustorino.backend.utils; | ||||
import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
import java.io.*; | import java.io.*; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.Date; | import java.util.*; | ||||
import java.util.List; | |||||
import java.util.Locale; | |||||
import java.util.concurrent.ExecutorService; | import java.util.concurrent.ExecutorService; | ||||
import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||
import java.util.concurrent.atomic.AtomicReference; | import java.util.concurrent.atomic.AtomicReference; | ||||
import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
import java.util.zip.ZipFile; | import java.util.zip.ZipFile; | ||||
import java.util.zip.ZipInputStream; | import java.util.zip.ZipInputStream; | ||||
public class ActivityExperiments extends GeneralActivity { | public class ActivityExperiments extends GeneralActivity { | ||||
Show All 31 Lines | public void runExp(View v){ | ||||
Log.w( | Log.w( | ||||
"ExperimentGTFS", "Last update date is " + updateDate//utils.joinList(files, "\n") | "ExperimentGTFS", "Last update date is " + updateDate//utils.joinList(files, "\n") | ||||
); | ); | ||||
//Toast.makeText(v.getContext(), "Gtfs data already downloaded", Toast.LENGTH_SHORT).show(); | //Toast.makeText(v.getContext(), "Gtfs data already downloaded", Toast.LENGTH_SHORT).show(); | ||||
File saveFile = new File(getFilesDir(), "gtfs_data.zip"); | File saveFile = new File(getFilesDir(), "gtfs_data.zip"); | ||||
if (!saveFile.isDirectory() && saveFile.exists()) { | if (!saveFile.isDirectory() && saveFile.exists()) { | ||||
Log.w(DEBUG_TAG, "Zip exists: " + saveFile); | Log.w(DEBUG_TAG, "Zip exists: " + saveFile); | ||||
try (FileInputStream fileStream = new FileInputStream(saveFile)) { | |||||
ZipInputStream stream = new ZipInputStream(fileStream); | try (ZipFile zipFile = new ZipFile(saveFile)) { | ||||
//ZipInputStream stream = new ZipInputStream(fileStream); | |||||
// now iterate through each item in the stream. The get next | // now iterate through each item in the stream. The get next | ||||
// entry call will return a ZipEntry for each file in the | // entry call will return a ZipEntry for each file in the | ||||
// stream | // stream | ||||
Enumeration<? extends ZipEntry> entries = zipFile.entries(); | |||||
ZipEntry entry; | ZipEntry entry; | ||||
String line; | String line; | ||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | //final BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | ||||
HashSet<ZipEntry> readLater = new HashSet<>(); | |||||
while(entries.hasMoreElements()){ | |||||
entry = entries.nextElement(); | |||||
//String tableName = entry.getName().split("\\.")[0].trim(); | |||||
if(entry.getName().trim().equals("stop_times.txt")) { | |||||
readLater.add(entry); | |||||
continue; | |||||
} | |||||
GtfsDataParser.readGtfsZipEntry(entry, zipFile, v.getContext().getApplicationContext()); | |||||
} | |||||
for(ZipEntry laterEntry: readLater){ | |||||
GtfsDataParser.readGtfsZipEntry(laterEntry, zipFile, v.getContext().getApplicationContext()); | |||||
} | |||||
/* | |||||
while ((entry = stream.getNextEntry()) != null) { | while ((entry = stream.getNextEntry()) != null) { | ||||
String s = String.format(Locale.ENGLISH, "Entry: %s len %d added", | String s = String.format(Locale.ENGLISH, "Entry: %s len %d added", | ||||
entry.getName(), | entry.getName(), | ||||
entry.getSize() | entry.getSize() | ||||
); | ); | ||||
if(entry.getName().contains("stop_times.")){ | |||||
//skip and do later | |||||
} | |||||
//Toast.makeText(v.getContext(), "File: " + entry.getName(), Toast.LENGTH_SHORT).show(); | //Toast.makeText(v.getContext(), "File: " + entry.getName(), Toast.LENGTH_SHORT).show(); | ||||
Log.d(DEBUG_TAG, s); | Log.d(DEBUG_TAG, s); | ||||
//read data in table | //read data in table | ||||
final String tableName = entry.getName().split("\\.")[0].trim(); | final String tableName = entry.getName().split("\\.")[0].trim(); | ||||
GtfsDataParser.readCSVWithColumns(reader, tableName, v.getContext().getApplicationContext()); | |||||
// Once we get the entry from the stream, the stream is | // Once we get the entry from the stream, the stream is | ||||
// positioned read to read the raw data, and we keep | // positioned read to read the raw data, and we keep | ||||
// reading until read returns 0 or less. | // reading until read returns 0 or less. | ||||
//result.add(entry.getName()); | //result.add(entry.getName()); | ||||
} | } | ||||
stream.close(); | stream.close(); | ||||
*/ | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
//saveFile.delete(); | //saveFile.delete(); | ||||
} else | } else | ||||
try { | try { | ||||
//Toast.makeText(v.getContext(), "Downloading gtfs data", Toast.LENGTH_SHORT).show(); | //Toast.makeText(v.getContext(), "Downloading gtfs data", Toast.LENGTH_SHORT).show(); | ||||
Show All 11 Lines | public void runExp(View v){ | ||||
//handler.post(run); | //handler.post(run); | ||||
executorService.execute(run); | executorService.execute(run); | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
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