Example usage for java.util Properties load

List of usage examples for java.util Properties load

Introduction

In this page you can find the example usage for java.util Properties load.

Prototype

public synchronized void load(InputStream inStream) throws IOException 

Source Link

Document

Reads a property list (key and element pairs) from the input byte stream.

Usage

From source file:Main.java

public static boolean readProperties(InputStream input, Properties properties) {
    if (input != null && properties != null) {
        boolean e;

        try {//from   ww  w.j av  a2  s .  c o m
            properties.load(input);
            e = true;
        } catch (IOException var6) {
            var6.printStackTrace();
            return false;
        } finally {
            close((Closeable) input);
        }

        return e;
    } else {
        return false;
    }
}

From source file:com.parasoft.xtest.reports.jenkins.util.FilePathUtil.java

/**
 * @param file/*from   w  w  w  . j  av  a2s.c om*/
 * @return properties loaded from given file
 */
public static Properties loadProperties(FilePath file) {
    Properties props = null;
    try {
        props = file.act(new FileCallable<Properties>() {
            private static final long serialVersionUID = -286350596197180650L;

            public Properties invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
                Logger.getLogger().info("File path is " + f.getAbsolutePath()); //$NON-NLS-1$
                InputStream input = new FileInputStream(f);
                try {
                    Properties properties = new Properties();
                    properties.load(input);
                    return properties;
                } finally {
                    IOUtils.closeQuietly(input);
                }
            }

            @Override
            public void checkRoles(RoleChecker arg0) throws SecurityException {
                // TODO Auto-generated method stub

            }
        });
    } catch (IOException e) {
        Logger.getLogger().error("Localsettings file not found", e); //$NON-NLS-1$
    } catch (InterruptedException e) {
        Logger.getLogger().error("Error while reading remote file", e); //$NON-NLS-1$
    }
    if (props == null) {
        props = new Properties();
        Logger.getLogger().info("No properties loaded"); //$NON-NLS-1$
    }
    return props;
}

From source file:gov.nih.nci.cagrid.caarray.stubs.cql.CaArrayCQLQueryProcessor.java

private static synchronized CaArraySearchService getSearchService() {
    try {/*  w  ww  .j  av  a  2 s .  c  o  m*/
        final Properties jndiProp = new Properties();
        jndiProp.load(CaArraySvcImpl.class.getResourceAsStream("/gov/nih/nci/cagrid/caarray/jndi.properties"));

        if (jndiProp.getProperty("java.naming.factory.initial") == null
                || jndiProp.getProperty("java.naming.factory.url.pkgs") == null
                || jndiProp.getProperty("java.naming.provider.url") == null) {
            throw new IllegalArgumentException(
                    "Unable to find all required properties in jndi.properties file.");
        }

        final Context context = new InitialContext(jndiProp);
        searchService = (CaArraySearchService) context.lookup(CaArraySearchService.JNDI_NAME);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
    return searchService;
}

From source file:com.hzc.framework.util.PropertiesUtil.java

public static void init(String configPath) {
    Properties p1 = new Properties();
    InputStream is = PropertiesUtil.class.getResourceAsStream(configPath);
    try {//from ww w.  ja  v  a2s  .com
        p1.load(is);
        p.putAll(p1);
    } catch (IOException ex) {
        log.error(ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ex) {
                log.error(ex);
            }
            is = null;
        }
    }
}

From source file:net.sf.dsig.helpers.UserHomeSettingsParser.java

public static Properties parse() {
    try {/*  w w w  .  ja  v  a  2 s. com*/
        String userHome = System.getProperty("user.home");
        File dsigFolder = new File(userHome, ".dsig");
        if (!dsigFolder.exists() && !dsigFolder.mkdir()) {
            throw new IOException("Could not create .dsig folder in user home directory");
        }

        File settingsFile = new File(dsigFolder, "settings.properties");
        if (!settingsFile.exists()) {
            InputStream is = UserHomeSettingsParser.class.getResourceAsStream("/defaultSettings.properties");
            if (is != null) {
                IOUtils.copy(is, new FileOutputStream(settingsFile));
            }
        }

        if (settingsFile.exists()) {
            Properties p = new Properties();
            FileInputStream fis = new FileInputStream(settingsFile);
            p.load(fis);
            IOUtils.closeQuietly(fis);
            return p;
        }
    } catch (IOException e) {
        logger.warn("Error while initialize settings", e);
    }

    return null;
}

