Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

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

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:com.ms.commons.test.tool.exportdata.DatabasePropertiesLoader.java

private static String getNotBlankItem(Properties properties, String name, String key) {
    String nk = "intltest.conn." + name + "." + key;
    String value = properties.getProperty(nk);
    if (value == null) {
        throw new RuntimeException("Value for key '" + nk + "' is empty.");
    }//  ww w. j a va2s  . co m
    return value.trim();
}

From source file:com.edgenius.core.DataRoot.java

public static String getDataRoot() {
    String root = null;/*ww  w. j  a  v a2  s. co  m*/
    root = System.getProperty(rootKey);
    if (root != null && root.trim().length() > 0) {
        log.info("System property includes {}, using this value instead of geniuswiki.properties", rootKey);
        root = formatRoot(root);
        return root;
    }

    //default value
    root = "file:///var/data/geniuswiki/";
    try {
        Properties prop = FileUtil.loadProperties(rootResource);
        root = prop.getProperty(rootKey);
        log.info("System data root from geniuswiki.properties is {}", root);
        //we don't do format for each get request
        //root = formatRoot(root);
    } catch (Exception e) {
        log.error("Load system root failed, please assign it in geniuswiki.properites.", e);
        throw new SystemInitException("Load system root failed, please assign it in geniuswiki.properites.", e);
    }
    return root;
}

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

private static void generateEncryptedPassword(String propsFile, String outFile) throws Exception {
    FileInputStream fis = null;//from   w ww.  ja  v a2s.  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:com.simple.sftpfetch.App.java

private static S3 s3FromProperties(Properties properties) {
    String s3Bucket = properties.getProperty("s3.bucket");
    final String awsAccessKey = properties.getProperty("s3.access.key", "");
    final String awsSecretKey = properties.getProperty("s3.secret.key", "");

    AmazonS3Client client;/*w  w w.ja  v  a2s.  co  m*/
    if (awsAccessKey.isEmpty() || awsSecretKey.isEmpty()) {
        client = new AmazonS3Client();
    } else {
        client = new AmazonS3Client(new SuppliedAWSCredentials(awsAccessKey, awsSecretKey));
    }

    return new S3(client, s3Bucket);
}

From source file:TestDB.java

 /**
 * Gets a connection from the properties specified in the file database.properties
 * @return the database connection//w  w w .ja  va 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:azkaban.jobtype.HadoopSecureHiveWrapper.java

public static boolean shouldProxy(Properties prop) {
    String shouldProxy = prop.getProperty(HadoopSecurityManager.ENABLE_PROXYING);

    return shouldProxy != null && shouldProxy.equals("true");
}

From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java

public static SimpleCobarNode getSimpleCobarNode(String cobarNodeName) throws Exception {
    Properties prop = new Properties();
    prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties"));
    String user = prop.getProperty(cobarNodeName + ".user").trim();
    String password = prop.getProperty(cobarNodeName + ".password").trim();
    String ip = prop.getProperty(cobarNodeName + ".ip").trim();
    int dmlPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".dml.port").trim());
    int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim());
    SimpleCobarNode sCobarNode = new SimpleCobarNode(ip, dmlPort, managerPort, user, password);
    return sCobarNode;
}

From source file:com.google.mr4c.config.execution.DirectoryConfig.java

private static List<String> loadList(Properties props, String name) {
    String data = props.getProperty(name);
    if (data == null) {
        throw new IllegalArgumentException("Missing " + name);
    }//from w w  w  .  jav  a 2  s.com
    data = StringUtils.strip(data);
    if (StringUtils.isEmpty(data)) {
        return Collections.emptyList();
    }
    String[] vals = StringUtils.split(data, ", ");
    return Arrays.asList(vals);
}

From source file:net.padaf.preflight.IsartorTargetFileInformation.java

protected static IsartorTargetFileInformation getInformation(File file, Properties props) {
    Logger logger = Logger.getLogger("test.isartor");
    String key = file.getName();//from  www.j av  a 2  s .  co  m
    String line = props.getProperty(key);
    if (line != null) {
        // only one parameter for the moment
        String error = new StringTokenizer(line, "//").nextToken().trim();
        return new IsartorTargetFileInformation(file, error);
    } else {
        logger.error("There is no expected error for " + key);
        return null;
    }

}

From source file:consumer.kafka.ProcessedOffsetManager.java

private static void persistProcessedOffsets(Properties props, Map<Integer, Long> partitionOffsetMap) {
    ZkState state = new ZkState(props.getProperty(Config.ZOOKEEPER_CONSUMER_CONNECTION));
    for (Map.Entry<Integer, Long> po : partitionOffsetMap.entrySet()) {
        String path = processedPath(po.getKey(), props);
        try {/*from   ww w.  j  a  v a2  s. c o  m*/
            state.writeBytes(path, po.getValue().toString().getBytes());
            LOG.info("Wrote processed offset " + po.getValue() + " for Parittion " + po.getKey());
        } catch (Exception ex) {
            LOG.error(
                    "Error while comitting processed offset " + po.getValue() + " for Parittion " + po.getKey(),
                    ex);
            state.close();
            throw ex;
        }
    }
    state.close();
}