Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

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

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:org.paxml.util.PaxmlUtils.java

/**
 * Trim the property names and values and return in a new Properties object.
 * // w  w w. java2 s.c  o  m
 * @param props
 *            properties
 * @return the new Properties object contained the trimmed names and values.
 */
public static Properties trimProperties(Properties props) {
    Properties result = new Properties();
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        String key = entry.getKey().toString();
        String value = entry.getValue().toString();
        result.put(key.trim(), value.trim());
    }
    return result;
}

From source file:com.streamsets.pipeline.kafka.common.KafkaTestUtil.java

public static List<KafkaStream<byte[], byte[]>> createKafkaStream(String zookeeperConnectString, String topic,
        int partitions) {
    //create consumer
    Properties consumerProps = new Properties();
    consumerProps.put("zookeeper.connect", zookeeperConnectString);
    consumerProps.put("group.id", "testClient");
    consumerProps.put("zookeeper.session.timeout.ms", "6000");
    consumerProps.put("zookeeper.sync.time.ms", "200");
    consumerProps.put("auto.commit.interval.ms", "1000");
    consumerProps.put("consumer.timeout.ms", "500");
    ConsumerConfig consumerConfig = new ConsumerConfig(consumerProps);
    ConsumerConnector consumer = Consumer.createJavaConsumerConnector(consumerConfig);
    Map<String, Integer> topicCountMap = new HashMap<>();
    topicCountMap.put(topic, partitions);
    Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
    return consumerMap.get(topic);

}

From source file:com.esri.geoportal.commons.pdf.PdfUtils.java

/**
 * Generates a Dublin-Core XML string from the given PDF's metadata.
 * /*from  ww  w.  j  a v  a 2  s .  c  o  m*/
 * @param pdfBytes the PDF file to parse
 * @param fileName the name of the PDF file. Used if the PDF metadata doesn't specify a title.
 * @param url the source location of the PDF file. Used to set the XML's "resource URL".
 * @param geometryServiceUrl url of a <a href="https://developers.arcgis.com/rest/services-reference/geometry-service.htm">geometry service</a> for reprojecting coordinates. 
 * 
 * @return Dublin-Core XML metadata
 */
public static byte[] generateMetadataXML(byte[] pdfBytes, String fileName, String url,
        String geometryServiceUrl) throws IOException {
    byte[] bytes = null;

    // Read in the PDF metadata.
    Properties metaProps = readMetadata(pdfBytes, fileName, geometryServiceUrl);

    // Build out the XML metadata
    if (metaProps != null) {
        Properties props = new Properties();
        props.put(WKAConstants.WKA_TITLE, metaProps.get(PdfUtils.PROP_TITLE));
        props.put(WKAConstants.WKA_DESCRIPTION, metaProps.get(PdfUtils.PROP_SUBJECT));
        props.put(WKAConstants.WKA_MODIFIED, metaProps.get(PdfUtils.PROP_MODIFICATION_DATE));
        props.put(WKAConstants.WKA_BBOX, metaProps.getOrDefault(PdfUtils.PROP_BBOX, DEFAULT_BBOX));
        props.put(WKAConstants.WKA_RESOURCE_URL, url);

        try {
            MapAttribute attr = AttributeUtils.fromProperties(props);
            Document document = new SimpleDcMetaBuilder().create(attr);
            bytes = XmlUtils.toString(document).getBytes("UTF-8");
        } catch (MetaException | TransformerException ex) {
            throw new IOException(ex);
        }
    }

    return bytes;
}

From source file:org.apache.lens.regression.util.Util.java

public static String runRemoteCommand(String command) throws JSchException, IOException {
    StringBuilder outputBuffer = new StringBuilder();
    StringBuilder print = new StringBuilder();

    String userName = Util.getProperty("lens.remote.username");
    String host = Util.getProperty("lens.remote.host");
    String password = Util.getProperty("lens.remote.password");

    log.info("Running command : {} on host : {} with user as {}", command, host, userName);

    JSch jsch = new JSch();
    Session session = jsch.getSession(userName, host, 22);
    session.setPassword(password);//from  ww w. j  av  a 2  s . com

    Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");

    session.setServerAliveInterval(10000);
    session.setConfig(config);
    session.connect(0);

    ChannelExec channel = (ChannelExec) session.openChannel("exec");
    InputStream commandOutput = channel.getInputStream();

    channel.setCommand(command);
    channel.connect();
    int readByte = commandOutput.read();
    char toAppend = ' ';
    while (readByte != 0xffffffff) {
        toAppend = (char) readByte;
        outputBuffer.append(toAppend);
        readByte = commandOutput.read();
        if (toAppend == '\n') {
            log.info(print.toString());
            print = new StringBuilder();
        } else {
            print.append(toAppend);
        }
    }
    channel.disconnect();
    session.disconnect();
    return outputBuffer.toString();
}

