aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/files/FileParser.java
blob: c7f16c842355ff19abda81f99437965d43078812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cgeo.geocaching.files;

import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgSearch;

import android.os.Handler;
import android.os.Message;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;

public abstract class FileParser {
    protected static StringBuilder readFile(File file)
            throws FileNotFoundException, IOException {
        StringBuilder buffer = new StringBuilder();
        BufferedReader input = new BufferedReader(new FileReader(file));
        try {
            String line = null;
            while ((line = input.readLine()) != null) {
                buffer.append(line);
            }
        } finally {
            input.close();
        }
        return buffer;
    }

    static void showFinishedMessage(Handler handler, cgSearch search) {
        if (handler != null) {
            final Message msg = new Message();
            msg.obj = search.getCount();
            handler.sendMessage(msg);
        }
    }

    protected static void fixCache(cgCache cache) {
        cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true);
        cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true);
        if (cache.inventory != null) {
            cache.inventoryItems = cache.inventory.size();
        } else {
            cache.inventoryItems = 0;
        }
        cache.updated = new Date().getTime();
        cache.detailedUpdate = new Date().getTime();
    }

}