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:net.ontopia.utils.PropertyUtils.java

public static Properties loadProperties(InputStream istream) throws IOException {
    Properties properties = new Properties();
    properties.load(istream);
    return properties;
}

From source file:TestDB.java

 /**
 * Gets a connection from the properties specified in the file database.properties
 * @return the database connection//from  w ww .j  a  v a  2s  .  c  o  m
 */
public static Connection getConnection() throws SQLException, IOException
{
   Properties props = new Properties();
   FileInputStream in = new FileInputStream("database.properties");
   props.load(in);
   in.close();

   String drivers = props.getProperty("jdbc.drivers");
   if (drivers != null) System.setProperty("jdbc.drivers", drivers);
   String url = props.getProperty("jdbc.url");
   String username = props.getProperty("jdbc.username");
   String password = props.getProperty("jdbc.password");

   return DriverManager.getConnection(url, username, password);
}

From source file:org.eclipse.swordfish.core.test.util.base.BaseMavenOsgiTestCase.java

protected static String getBundleVersion(String groupId, String artifactId) {
    Properties dependencies = null;
    InputStream inputStream = null;
    try {// w  w w  .j a  v  a2s  .c om
        inputStream = BaseMavenOsgiTestCase.class.getClassLoader()
                .getResource("META-INF/maven/dependencies.properties").openStream();
        Properties prop = new Properties();
        prop.load(inputStream);
        dependencies = prop;
    } catch (IOException e) {
        throw new IllegalStateException("Unable to load dependencies informations", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new AssertionError();
            }
        }
    }
    String version = dependencies.getProperty(groupId + "/" + artifactId + "/version");
    if (version == null) {
        throw new IllegalStateException(
                "Unable to find dependency information for: " + groupId + "/" + artifactId + "/version");
    }
    return version;
}

From source file:aot.util.IOUtil.java

public static Properties loadProperties(Class clazz, String name) {
    //        log.info("Load properties '{}/{}'", clazz.getPackage().getName(), name);
    try (InputStream input = clazz.getResourceAsStream(name)) {
        Properties properties = new Properties();
        properties.load(input);
        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }//from  w  w  w.j  a v  a 2  s  .c  o m
}

From source file:com.opengamma.examples.simulated.DBTestUtils.java

public static Properties loadProperties(String configResourceLocation) throws IOException {
    Resource resource = ResourceUtils.createResource(configResourceLocation);
    Properties props = new Properties();
    props.load(resource.getInputStream());

    String nextConfiguration = props.getProperty("MANAGER.NEXT.FILE");
    if (nextConfiguration != null) {
        resource = ResourceUtils.createResource(nextConfiguration);
        Properties parentProps = new Properties();
        parentProps.load(resource.getInputStream());
        for (String key : props.stringPropertyNames()) {
            parentProps.put(key, props.getProperty(key));
        }/*from w ww  .  j  ava2s  . c om*/
        props = parentProps;
    }

    for (String key : props.stringPropertyNames()) {
        s_logger.debug("\t{}={}", key, props.getProperty(key));
    }

    return props;
}

From source file:com.rdonasco.security.utils.EncryptionUtil.java

private static void generateEncryptedPassword(String propsFile, String outFile) throws Exception {
    FileInputStream fis = null;/*www  .j  a v a  2  s.  c o  m*/
    FileOutputStream fos = null;
    try {
        fis = new FileInputStream(new File(propsFile));
        Properties props = new Properties();
        props.load(fis);
        String stringToEncrypt = props.getProperty("password");
        String passphrase = props.getProperty("passphrase");
        System.out.println("passphrase:<" + passphrase + ">");
        System.out.println("encrypting " + stringToEncrypt);
        String encrypted = EncryptionUtil.encryptWithPassword(stringToEncrypt, passphrase);
        System.out.println("encrypted:" + encrypted);
        String decrypted = EncryptionUtil.decryptWithPassword(encrypted, passphrase);
        System.out.println("decrypted:" + decrypted);
        if (!stringToEncrypt.equals(decrypted)) {
            throw new Exception(
                    "password cannot be decrypted properly, please choose another password or change passphrase.");
        }
        Properties keyProperties = new Properties();
        keyProperties.put("encrypted", encrypted);
        fos = new FileOutputStream(new File(outFile));
        keyProperties.store(fos,
                "last updated " + new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss").format(new Date()));

    } finally {
        if (null != fis) {
            try {
                fis.close();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
        if (null != fos) {
            try {
                fos.close();
            } catch (IOException ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.TagsetMappingFactory.java

public static Map<String, String> loadProperties(URL aUrl) {
    InputStream is = null;//  w  w w  . j  a va2  s .  c  om
    try {
        is = aUrl.openStream();
        Properties mappingProperties = new Properties();
        mappingProperties.load(is);
        Map<String, String> mapping = new HashMap<String, String>();
        for (String key : mappingProperties.stringPropertyNames()) {
            mapping.put(key.trim(), mappingProperties.getProperty(key).trim());
        }
        return mapping;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        closeQuietly(is);
    }
}

From source file:Main.java

public static void loadHashMapData() throws IOException {
    HashMap<String, String> hashMap = new HashMap<String, String>();
    Properties properties = new Properties();

    File file = new File(HASHMAPFILEPATH);
    if (file.exists()) {
        properties.load(new FileInputStream(HASHMAPFILEPATH));

        for (String key : properties.stringPropertyNames()) {
            hashMap.put(key, properties.getProperty(key));
            GPSDataMap = hashMap;//from ww w  . j  a v  a2  s .co  m
        }
    } else {
        file.createNewFile();
    }
}

From source file:Main.java

/**
 * (android) read from file//from  w ww.j av a2s.  co  m
 * 
 * @param fileName
 * @return
 */
public static String androidFileload(Context con, String fileName) {
    Properties properties = new Properties();
    try {
        FileInputStream stream = con.openFileInput(fileName);
        properties.load(stream);
    } catch (FileNotFoundException e) {
        return null;
    } catch (IOException e) {
        return null;
    }

    return properties.get(FILE_ENCODING).toString();
}

From source file:com.subakva.formicid.Main.java

private static void defineTasks(Container container) throws IOException {
    Scriptable scope = container.getScope();
    InputStream stream = Task.class.getResourceAsStream("/org/apache/tools/ant/taskdefs/defaults.properties");
    Properties p = new Properties();
    p.load(stream);

    for (Iterator iter = p.keySet().iterator(); iter.hasNext();) {
        String taskType = (String) iter.next();
        String functionName = taskType;
        if ("delete".equals(taskType)) {
            functionName = "rm";
        }//from w ww .j  av a  2s .co  m
        scope.put(functionName, scope, new TaskFunction(container, taskType));
        //Path, Resource, Zip$WhenEmpty, Jar$FilesetManifestConfig, Zip$Duplicate,
        //ExecuteOn$FileDirBoth, Commandline, ExecuteStreamHandler, Tar$TarLongFileMode,
        //Tar$TarCompressionMethod, Javadoc$AccessType, Echo$EchoLevel, Definer$OnError,
        //Definer$Format, ClassLoader, Available$FileDir, Untar$UntarCompressionMethod,
        //WaitFor$Unit, Writer, FixCRLF$CrLf, EmailTask$Encoding, Checksum$FormatElement,
        //Reference, Recorder$VerbosityLevelChoices, Recorder$ActionChoices,
        //FixCRLF$AddAsisRemove, URL, Comparison, Date, Length$FileMode, SQLExec$OnError,
        //SQLExec$DelimiterType
    }
}