Java Properties Load from File loadCredentials(File credentials, String credentialsAppend)

Here you can find the source of loadCredentials(File credentials, String credentialsAppend)

Description

load Credentials

License

Apache License

Declaration

private static void loadCredentials(File credentials,
            String credentialsAppend) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.Properties;

public class Main {
    /**********************************************
     *// w  w  w.j a v  a  2 s  .  c  o  m
     * Helper methods for test case setup or reporting
     *
     **********************************************/

    private static String username;
    private static String password;
    private static String teamworkServer;
    private static String teamworkPort;
    private static String twCloudServer;
    private static String twCloudPort;

    private static void loadCredentials(File credentials,
            String credentialsAppend) throws IOException {
        InputStream propertiesFileStream = new FileInputStream(credentials);
        if (propertiesFileStream == null) {
            throw new IOException("Credentials stream is invalid.");
        }
        Properties prop = new Properties();
        prop.load(propertiesFileStream);
        if (prop.containsKey("user.name" + credentialsAppend)) {
            username = prop.getProperty("user.name" + credentialsAppend);
            password = prop.getProperty("user.pass" + credentialsAppend);
        } else {
            username = prop.getProperty("user.name") + credentialsAppend;
            password = prop.getProperty("user.pass") + credentialsAppend;
        }
        teamworkServer = prop.getProperty("tw.url");
        teamworkPort = prop.getProperty("tw.port");
        twCloudServer = prop.getProperty("twc.url");
        twCloudPort = prop.getProperty("twc.port");
        if (teamworkServer != null && teamworkServer.indexOf("//") != -1)
            teamworkServer = teamworkServer.substring(teamworkServer
                    .indexOf("//") + 2);
        if (teamworkServer != null && teamworkServer.lastIndexOf(':') != -1)
            teamworkServer = teamworkServer.substring(0,
                    teamworkServer.lastIndexOf(':'));
    }
}

Related

  1. loadConfigProperties()
  2. loadConfigProperties()
  3. loadConfiguration()
  4. loadConfiguration(String file)
  5. loadConfiguration(String filePath)
  6. loadCryptoProperties()
  7. loadDBProperties(String dbConn)
  8. loadDefault(String _file_path)
  9. loadDefaultConfiguration()