All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.nicosensei.textbatch.utils.hosts.HostFile Maven / Gradle / Ivy

/**
 *
 */
package com.github.nicosensei.textbatch.utils.hosts;

import java.io.IOException;
import java.util.HashMap;

import com.github.nicosensei.textbatch.job.InputFileException;


/**
 * @author ngiraud
 *
 */
public class HostFile {

    private static HostFile instance;

    private HashMap hostAliases = new HashMap();

    public static void init(String file)
    throws InputFileException, IOException {
        instance = new HostFile(file);
    }

    public static HostFile getInstance() {
        return instance;
    }

    private HostFile(String file) throws InputFileException, IOException {
        HostFileReader in = new HostFileReader(file);

        HostFileLine l;
        while ((l = in.readLine()) != null) {
            if (l.isValidHostLine()) {
                hostAliases.put(l.getHostAlias1(), l.getHostAlias2());
            }
        }
    }

    public String getHostAlias(String host) {
        String alias = hostAliases.get(host);
        return (alias != null ? alias : host);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy