close() public method

public close ( ) : bool
return bool
Example #1
0
        private static List loadDatabase()
        {
            InStream input         = null;
            List     quantityNames = new List(Sys.StrType);

            try
            {
                // parse etc/sys/units.fog as big serialized list which contains
                // lists for each quantity (first item being the name)
                String path = "etc/sys/units.txt";
                input = Env.cur().findFile(path).@in();

                // parse each line
                string curQuantityName = null;
                List   curQuantityList = null;
                string line;
                while ((line = input.readLine()) != null)
                {
                    // skip comment and blank lines
                    line = line.Trim();
                    if (line.StartsWith("//") || line.Length == 0)
                    {
                        continue;
                    }

                    // quanity sections delimited as "-- name (dim)"
                    if (line.StartsWith("--"))
                    {
                        if (curQuantityName != null)
                        {
                            m_quantities[curQuantityName] = curQuantityList.toImmutable();
                        }
                        curQuantityName = line.Substring(2, line.IndexOf('(') - 2).Trim();
                        curQuantityList = new List(Sys.UnitType);
                        quantityNames.add(curQuantityName);
                        continue;
                    }

                    // must be a unit
                    try
                    {
                        Unit unit = Unit.define(line);
                        curQuantityList.add(unit);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line);
                        System.Console.WriteLine("  " + e);
                    }
                }
                m_quantities[curQuantityName] = curQuantityList.toImmutable();
            }
            catch (Exception e)
            {
                try { input.close(); } catch (Exception) {}
                System.Console.WriteLine("WARNING: Cannot load lib/units.txt");
                Err.dumpStack(e);
            }
            return((List)quantityNames.toImmutable());
        }