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

org.apiwatch.util.IniFile Maven / Gradle / Ivy

The newest version!
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright (c) 2012, Robin Jarry. All rights reserved.               *
 *                                                                     *
 * This file is part of APIWATCH and published under the BSD license.  *
 *                                                                     *
 * See the "LICENSE" file for more information.                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package org.apiwatch.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

import org.ini4j.Ini;
import org.ini4j.InvalidFileFormatException;
import org.ini4j.Profile.Section;

public class IniFile {
    
    public static Map> read(File file) throws InvalidFileFormatException,
            IOException
    {
        Ini ini = new Ini();
        ini.load(file);
        return read(ini);
    }

    public static Map> read(InputStream is) throws InvalidFileFormatException,
            IOException
    {
        Ini ini = new Ini();
        ini.load(is);
        return read(ini);
    }

    public static Map> read(Reader r) throws InvalidFileFormatException,
            IOException
    {
        Ini ini = new Ini();
        ini.load(r);
        return read(ini);
    }

    private static Map> read(Ini ini) {
        Map> iniSections = new HashMap>();
        for (Map.Entry section : ini.entrySet()) {
            Map sectionValues = new HashMap();
            for (Map.Entry val : section.getValue().entrySet()) {
                sectionValues.put(val.getKey(), val.getValue());
            }
            iniSections.put(section.getKey(), sectionValues);
        }
        return iniSections;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy