Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityExperiments.java
- This file was added.
package it.reyboz.bustorino; | |||||
import android.os.AsyncTask; | |||||
import android.util.Log; | |||||
import android.view.View; | |||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import android.os.Bundle; | |||||
import it.reyboz.bustorino.backend.Fetcher; | |||||
import it.reyboz.bustorino.backend.gtfs.GtfsDataParser; | |||||
import it.reyboz.bustorino.backend.networkTools; | |||||
import it.reyboz.bustorino.backend.utils; | |||||
import it.reyboz.bustorino.middleware.GeneralActivity; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.net.MalformedURLException; | |||||
import java.net.URL; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
import java.util.Locale; | |||||
import java.util.concurrent.atomic.AtomicReference; | |||||
import java.util.zip.ZipEntry; | |||||
import java.util.zip.ZipFile; | |||||
import java.util.zip.ZipInputStream; | |||||
public class ActivityExperiments extends GeneralActivity { | |||||
@Override | |||||
protected void onCreate(Bundle savedInstanceState) { | |||||
super.onCreate(savedInstanceState); | |||||
setContentView(R.layout.activity_experiments); | |||||
} | |||||
public void runExp(View v){ | |||||
Thread th = new Thread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
final String DEBUG_TAG = "ExperimentsGTFS"; | |||||
AtomicReference<Fetcher.Result> res = new AtomicReference<>(); | |||||
//List<String> files = GtfsDataParser.readFilesList(res); | |||||
Date updateDate = GtfsDataParser.getLastGTFSUpdateDate(res); | |||||
Log.w( | |||||
"ExperimentGTFS", "Last update date is "+updateDate//utils.joinList(files, "\n") | |||||
); | |||||
File saveFile = new File(getFilesDir(), "gtfs_data.zip"); | |||||
if(!saveFile.isDirectory() && saveFile.exists()){ | |||||
Log.w(DEBUG_TAG, "Zip exists: "+saveFile); | |||||
try (FileInputStream fileStream = new FileInputStream(saveFile);) { | |||||
ZipInputStream stream = new ZipInputStream(fileStream); | |||||
// now iterate through each item in the stream. The get next | |||||
// entry call will return a ZipEntry for each file in the | |||||
// stream | |||||
ZipEntry entry; | |||||
while ((entry = stream.getNextEntry()) != null) { | |||||
String s = String.format(Locale.ENGLISH, "Entry: %s len %d added", | |||||
entry.getName(), | |||||
entry.getSize() | |||||
); | |||||
Log.d(DEBUG_TAG,s); | |||||
// Once we get the entry from the stream, the stream is | |||||
// positioned read to read the raw data, and we keep | |||||
// reading until read returns 0 or less. | |||||
//result.add(entry.getName()); | |||||
} | |||||
stream.close(); | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
//saveFile.delete(); | |||||
} else | |||||
try { | |||||
networkTools.saveFileInCache(saveFile,new URL(GtfsDataParser.GTFS_ADDRESS)); | |||||
Log.w(DEBUG_TAG, "File saved"); | |||||
} catch (MalformedURLException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
}); | |||||
th.start(); | |||||
} | |||||
} | |||||
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