From source file:Main.java

public static String readData(Context mContext, String key, int resId) {
    Properties props = new Properties();
    try {// w  w  w.  ja v  a 2 s  .c  o m
        InputStream in = new BufferedInputStream(mContext.getResources().openRawResource(resId));
        props.load(in);
        in.close();
        String value = props.getProperty(key);
        return value;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.surveypanel.view.FreemarkerManager.java

/**
 * Load the settings from the /freemarker.properties file on the classpath
 *
 * @see freemarker.template.Configuration#setSettings for the definition of valid settings
 */// w w w  .  ja  va 2s. c  o m
protected static void loadSettings(Configuration configuration) {
    InputStream in = null;
    try {
        in = FreemarkerManager.class.getResourceAsStream("freemarker.properties");
        if (in != null) {
            Properties p = new Properties();
            p.load(in);
            configuration.setSettings(p);
        }
    } catch (IOException e) {
        log.error("Error while loading freemarker settings from /freemarker.properties", e);
    } catch (TemplateException e) {
        log.error("Error while loading freemarker settings from /freemarker.properties", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException io) {
                log.warn("Unable to close input stream", io);
            }
        }
    }
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase411RemoteMultiThreadsCustomMarshal.java

public static String jdgProperty(String name) {
    Properties props = new Properties();
    try {/*from   w  w w  .  j a  v a  2  s .c o  m*/
        props.load(TestCase411RemoteMultiThreadsCustomMarshal.class.getClassLoader()
                .getResourceAsStream(PROPERTIES_FILE));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    return props.getProperty(name);
}

From source file:com.sap.prd.mobile.ios.mios.EffectiveBuildSettings.java

private static Properties extractBuildSettings(final IXCodeContext context) throws XCodeException {
    List<String> buildActions = Collections.emptyList();
    IOptions options = context.getOptions();
    Map<String, String> managedOptions = new HashMap<String, String>(options.getManagedOptions());
    managedOptions.put(Options.ManagedOption.SHOWBUILDSETTINGS.getOptionName(), null);

    XCodeContext showBuildSettingsContext = new XCodeContext(buildActions, context.getProjectRootDirectory(),
            context.getOut(),/* ww w. j  ava2 s  .c o  m*/
            new Settings(context.getSettings().getUserSettings(), context.getSettings().getManagedSettings()),
            new Options(options.getUserOptions(), managedOptions));

    final CommandLineBuilder cmdLineBuilder = new CommandLineBuilder(showBuildSettingsContext);
    PrintStream out = null;
    ByteArrayOutputStream os = null;
    try {
        os = new ByteArrayOutputStream();
        out = new PrintStream(os, true, Charset.defaultCharset().name());

        final int returnValue = Forker.forkProcess(out, context.getProjectRootDirectory(),
                cmdLineBuilder.createBuildCall());

        if (returnValue != 0) {
            if (out != null)
                out.flush();
            throw new XCodeException(
                    "Could not execute xcodebuild -showBuildSettings command for configuration "
                            + context.getConfiguration() + " and sdk " + context.getSDK() + ": "
                            + new String(os.toByteArray(), Charset.defaultCharset().name()));
        }

        out.flush();
        Properties prop = new Properties();
        prop.load(new ByteArrayInputStream(os.toByteArray()));
        return prop;

    } catch (IOException ex) {
        throw new XCodeException("Cannot extract build properties: " + ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

private static Properties loadProperties(Class<?> aClass, String aFileName, InputStream aResourceAsStream)
        throws NullPointerException {
    try {/*from   ww w  . j a v a2  s .c  o  m*/
        try {
            Properties tProperties = new Properties();
            tProperties.load(aResourceAsStream);
            return tProperties;
        } finally {
            aResourceAsStream.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}