1 |
package dk.thoerup.traininfo.provider; |
package dk.thoerup.traininfo.provider; |
2 |
|
|
|
import java.io.EOFException; |
|
3 |
import java.io.File; |
import java.io.File; |
4 |
import java.io.FileInputStream; |
import java.io.FileInputStream; |
5 |
import java.io.FileOutputStream; |
import java.io.FileOutputStream; |
28 |
|
|
29 |
StationBean stations = new StationBean(); |
StationBean stations = new StationBean(); |
30 |
|
|
31 |
|
public boolean hasStations() { |
32 |
|
return (stations != null && stations.entries.size() > 0); |
33 |
|
} |
34 |
|
|
35 |
|
|
36 |
public boolean loadStations(Context context) throws Exception { |
public boolean loadStations(Context context) throws Exception { |
37 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
54 |
stations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") );*/ |
stations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") );*/ |
55 |
|
|
56 |
|
|
57 |
try { |
|
58 |
ObjectInputStream in = new ObjectInputStream( new FileInputStream(stationsFile) ); |
ObjectInputStream in = new ObjectInputStream( new FileInputStream(stationsFile) ); |
59 |
Object o; |
|
60 |
StationEntry e = null; |
int length = in.readInt(); // first field is the length |
61 |
while ( (o=in.readObject()) != null ) { |
|
62 |
e = (StationEntry) o; |
for (int i=0; i<length; i++) { |
63 |
updateSearchStrings(e); |
StationEntry entry = (StationEntry) in.readObject(); |
64 |
stations.entries.add( e ); |
updateSearchStrings(entry); |
65 |
} |
stations.entries.add( entry ); |
|
in.close(); |
|
|
} catch (EOFException e) { |
|
|
//do nothing; |
|
66 |
} |
} |
67 |
|
|
68 |
|
in.close(); |
69 |
|
|
70 |
|
|
71 |
Log.e("OFFLINE", "loaded" + stations.entries.size()); |
Log.e("OFFLINE", "loaded" + stations.entries.size()); |
72 |
logElapsedTime(start, "loadStations"); |
logElapsedTime(start, "loadStations"); |
73 |
|
|
92 |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
93 |
Log.e("OFFLINE", "data size" + data.length); |
Log.e("OFFLINE", "data size" + data.length); |
94 |
|
|
95 |
|
out.writeInt( stations.entries.size() ); //start with writing the length of the dataset |
96 |
|
|
97 |
for (StationEntry entry : stations.entries) { |
for (StationEntry entry : stations.entries) { |
98 |
updateSearchStrings( entry ); //prepare name fields for byName search |
updateSearchStrings( entry ); //prepare name fields for byName search |
99 |
out.writeObject(entry); |
out.writeObject(entry); |
154 |
Collections.sort( entries, distanceComparator); |
Collections.sort( entries, distanceComparator); |
155 |
|
|
156 |
StationBean tmpStations = new StationBean(); |
StationBean tmpStations = new StationBean(); |
157 |
for (int i = 0; i<8; i++) { |
for (int i = 0; i<8 && i<entries.size(); i++) { |
158 |
tmpStations.entries.add( entries.get(i) ); |
tmpStations.entries.add( entries.get(i) ); |
159 |
} |
} |
160 |
|
|