List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever.java
private void writeMarkerFile(File destination, URI ovaOrOvfUri) { Properties props = new Properties(); props.setProperty("download-uri", ovaOrOvfUri.toString()); props.setProperty("download-date", new Date().toString()); props.setProperty("download-folder", destination.getAbsolutePath()); try {//from w ww . j a va 2s. com File propFile = new File(destination, MARKER_FILE); try (FileOutputStream fos = new FileOutputStream(propFile)) { try { props.store(fos, null); logger.debug("Stored OVA download progress to {}", propFile.getAbsoluteFile()); } catch (IOException ignore) { } } } catch (IOException e) { } }
From source file:org.semantictools.frame.api.OntologyManager.java
private File writeAssetPropertiesFile(File repoDir, String uri, LdContentType contentType) { repoDir.mkdirs();/*from w w w .j ava2 s. c o m*/ String format = contentType.name(); String fileName = contentType.repoFileName(); Properties properties = new Properties(); properties.setProperty(URI, uri); properties.setProperty(DEFAULT, format); properties.setProperty(format, fileName); FileWriter writer = null; try { File file = new File(repoDir, PROPERTIES_FILENAME); writer = new FileWriter(file); properties.store(writer, null); } catch (Throwable oops) { logger.error("Failed to save properties at " + repoDir, oops); } finally { safeClose(writer); } return new File(repoDir, fileName); }
From source file:com.googlecode.fascinator.storage.filesystem.FileSystemPayload.java
/** * Write metadata to disk, calculating/retrieving if it is not known yet * *///from www.j ava 2s .c o m public void writeMetadata() { if (getLabel() == null) { setLabel(dataFile.getName()); } if (getType() == null) { setType(PayloadType.Source); } if (getContentType() == null) { setContentType(MimeTypeUtil.getMimeType(dataFile)); } try { if (!metaFile.exists()) { metaFile.getParentFile().mkdirs(); metaFile.createNewFile(); } Properties props = new Properties(); OutputStream metaOut = new FileOutputStream(metaFile); props.setProperty("id", getId()); props.setProperty("payloadType", getType().toString()); props.setProperty("label", getLabel()); props.setProperty("linked", String.valueOf(isLinked())); // Sometimes we just can't get it if (getContentType() != null) { props.setProperty("contentType", getContentType()); } props.store(metaOut, "Payload metadata for " + dataFile.getAbsolutePath()); metaOut.close(); } catch (IOException ioe) { log.warn("Failed to read/write metaFile", ioe); } }
From source file:org.openmrs.module.upgradehelperoneten.web.controller.MapDoseToConceptsFormController.java
/** * @param httpSession/*from w w w. j av a 2 s.co m*/ * @param mm * @return */ @RequestMapping(method = RequestMethod.POST) public String onSubmit(HttpSession httpSession, @ModelAttribute("mm") MappingsModel mm) { Properties props = new Properties(); try { // create properties file if it doesn't exist File f = new File(path); if (!f.exists()) { f.createNewFile(); } List<DoseToConceptMapping> mappings = mm.getMappings(); // store the properties for (DoseToConceptMapping m : mappings) { if (StringUtils.isNotBlank(m.getText()) && StringUtils.isNotBlank(m.getConceptId())) { props.setProperty(m.getText(), m.getConceptId().toString()); } } props.store(new FileOutputStream(path), null); } catch (Exception e) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "An error occurred while storing the properties: " + e.getMessage()); return FORM_VIEW; } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "upgradehelperoneten.mappings.saved"); return FORM_VIEW; }
From source file:ch.tatool.app.service.impl.UserAccountServiceImpl.java
/** Writes the description to a properties file. */ private void writeAccountDescFile(UserAccountImpl.InfoImpl info) { // make sure the file exists - create if it doesn't File descriptionFile = createAccountDescFile(info); Properties p = new Properties(); p.setProperty("name", info.getName()); p.setProperty("passwordProtected", String.valueOf(info.isPasswordProtected())); p.setProperty("id", info.getId().toString()); try {// w w w.j ava 2 s. co m FileOutputStream fos = new FileOutputStream(descriptionFile); p.store(fos, "Tatool account info"); fos.close(); } catch (IOException ioe) { logger.error("Unable to write account info file", ioe); } }
From source file:hudson.remoting.Engine.java
@SuppressWarnings({ "ThrowableInstanceNeverThrown" }) @Override/* w w w . j a va 2 s . c o m*/ public void run() { try { boolean first = true; while (true) { if (first) { first = false; } else { if (noReconnect) return; // exit } listener.status("Locating server among " + candidateUrls); Throwable firstError = null; String port = null; for (URL url : candidateUrls) { String s = url.toExternalForm(); if (!s.endsWith("/")) s += '/'; URL salURL = new URL(s + "tcpSlaveAgentListener/"); // find out the TCP port HttpURLConnection con = (HttpURLConnection) salURL.openConnection(); if (con instanceof HttpURLConnection && credentials != null) { String encoding = new String(Base64.encodeBase64(credentials.getBytes())); con.setRequestProperty("Authorization", "Basic " + encoding); } try { try { con.setConnectTimeout(30000); con.setReadTimeout(60000); con.connect(); } catch (IOException x) { if (firstError == null) { firstError = new IOException( "Failed to connect to " + salURL + ": " + x.getMessage()).initCause(x); } continue; } port = con.getHeaderField("X-Hudson-JNLP-Port"); if (con.getResponseCode() != 200) { if (firstError == null) firstError = new Exception(salURL + " is invalid: " + con.getResponseCode() + " " + con.getResponseMessage()); continue; } if (port == null) { if (firstError == null) firstError = new Exception(url + " is not Hudson"); continue; } } finally { con.disconnect(); } // this URL works. From now on, only try this URL hudsonUrl = url; firstError = null; candidateUrls = Collections.singletonList(hudsonUrl); break; } if (firstError != null) { listener.error(firstError); return; } Socket s = connect(port); listener.status("Handshaking"); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); BufferedInputStream in = new BufferedInputStream(s.getInputStream()); dos.writeUTF("Protocol:JNLP2-connect"); Properties props = new Properties(); props.put("Secret-Key", secretKey); props.put("Node-Name", slaveName); if (cookie != null) props.put("Cookie", cookie); ByteArrayOutputStream o = new ByteArrayOutputStream(); props.store(o, null); dos.writeUTF(o.toString("UTF-8")); String greeting = readLine(in); if (greeting.startsWith("Unknown protocol")) { LOGGER.info("The server didn't understand the v2 handshake. Falling back to v1 handshake"); s.close(); s = connect(port); in = new BufferedInputStream(s.getInputStream()); dos = new DataOutputStream(s.getOutputStream()); dos.writeUTF("Protocol:JNLP-connect"); dos.writeUTF(secretKey); dos.writeUTF(slaveName); greeting = readLine(in); // why, oh why didn't I use DataOutputStream when writing to the network? if (!greeting.equals(GREETING_SUCCESS)) { onConnectionRejected(greeting); continue; } } else { if (greeting.equals(GREETING_SUCCESS)) { Properties responses = readResponseHeaders(in); cookie = responses.getProperty("Cookie"); } else { onConnectionRejected(greeting); continue; } } final Socket socket = s; final Channel channel = new Channel("channel", executor, in, new BufferedOutputStream(s.getOutputStream())); PingThread t = new PingThread(channel) { protected void onDead() { try { if (!channel.isInClosed()) { LOGGER.info("Ping failed. Terminating the socket."); socket.close(); } } catch (IOException e) { LOGGER.log(SEVERE, "Failed to terminate the socket", e); } } }; t.start(); listener.status("Connected"); channel.join(); listener.status("Terminated"); t.interrupt(); // make sure the ping thread is terminated listener.onDisconnect(); if (noReconnect) return; // exit // try to connect back to the server every 10 secs. waitForServerToBack(); } } catch (Throwable e) { listener.error(e); } }
From source file:hydrograph.ui.engine.ui.util.UiConverterUtil.java
private void storeParameterData(IFile parameterFile, String jobXmlData) { LOGGER.debug("Creating Parameter(i.e *properties) File at {}", parameterFile.getFullPath()); CanvasDataAdapter canvasDataAdapter = new CanvasDataAdapter(jobXmlData); String defaultParameterValue = ""; Properties properties = new Properties(); ByteArrayOutputStream out = new ByteArrayOutputStream(); for (String parameter : canvasDataAdapter.getParameterList()) { properties.setProperty(parameter, defaultParameterValue); }//from w w w . ja v a 2 s . co m try { properties.store(out, null); if (parameterFile.exists()) { showMessageBox(parameterFile, out, parameterFile.getName() + " already exists.Do you want to replace it?"); } else { parameterFile.create(new ByteArrayInputStream(out.toByteArray()), true, null); } } catch (IOException | CoreException e) { LOGGER.error("Exception occurred while creating parameter file -", e); } finally { try { out.close(); } catch (IOException e) { LOGGER.error("Exception occurred while closing parameter file's out stream -", e); } } }
From source file:net.firejack.platform.generate.service.ResourceGeneratorService.java
private void generateWeb(Structure structure, IPackageDescriptor descriptor) throws Exception { OutputStream out = new FileOutputStream(new File(structure.getResource(), "gateway.properties")); Properties properties = new Properties(); properties.setProperty(Env.FIREJACK_URL.getPropertyName(), Env.FIREJACK_URL.getValue()); properties.setProperty(OpenFlameConfig.MC_SERVER_URL.getKey(), OpenFlameConfig.MC_SERVER_URL.getValue()); properties.setProperty(OpenFlameConfig.MC_PORT.getKey(), OpenFlameConfig.MC_PORT.getValue()); properties.setProperty(GatewayLoader.LOOKUP, DiffUtils.lookup(descriptor.getPath(), descriptor.getName())); properties.setProperty(GatewayLoader.TIMEOUT, "20000"); properties.store(out, null); IOUtils.closeQuietly(out);/*from w w w. j a v a2s .c o m*/ }
From source file:org.hardisonbrewing.s3j.FileSyncer.java
private void uploadProperties(String path, Properties properties) throws Exception { path = getPropertiesPath(path);//from w ww .j a v a 2s.c o m ByteArrayOutputStream outputStream = null; byte[] bytes; try { outputStream = new ByteArrayOutputStream(); properties.store(outputStream, null); bytes = outputStream.toByteArray(); } finally { IOUtil.close(outputStream); } InputStream inputStream = null; try { inputStream = new ByteArrayInputStream(bytes); put(path.toString(), inputStream, bytes.length); } finally { IOUtil.close(inputStream); } }
From source file:net.erdfelt.android.sdkfido.configer.Configer.java
public void persist() throws IOException { Properties props = new Properties(); String key, value;/*w w w .ja va 2 s .com*/ for (Configurable conf : configurables.values()) { if (conf.isInternal()) { continue; // skip Configuration internal configurables } key = conf.getKey(); value = getValue(key); props.put(key, StringUtils.defaultString(value)); } FileWriter writer = null; try { writer = new FileWriter(this.persistFile); props.store(writer, "Written by " + this.getClass().getName()); } finally { IOUtils.closeQuietly(writer); } }