36 |
public boolean loadStations(Context context) throws Exception { |
public boolean loadStations(Context context) throws Exception { |
37 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
38 |
|
|
39 |
stations.entries.clear(); //TODO: remove |
StationBean tmpStations = new StationBean(); |
40 |
|
|
41 |
File parent = context.getFilesDir(); |
File parent = context.getFilesDir(); |
42 |
File stationsFile = new File(parent, "stations.bin"); |
File stationsFile = new File(parent, "stations.bin"); |
62 |
for (int i=0; i<length; i++) { |
for (int i=0; i<length; i++) { |
63 |
StationEntry entry = (StationEntry) in.readObject(); |
StationEntry entry = (StationEntry) in.readObject(); |
64 |
updateSearchStrings(entry); |
updateSearchStrings(entry); |
65 |
stations.entries.add( entry ); |
tmpStations.entries.add( entry ); |
66 |
} |
} |
67 |
|
|
68 |
in.close(); |
in.close(); |
69 |
|
|
70 |
|
stations = tmpStations; // når indlæsningen er ok skifter vi over |
71 |
|
|
72 |
Log.e("OFFLINE", "loaded" + stations.entries.size()); |
Log.e("OFFLINE", "loaded" + tmpStations.entries.size()); |
73 |
logElapsedTime(start, "loadStations"); |
logElapsedTime(start, "loadStations"); |
74 |
|
|
75 |
return true; |
return true; |
87 |
|
|
88 |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
89 |
Serializer serializer = new Persister(); |
Serializer serializer = new Persister(); |
90 |
stations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
StationBean tmpStations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
91 |
|
|
92 |
|
|
93 |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
94 |
Log.e("OFFLINE", "data size" + data.length); |
Log.e("OFFLINE", "data size" + data.length); |
95 |
|
|
96 |
out.writeInt( stations.entries.size() ); //start with writing the length of the dataset |
out.writeInt( tmpStations.entries.size() ); //start with writing the length of the dataset |
97 |
|
|
98 |
for (StationEntry entry : stations.entries) { |
for (StationEntry entry : tmpStations.entries) { |
99 |
updateSearchStrings( entry ); //prepare name fields for byName search |
updateSearchStrings( entry ); //prepare name fields for byName search |
100 |
out.writeObject(entry); |
out.writeObject(entry); |
101 |
} |
} |
102 |
|
|
103 |
out.close(); |
out.close(); |
104 |
|
|
105 |
|
stations = tmpStations; // når alt er ok skifter vi over til ny udgave |
106 |
} |
} |
107 |
|
|
108 |
|
|