From source file:at.kc.tugraz.ss.cloud.impl.fct.op.SSCloudPublishServiceFct.java

License:asdf

private static void copyFilesRemotely(final String localWorkTmpDirPath, final String serviceDestDirPath,
        final String host, final String userName, final String password) throws Exception {

    Session session = null;/*  w w  w . jav  a 2s  . c o  m*/
    Channel channel = null;
    FileInputStream in = null;

    try {

        final Properties config = new java.util.Properties();
        final JSch jsch = new JSch();
        final ChannelSftp channelSftp;

        session = jsch.getSession(userName, host, 22);

        config.put("StrictHostKeyChecking", "no");
        session.setPassword(password);
        session.setConfig(config);
        session.connect();

        channel = session.openChannel("sftp");
        channel.connect();

        channelSftp = (ChannelSftp) channel;

        try {
            channelSftp.mkdir(serviceDestDirPath);
        } catch (SftpException error) {
            SSLogU.warn("service folder already exists");
        }

        channelSftp.cd(serviceDestDirPath);

        in = SSFileU.openFileForRead(localWorkTmpDirPath + SSVocConf.fileNameSSSConf);

        channelSftp.put(in, SSVocConf.fileNameSSSConf);

        in.close();

        in = SSFileU.openFileForRead(SSFileU.dirWorking() + SSVocConf.fileNameSSSJar);

        channelSftp.put(in, SSVocConf.fileNameSSSJar);

        in.close();

        in = SSFileU.openFileForRead(SSFileU.dirWorking() + SSVocConf.fileNameLog4JProperties);

        channelSftp.put(in, SSVocConf.fileNameLog4JProperties);

        in.close();

        in = SSFileU.openFileForRead(SSFileU.dirWorking() + SSVocConf.fileNameRunitSh);

        channelSftp.put(in, SSVocConf.fileNameRunitSh);

        in.close();

        try {
            channelSftp.mkdir(serviceDestDirPath + SSVocConf.dirNameLib);
        } catch (SftpException error) {
            SSLogU.warn("service lib folder already exists");
        }

        channelSftp.cd(serviceDestDirPath + SSVocConf.dirNameLib);

        for (File file : SSFileU.filesForDirPath(SSFileU.dirWorking() + SSVocConf.dirNameLib)) {

            in = new FileInputStream(file);

            channelSftp.put(in, file.getName());

            in.close();
        }

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (in != null) {
            in.close();
        }

        if (channel != null) {
            channel.disconnect();
        }

        if (session != null) {
            session.disconnect();
        }

        FileUtils.deleteDirectory(new File(localWorkTmpDirPath));
    }
}

From source file:com.streamsets.pipeline.kafka.common.KafkaTestUtil.java

public static void startKafkaBrokers(int numberOfBrokers) {
    kafkaServers = new ArrayList<>(numberOfBrokers);
    kafkaProps = new HashMap<>();
    // setup Broker
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numberOfBrokers; i++) {
        int port = TestUtils.choosePort();
        Properties props = TestUtils.createBrokerConfig(i, port);
        props.put("auto.create.topics.enable", "false");
        kafkaServers.add(TestUtils.createServer(new KafkaConfig(props), new MockTime()));
        sb.append("localhost:" + port).append(",");
    }/*  w  ww  .j a v  a 2s.c o m*/
    metadataBrokerURI = sb.deleteCharAt(sb.length() - 1).toString();
    LOG.info("Setting metadataBrokerList and auto.offset.reset for test case");
    kafkaProps.put("auto.offset.reset", "smallest");
}

From source file:edu.umd.cs.eclipse.courseProjectManager.EclipseLaunchEventLog.java

