Package org.apache.qpid.info.util

Examples of org.apache.qpid.info.util.IniFileReader


        {
            // invalid state
            return;
        }

        IniFileReader ifr = new IniFileReader();
        try
        {
            String QPID_HOME = System.getProperty("QPID_HOME");
            String cfgFilePath = QPID_HOME + File.separator + "etc"
                                 + File.separator + "qpidinfo.ini";
            ifr.load(cfgFilePath);
        }
        catch (Throwable ex)
        {
            // drop everything to be silent
            return;
        }

        // Only send Messages if we have some sections.
        if (ifr.getSections().size() != 0)
        {
            Info<? extends Map<String, ?>> info = _service.invoke(action);
            String protocol = ifr.getSections().get("").getProperty("protocol");
            sendMessages(protocol, ifr, info);
        }
    }
View Full Code Here


        {
            // invalid state
            return;
        }

        IniFileReader ifr = new IniFileReader();
        try
        {
            String QPID_HOME = System.getProperty("QPID_HOME");
            String cfgFilePath = QPID_HOME + File.separator + "etc"
                                 + File.separator + "qpidinfo.ini";
            ifr.load(cfgFilePath);
        }
        catch (Throwable ex)
        {
            // drop everything to be silent
            return;
        }

        // Only send Messages if we have some sections.
        if (ifr.getSections().size() != 0)
        {
            Info<? extends Map<String, ?>> info = _service.invoke(action);
            String protocol = ifr.getSections().get("").getProperty("protocol");
            sendMessages(protocol, ifr, info);
        }
    }
View Full Code Here

public class IniFileReaderTest extends TestCase
{

    public void testLoad()
    {
        IniFileReader ifr = new IniFileReader();
        File iniFile = null;
        try
        {
            iniFile = File.createTempFile("temp", "ini");
            iniFile.deleteOnExit();
            BufferedWriter writer = new BufferedWriter(new FileWriter(iniFile));
            writer.write("# Global Comment1\n");
            writer.write("globalprop1=globalval1\n");
            writer.write("globalprop2=globalval2\n");
            writer.write("\n");
            writer.write("[Section1] # Comment on Section\n");
            writer.write("key1=val1 # Comment on Value\n");
            writer.write("key2=val2\n");
            writer.write("\n");
            writer.write("#Section2 Comment\n");
            writer.write("[Section2]\n");
            writer.write("key3=val3\n");
            writer.write("key4=val4\n");
            writer.write("key5=val5\n");
            writer.write("\n");
            writer.write("[Section3]\n");
            writer.write("key6=val6\n");
            writer.write("key7=val7\n");
            writer.write("\n");
            writer.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            fail("Unable to create temporary File");
        }
        ifr.load(iniFile.getAbsolutePath());
        Map<String, Properties> sections = ifr.getSections();
        assertNotNull("Sections not null", sections);
        assertEquals("Have 4 sections", sections.keySet().size(), 4);
        assertTrue("Get globalprop1", sections.get("").getProperty("globalprop1").equals("globalval1"));
        assertTrue("Get globalprop2", sections.get("").getProperty("globalprop2").equals("globalval2"));
        assertNotNull("Section1 not null", sections.get("Section1"));
View Full Code Here

     *
     * Section needs to be fully enclosed in square brackets '[<name>]'
     */
    public void testIncompleteSection1Load()
    {
        IniFileReader ifr = new IniFileReader();
        File iniFile = null;
        try
        {
            iniFile = File.createTempFile(getName(), "ini");
            iniFile.deleteOnExit();
            BufferedWriter writer = new BufferedWriter(new FileWriter(iniFile));
            writer.write("# Global Comment1\n");
            writer.write("globalprop1=globalval1\n");
            writer.write("globalprop2=globalval2\n");
            writer.write("\n");
            writer.write("[Section1\n")// Note '[Section1' not complete
            writer.write("key1=val1\n");
            writer.write("key2=val2\n");
            writer.write("\n");
            writer.close();           
        }
        catch (IOException e)
        {
            e.printStackTrace();
            fail("Unable to create temporary File");
        }
        try
        {
            ifr.load(iniFile.getAbsolutePath());
            fail("File should fail to parse");
        }
        catch (IllegalArgumentException iae)
        {
            assertEquals("Incorrect Exception", "Section1 is not closed", iae.getMessage());
View Full Code Here

TOP

Related Classes of org.apache.qpid.info.util.IniFileReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.