package tw.kewang.cwb;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Geocode {
    private static final Logger LOG = LoggerFactory.getLogger(Geocode.class);

    private static HashMap<String, Geocode> MAPS = new HashMap<>();

    private static boolean isInit = false;

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return code + ": " + name;
    }

    public static Geocode find(String data) {
        if (!isInit) {
            LOG.error("Uninitialized");

            return null;
        }

        Geocode result = MAPS.get(data);

        // find by code
        if (result != null) {
            return result;
        }

        // find by name
        for (Geocode geocode : MAPS.values()) {
            if (geocode.name.equalsIgnoreCase(data)) {
                return geocode;
            }
        }

        // not found
        return null;
    }

    public static void init() {
        if (isInit) {
            return;
        }

        ClassLoader classLoader = Geocode.class.getClassLoader();
        File file = new File(classLoader.getResource("geocode.txt").getFile());

        List<String> lines = new ArrayList<>();

        try {
            lines = FileUtils.readLines(file, Charset.defaultCharset());
        } catch (IOException e) {
            LOG.error("Caught Exception: ", e);
        }

        for (String line : lines) {
            String[] parts = line.split(",");

            Geocode geocode = new Geocode();

            geocode.code = parts[0];
            geocode.name = parts[1];

            MAPS.put(parts[0], geocode);
        }

        isInit = true;
    }
}
@@ -46,20 +46,18 @@
 mons.io.
-File
+IO
 Utils;%0Ai
@@ -117,29 +117,8 @@
 y;%0A%0A
-import java.io.File;%0A
 impo
@@ -1311,32 +1311,99 @@
 urn;%0A        %7D%0A%0A
+        List%3CString%3E lines = new ArrayList%3C%3E();%0A%0A        try %7B%0A    
         ClassLoa
@@ -1452,24 +1452,29 @@
 ader();%0A
+%0A    
         
 File fil
@@ -1469,28 +1469,33 @@
     
-File file = new File
+lines = IOUtils.readLines
 (cla
@@ -1514,16 +1514,24 @@
 Resource
+AsStream
 (%22geocod
@@ -1541,129 +1541,8 @@
 xt%22)
-.getFile());%0A%0A        List%3CString%3E lines = new ArrayList%3C%3E();%0A%0A        try %7B%0A            lines = FileUtils.readLines(file
 , Ch

Use getResourceAsStream to get file