List of usage examples for java.util Properties toString
@Override public synchronized String toString()
From source file:io.github.jrobotframework.syntax.HighlighterUtils.java
public String highlightProperties(Properties properties, String comment) { try {//from w w w . ja v a 2s . c om StringWriter writer = new StringWriter(); properties.store(writer, comment); return highlight(writer.toString(), "properties"); } catch (IOException e) { return properties.toString(); } }
From source file:il.ac.tau.yoavram.pes.SimulationConfigurer.java
private Properties loadPropertiesFromClasspath(Properties props, String filename) throws IOException { InputStream stream = this.getClass().getClassLoader().getResourceAsStream(filename); props.load(stream);/* ww w .j a v a 2 s. com*/ logger.info("Loaded properties from file " + filename + ": " + props.toString()); return props; }
From source file:hydrograph.ui.parametergrid.utils.ParameterFileManager.java
/** * /*from www.j a v a 2 s . com*/ * Save parameters to file * * @param parameterMap * @param object * @param filename * @throws IOException */ public void storeParameters(Map<String, String> parameterMap, IFile filename, String parameterFilePath) throws IOException { Properties properties = new Properties(); properties.setProperty(updatePropertyMap(parameterMap)); File file = new File(parameterFilePath); if (file.exists()) { properties.store(parameterFilePath); logger.debug("Saved properties {} to file {}", properties.toString(), parameterFilePath); } else { if (filename != null) { properties.load(filename.getRawLocation().toString()); properties.store(file.getAbsolutePath()); } } }
From source file:il.ac.tau.yoavram.pes.SimulationConfigurer.java
public SimulationConfigurer(String[] args, Date date) throws IOException { CommandLine cmdLine = PesCommandLineParser.parse(args); // TODO check stuff springXmlConfig = this.getClass().getClassLoader() .getResource(cmdLine.getOptionValue(PesCommandLineParser.OptCode.Xml.toString())); properties = new Properties(); if (cmdLine.hasOption(PesCommandLineParser.OptCode.FileProperties.toString())) { String filename = cmdLine.getOptionValue(PesCommandLineParser.OptCode.FileProperties.toString()); properties = loadPropertiesFromClasspath(properties, filename); }/*ww w . j a va 2 s . c o m*/ if (cmdLine.hasOption(PesCommandLineParser.OptCode.Properties.toString())) { Properties cmdLineProps = cmdLine .getOptionProperties(PesCommandLineParser.OptCode.Properties.toString()); properties.putAll(cmdLineProps); logger.info("Command line properties given: " + cmdLineProps.toString()); } String log4jConfigFilename = null; if (cmdLine.hasOption(PesCommandLineParser.OptCode.Log.toString())) { log4jConfigFilename = cmdLine.getOptionValue(PesCommandLineParser.OptCode.Log.toString()); } else { log4jConfigFilename = LOG4J_DEFAULT_CONFIG_FILE; } Properties log4jProps = loadPropertiesFromClasspath(log4jConfigFilename); if (!properties.containsKey(JOB_NAME_KEY)) { String fullpath = springXmlConfig.getFile(); String[] parts = fullpath.split("/"); String lastPart = parts[parts.length - 1]; String filename = lastPart.replace(XML_EXTENSION, EMPTY_STRING); properties.setProperty(JOB_NAME_KEY, filename); } if (!properties.containsKey(TIME)) { properties.setProperty(TIME, TimeUtils.formatDate(date)); } logFilename = properties.getProperty("log.dir") + File.separator + properties.getProperty(JOB_NAME_KEY) + File.separator + properties.getProperty(JOB_NAME_KEY) + '.' + properties.getProperty(TIME) + LOG_EXTENTION; log4jProps.setProperty("log4j.appender.FILE.File", logFilename); logger.info("Logging to file " + logFilename); PropertyConfigurator.configure(log4jProps); logger.info("Finished configuring simulation"); }
From source file:org.apache.eagle.alert.util.ConfigUtilsTest.java
@Test public void testToProperties() throws IOException { Config config = ConfigFactory.parseFile(genConfig()); Properties properties = ConfigUtils.toProperties(config); System.out.print(properties); Assert.assertEquals(/*w w w. j av a 2 s . c o m*/ "{metric={sink={stdout={}, elasticsearch={hosts=[localhost:9200], index=alert_metric_test}, kafka={topic=alert_metric_test, bootstrap.servers=localhost:9092}, logger={level=INFO}}}, zkConfig={zkQuorum=localhost:2181, zkRoot=/alert}}", properties.toString()); }
From source file:org.ejbca.util.keystore.KeyTools.java
/** Creates a SUN or IAIK PKCS#11 provider using the passed in pkcs11 library. First we try to see if the IAIK provider is available, * because it supports more algorithms. If the IAIK provider is not available in the classpath, we try the SUN provider. * /*from ww w. j a va2 s. co m*/ * @param slot pkcs11 slot number or null if a config file name is provided as fileName * @param fileName the manufacturers provided pkcs11 library (.dll or .so) or config file name if slot is null * @param isIndex specifies if the slot is a slot number or a slotIndex * @param attributesFile a file specifying PKCS#11 attributes (used mainly for key generation) in the format specified in the "JavaTM PKCS#11 Reference Guide", http://java.sun.com/javase/6/docs/technotes/guides/security/p11guide.html * * Example contents of attributes file: * * attributes(generate,CKO_PRIVATE_KEY,*) = { * CKA_PRIVATE = true * CKA_SIGN = true * CKA_DECRYPT = true * CKA_TOKEN = true * } * * See also html documentation for PKCS#11 HSMs in EJBCA. * * @return AuthProvider of type "sun.security.pkcs11.SunPKCS11" or * @throws IOException if the pkcs11 library can not be found, or the PKCS11 provider can not be created. */ public static Provider getP11Provider(final String slot, final String fileName, final boolean isIndex, final String attributesFile) throws IOException { if (StringUtils.isEmpty(fileName)) { throw new IOException("A file name must be supplied."); } final File libFile = new File(fileName); if (!libFile.isFile() || !libFile.canRead()) { throw new IOException("The file " + fileName + " can't be read."); } if (slot == null) { return getP11Provider(new FileInputStream(fileName), null); } // Properties for the SUN PKCS#11 provider final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter pw = new PrintWriter(baos); pw.println("name = " + libFile.getName() + "-slot" + slot); pw.println("library = " + libFile.getCanonicalPath()); final int slotNr; try { if (slot.length() > 0) { slotNr = Integer.parseInt(slot); } else { slotNr = -1; } } catch (NumberFormatException e) { throw new IOException("Slot nr " + slot + " not an integer."); } if (slotNr >= 0) { pw.println("slot" + (isIndex ? "ListIndex" : "") + " = " + slot); } if (attributesFile != null) { byte[] attrs = FileTools.readFiletoBuffer(attributesFile); pw.println(new String(attrs)); } else { // setting the attributes like this should work for most HSMs. pw.println("attributes(*, *, *) = {"); pw.println(" CKA_TOKEN = true"); // all created objects should be permanent. They should not only exiswt during the session. pw.println("}"); pw.println("attributes(*, CKO_PUBLIC_KEY, *) = {"); pw.println(" CKA_ENCRYPT = true"); pw.println(" CKA_VERIFY = true"); pw.println(" CKA_WRAP = true");// no harm allowing wrapping of keys. created private keys can not be wrapped anyway since CKA_EXTRACTABLE is false. pw.println("}"); pw.println("attributes(*, CKO_PRIVATE_KEY, *) = {"); pw.println(" CKA_PRIVATE = true"); // always require logon with password to use the key pw.println(" CKA_SENSITIVE = true"); // not possible to read the key pw.println(" CKA_EXTRACTABLE = false"); // not possible to wrap the key with another key pw.println(" CKA_DECRYPT = true"); pw.println(" CKA_SIGN = true"); pw.println(" CKA_UNWRAP = true");// for unwrapping of session keys, pw.println("}"); } pw.flush(); pw.close(); if (log.isDebugEnabled()) { log.debug(baos.toString()); } // Properties for the IAIK PKCS#11 provider final Properties prop = new Properties(); prop.setProperty("PKCS11_NATIVE_MODULE", libFile.getCanonicalPath()); // If using Slot Index it is denoted by brackets in iaik prop.setProperty("SLOT_ID", isIndex ? ("[" + slot + "]") : slot); if (log.isDebugEnabled()) { log.debug(prop.toString()); } return getP11Provider(new ByteArrayInputStream(baos.toByteArray()), prop); }
From source file:org.fabrican.extension.variable.provider.VariableProviderProxy.java
public Properties getVariables(FabricEngineInfo engineInfo, StackInfo stackInfo, ComponentInfo componentInfo) { MapContext jc = new MapContext(); jc.set("engineInfo", engineInfo); jc.set("stackInfo", stackInfo); jc.set("componentInfo", componentInfo); String p = evaluate(getPrimaryKey(), jc); String s = evaluate(getSecondaryKey(), jc); ;/*ww w .j av a2s . c o m*/ if (getServerURL() == null) { throw new IllegalArgumentException("serverURL is not set"); } String u = getServerURL(); try { u += "?primary=" + (p == null ? "" : URLEncoder.encode(p.trim(), "utf-8")); u += "&secondary=" + (s == null ? "" : URLEncoder.encode(s.trim(), "utf-8")); } catch (UnsupportedEncodingException e) { // we always have "UTF-8" but anyway throw new RuntimeException("utf-8 not supported", e); } InputStream is = null; try { URL url = new URL(u); URLConnection c = url.openConnection(); is = c.getInputStream(); JSONTokener tokener = new JSONTokener(new InputStreamReader(is, "utf-8")); JSONObject jObj = new JSONObject(tokener); Properties r = new Properties(); @SuppressWarnings("unchecked") Iterator<String> keys = jObj.keys(); while (keys.hasNext()) { String k = keys.next(); r.put(k, jObj.getString(k)); } String msg = "no variables"; if (r.size() > 0) { msg = r.toString(); } ContainerUtils.getLogger(this).fine( "Provided " + msg + " to Engine " + engineInfo.getUsername() + "-" + engineInfo.getInstance()); return r; } catch (IOException ioe) { throw new RuntimeException("failed to connection to web server", ioe); } catch (JSONException je) { throw new RuntimeException("failed to parse response from web server", je); } finally { try { if (is != null) { is.close(); } } catch (Exception e) { } } }
From source file:org.apache.openaz.xacml.rest.XACMLPdpRegisterThread.java
/** * This is our thread that runs on startup to tell the PAP server we are up-and-running. *//*from ww w . jav a 2 s. c om*/ @Override public void run() { synchronized (this) { this.isRunning = true; } boolean registered = false; boolean interrupted = false; int seconds; try { seconds = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER_SLEEP)); } catch (NumberFormatException e) { logger.error("REGISTER_SLEEP: ", e); seconds = 5; } if (seconds < 5) { seconds = 5; } int retries; try { retries = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER_RETRIES)); } catch (NumberFormatException e) { logger.error("REGISTER_SLEEP: ", e); retries = -1; } while (!registered && !interrupted && this.isRunning()) { HttpURLConnection connection = null; try { // // Get the PAP Servlet URL // URL url = new URL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL)); logger.info("Registering with " + url.toString()); boolean finished = false; while (!finished) { // // Open up the connection // connection = (HttpURLConnection) url.openConnection(); // // Setup our method and headers // connection.setRequestMethod("POST"); connection.setRequestProperty("Accept", "text/x-java-properties"); connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID, XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID)); connection.setUseCaches(false); // // Adding this in. It seems the HttpUrlConnection class does NOT // properly forward our headers for POST re-direction. It does so // for a GET re-direction. // // So we need to handle this ourselves. // connection.setInstanceFollowRedirects(false); connection.setDoOutput(true); connection.setDoInput(true); try { // // Send our current policy configuration // String lists = XACMLProperties.PROP_ROOTPOLICIES + "=" + XACMLProperties.getProperty(XACMLProperties.PROP_ROOTPOLICIES); lists = lists + "\n" + XACMLProperties.PROP_REFERENCEDPOLICIES + "=" + XACMLProperties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES) + "\n"; try (InputStream listsInputStream = new ByteArrayInputStream(lists.getBytes()); InputStream pipInputStream = Files.newInputStream(XACMLPdpLoader.getPIPConfig()); OutputStream os = connection.getOutputStream()) { IOUtils.copy(listsInputStream, os); // // Send our current PIP configuration // IOUtils.copy(pipInputStream, os); } } catch (Exception e) { logger.error("Failed to send property file", e); } // // Do the connect // connection.connect(); if (connection.getResponseCode() == 204) { logger.info("Success. We are configured correctly."); finished = true; registered = true; } else if (connection.getResponseCode() == 200) { logger.info("Success. We have a new configuration."); Properties properties = new Properties(); properties.load(connection.getInputStream()); logger.info("New properties: " + properties.toString()); // // Queue it // // The incoming properties does NOT include urls PutRequest req = new PutRequest(XACMLProperties.getPolicyProperties(properties, false), XACMLProperties.getPipProperties(properties)); XACMLPdpServlet.queue.offer(req); // // We are now registered // finished = true; registered = true; } else if (connection.getResponseCode() >= 300 && connection.getResponseCode() <= 399) { // // Re-direction // String newLocation = connection.getHeaderField("Location"); if (newLocation == null || newLocation.isEmpty()) { logger.warn("Did not receive a valid re-direction location"); finished = true; } else { logger.info("New Location: " + newLocation); url = new URL(newLocation); } } else { logger.warn("Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); finished = true; } } } catch (Exception e) { logger.error(e); } finally { // cleanup the connection if (connection != null) { try { // For some reason trying to get the inputStream from the connection // throws an exception rather than returning null when the InputStream does not exist. InputStream is = null; try { is = connection.getInputStream(); } catch (Exception e1) { //NOPMD // ignore this } if (is != null) { is.close(); } } catch (IOException ex) { logger.error("Failed to close connection: " + ex, ex); } connection.disconnect(); } } // // Wait a little while to try again // try { if (!registered) { if (retries > 0) { retries--; } else if (retries == 0) { break; } Thread.sleep(seconds * 1000); } } catch (InterruptedException e) { interrupted = true; this.terminate(); } } synchronized (this) { this.isRunning = false; } logger.info("Thread exiting...(registered=" + registered + ", interrupted=" + interrupted + ", isRunning=" + this.isRunning() + ", retries=" + retries + ")"); }
From source file:com.streamsets.pipeline.kafka.impl.BaseKafkaConsumer09.java
protected void createConsumer() { Properties kafkaConsumerProperties = new Properties(); configureKafkaProperties(kafkaConsumerProperties); LOG.debug("Creating Kafka Consumer with properties {}", kafkaConsumerProperties.toString()); kafkaConsumer = new KafkaConsumer<>(kafkaConsumerProperties); }
From source file:com.symbian.driver.remoting.packaging.installer.PackageInstaller.java
/** * //from w w w . j a v a2 s . c o m * @see com.symbian.driver.remoting.packaging.installer.Installer#Install(java.lang.String) */ public void Install(File aTestPackage) { try { TDConfig CONFIG = TDConfig.getInstance(); File reposFile = CONFIG.getPreferenceFile(TDConfig.REPOSITORY_ROOT); File xmlRootFile = CONFIG.getPreferenceFile(TDConfig.XML_ROOT); File outLocation = CONFIG.getPreferenceFile(TDConfig.EPOC_ROOT); File out = aTestPackage; Zipper.Unzip(out, outLocation); Properties manifest = new Properties(); manifest.load(new FileInputStream( (outLocation.getAbsolutePath() + File.separator + "Manifest.mf").replaceAll("\\\\+", "\\\\"))); String platform = manifest.getProperty("platform"); String romFile = manifest.getProperty("romFile"); LOGGER.log(Level.INFO, "Package information: \n\t" + manifest.toString()); // unzip it File lDep = new File((outLocation.getAbsolutePath() + File.separator + "Dependencies.zip") .replaceAll("\\\\+", "\\\\")); File repository = new File((outLocation.getAbsolutePath() + File.separator + "Repository.zip") .replaceAll("\\\\+", "\\\\")); File lXml = new File( (outLocation.getAbsolutePath() + File.separator + "Xml.zip").replaceAll("\\\\+", "\\\\")); File lStat = new File( (outLocation.getAbsolutePath() + File.separator + "Stat.zip").replaceAll("\\\\+", "\\\\")); try { if (lDep.exists()) { LOGGER.log(Level.INFO, "Unzipping " + lDep.toString()); Zipper.Unzip(lDep, outLocation); lDep.delete(); } if (repository.exists()) { LOGGER.log(Level.INFO, "Unzipping " + repository.toString()); Zipper.Unzip(repository, reposFile); repository.delete(); } if (lXml.exists()) { LOGGER.log(Level.INFO, "Unzipping " + lXml.toString()); Zipper.Unzip(lXml, xmlRootFile); lXml.delete(); } if (lStat.exists()) { LOGGER.log(Level.INFO, "Unzipping " + lStat.toString()); Zipper.Unzip(lStat, outLocation); lStat.delete(); } if (romFile != null) { if (Epoc.isTargetEmulator(platform)) { File imageFile = new File(outLocation.getAbsolutePath(), romFile); if (imageFile.exists()) { LOGGER.log(Level.INFO, "Unzipping emulator image " + imageFile.toString()); Zipper.Unzip(imageFile, outLocation); imageFile.delete(); } } else { // write("Flashing "+romFile+" through port // "+trgtestPort); // restoreRom(romFile,platform,trgtestPort); } } } catch (IOException lE) { LOGGER.log(Level.SEVERE, "Failed to unzip file.", lE); } } catch (IOException lE) { LOGGER.log(Level.SEVERE, "package installation failed ", lE); } catch (ParseException e) { LOGGER.log(Level.SEVERE, "Could not get preference: " + e.getMessage(), e); } }