/**
 * Uploads a String containing eclipse launch events to the server.
 * /*  w w w.  j av a 2s. c  om*/
 * @param launchEvents
 *            the eclipse launch events to be uploaded
 * @param classAccount
 *            the class account of the user who generated the launch events
 * @param oneTimePassword
 *            the one-time password of the user who generated the launch
 *            events
 * @param url
 *            the URL of the server that will accept the launch events
 * @throws IOException
 * @throws HttpException
 */
private static int uploadMessages(String launchEvents, Properties props) throws IOException, HttpException {
    // Replace the path with /eclipse/LogEclipseLaunchEvent.
    if (!props.containsKey("submitURL")) {
        props.put("submitURL", "https://submit.cs.umd.edu:8443/eclipse/LogEclipseLaunchEvent");
    }
    String submitURL = props.getProperty("submitURL");
    Debug.print("submitURL: " + props.getProperty("submitURL"));
    int index = submitURL.indexOf("/eclipse/");
    if (index == -1) {
        Debug.print("Cannot find submitURL in .submitUser file");
        throw new IOException("Cannot find submitURL in .submitUser file");
    }
    submitURL = submitURL.substring(0, index) + "/eclipse/LogEclipseLaunchEvent";
    String version = System.getProperties().getProperty("java.runtime.version");
    boolean useEasyHttps = version.startsWith("1.3") || version.startsWith("1.2") || version.startsWith("1.4.0")
            || version.startsWith("1.4.1") || version.startsWith("1.4.2_0") && version.charAt(7) < '5';
    if (useEasyHttps) {
        if (submitURL.startsWith("https"))
            submitURL = "easy" + submitURL;
    }
    Debug.print("submitURL: " + submitURL);
    MultipartPostMethod filePost = new MultipartPostMethod(submitURL);

    // add filepart
    byte[] bytes = launchEvents.getBytes();
    filePost.addPart(new FilePart("eclipseLaunchEvent", new ByteArrayPartSource("eclipseLaunchEvent", bytes)));

    TurninProjectAction.addAllPropertiesButSubmitURL(props, filePost);

    filePost.addParameter("clientTime", Long.toString(System.currentTimeMillis()));

    HttpClient client = new HttpClient();
    client.setConnectionTimeout(5000);

    int status = client.executeMethod(filePost);
    if (status != HttpStatus.SC_OK) {
        System.err.println(filePost.getResponseBodyAsString());
        throw new HttpException("status is: " + status);
    }
    return status;
}

From source file:uk.ac.cam.cl.dtg.picky.client.analytics.Analytics.java

private static void fillProperties(Properties properties, Dataset dataset) {
    if (dataset == null)
        return;/*w  w w .j  a va2  s. c  om*/

    List<FileEntry> files = dataset.getFiles();

    long numberOfChunks = files.stream().flatMap(f -> f.getBlocks().stream())
            .flatMap(b -> b.getChunks().stream()).count();

    double avgNumberofBlocks = files.stream().mapToLong(f -> f.getBlocks().size()).average().getAsDouble();

    properties.put(KEY_DATASET_DESCRIPTION, Strings.nullToEmpty(dataset.getDescription()));
    properties.put(KEY_DATASET_ID, dataset.getId());
    properties.put(KEY_DATASET_NUMBER_OF_FILES, "" + files.size());
    properties.put(KEY_DATASET_NUMBER_OF_CHUNKS, "" + numberOfChunks);
    properties.put(KEY_DATASET_AVG_NUMBER_OF_BLOCKS, "" + avgNumberofBlocks);
}

From source file:it.cnr.icar.eric.common.AbstractProperties.java

protected static void initEricHomeDir(Properties properties) {
    //String ericHome = getEricHome(properties);
    String ericHome = getEricHome();
    File ericHomeFile = new File(ericHome);
    initHomeDir(ERIC_HOME_KEY, ericHomeFile);
    properties.put(ERIC_HOME_KEY, ericHome);
}

From source file:XMLUtils.java

public static String toString(Source source, Properties props) throws TransformerException, IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    StreamResult sr = new StreamResult(bos);
    Transformer trans = newTransformer();
    if (props == null) {
        props = new Properties();
        props.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
    }// ww  w.  ja v a2  s  . com
    trans.setOutputProperties(props);
    trans.transform(source, sr);
    bos.close();
    return bos.toString();
}