List of usage examples for java.util Properties store
public void store(OutputStream out, String comments) throws IOException
From source file:org.pepstock.jem.commands.util.HttpUtil.java
/** * Performs the login using user and password * /* w w w . ja va 2 s .c o m*/ * @param user user to authenticate * @param password password to authenticate * @param url http URL to call * @param httpclient hhtp client already created * @throws ClientProtocolException if any errors occurs on calling the * servlet * @throws IOException if I/O error occurs */ private static void login(String user, String password, String url, HttpClient httpclient) throws ClientProtocolException, IOException { // account info in a properties Properties properties = new Properties(); properties.setProperty(USER_PROPERTY_KEY, user); properties.setProperty(PASSWORD_PROPERTY_KEY, password); StringWriter writer = new StringWriter(); properties.store(writer, "Account info"); // login // concats URL with query string String completeUrl = url + HttpUtil.LOGIN_QUERY_STRING; StringEntity entity = new StringEntity(writer.toString(), ContentType.create("text/plain", "UTF-8")); // prepares POST request and basic response handler HttpPost httppost = new HttpPost(completeUrl); httppost.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); // executes and no parsing // result must be only a string httpclient.execute(httppost, responseHandler); }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setDebugging(boolean debugging) { if (sDebugging) writeLog("debugging stopped"); sDebugging = debugging;/* ww w. j a v a 2 s . co m*/ if (sDebugging) writeLog("debugging started"); Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setPassphrase(String passphrase) { Properties prop = new Properties(); try {// w ww. j a v a 2 s .c om prop.load(new FileInputStream(sProperties)); prop.setProperty(sPassphraseKey, passphrase); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (OS == OS_WIN) { KeyStore ks = getKeyStore(); if (ks != null) { SecretKey sk = getSecretKey(ks); if (ks != null) { try { ks.setKeyEntry(TAP_LOCK, sk, sPassphrase.toCharArray(), null); ks.store(new FileOutputStream(sKeystore), sPassphrase.toCharArray()); } catch (KeyStoreException e) { writeLog("change key password: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { writeLog("change key password: " + e.getMessage()); } catch (CertificateException e) { writeLog("change key password: " + e.getMessage()); } catch (FileNotFoundException e) { writeLog("change key password: " + e.getMessage()); } catch (IOException e) { writeLog("change key password: " + e.getMessage()); } } } } sPassphrase = passphrase; }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setTrayIconDisplay(boolean display) { sDisplaySystemTray = display;//from w ww .j ava2s .c o m Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }
From source file:com.pieframework.runtime.core.Installer.java
public static void createConfigFile(Properties prop) { try {//from w ww.j a v a 2s. c o m File pieConfig = new File(prop.getProperty("pie.config")); //Backup the config file if it exists if (pieConfig.exists()) { File backup = new File(pieConfig.getPath() + "." + TimeUtils.getCurrentTimeStamp()); FileUtils.copyFile(pieConfig, backup); } //Create/Overwrite the config file OutputStream out = new FileOutputStream(pieConfig); prop.store(out, getComments()); System.out.println("Created config file: " + pieConfig.getPath()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.wavemaker.common.util.SystemUtils.java
public static void writePropertiesFile(OutputStream os, Properties props, List<String> includePropertyNames, String comment) {/* w w w. ja v a 2 s. c o m*/ try { if (includePropertyNames != null) { Properties p = new Properties(); for (String key : CastUtils.<String>cast(props.keySet())) { if (includePropertyNames.contains(key)) { p.setProperty(key, props.getProperty(key)); } } props = p; } props.store(os, comment); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:io.amient.yarn1.YarnClient.java
/** * Distribute all dependencies in a single jar both from Client to Master as well as Master to Container(s) *//*w w w. ja va 2s . com*/ public static void distributeResources(Configuration yarnConf, Properties appConf, String appName) throws IOException { final FileSystem distFs = FileSystem.get(yarnConf); final FileSystem localFs = FileSystem.getLocal(yarnConf); try { //distribute configuration final Path dstConfig = new Path(distFs.getHomeDirectory(), appName + ".configuration"); final FSDataOutputStream fs = distFs.create(dstConfig); appConf.store(fs, "Yarn1 Application Config for " + appName); fs.close(); log.info("Updated resource " + dstConfig); //distribute main jar final String localPath = YarnClient.class.getProtectionDomain().getCodeSource().getLocation().getFile() .replace(".jar/", ".jar"); final Path src; final String jarName = appName + ".jar"; if (localPath.endsWith(".jar")) { log.info("Distributing local jar : " + localPath); src = new Path(localPath); } else { try { String localArchive = localPath + appName + ".jar"; localFs.delete(new Path(localArchive), false); log.info("Unpacking compile scope dependencies: " + localPath); executeShell("mvn -f " + localPath + "/../.. generate-resources"); log.info("Preparing application main jar " + localArchive); executeShell("jar cMf " + localArchive + " -C " + localPath + " ./"); src = new Path(localArchive); } catch (InterruptedException e) { throw new IOException(e); } } byte[] digest; final MessageDigest md = MessageDigest.getInstance("MD5"); try (InputStream is = new FileInputStream(src.toString())) { DigestInputStream dis = new DigestInputStream(is, md); byte[] buffer = new byte[8192]; int numOfBytesRead; while ((numOfBytesRead = dis.read(buffer)) > 0) { md.update(buffer, 0, numOfBytesRead); } digest = md.digest(); } log.info("Local check sum: " + Hex.encodeHexString(digest)); final Path dst = new Path(distFs.getHomeDirectory(), jarName); Path remoteChecksumFile = new Path(distFs.getHomeDirectory(), jarName + ".md5"); boolean checksumMatches = false; if (distFs.isFile(remoteChecksumFile)) { try (InputStream r = distFs.open(remoteChecksumFile)) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[1024]; while ((nRead = r.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); byte[] remoteDigest = buffer.toByteArray(); log.info("Remote check sum: " + Hex.encodeHexString(remoteDigest)); checksumMatches = Arrays.equals(digest, remoteDigest); } } if (!checksumMatches) { log.info("Updating resource " + dst + " ..."); distFs.copyFromLocalFile(false, true, src, dst); try (FSDataOutputStream remoteChecksumStream = distFs.create(remoteChecksumFile)) { log.info("Updating checksum " + remoteChecksumFile + " ..."); remoteChecksumStream.write(digest); } FileStatus scFileStatus = distFs.getFileStatus(dst); log.info("Updated resource " + dst + " " + scFileStatus.getLen()); } } catch (NoSuchAlgorithmException e) { throw new IOException(e); } }
From source file:uk.ac.cam.cl.dtg.picky.client.analytics.Analytics.java
private static void upload(Properties properties, String datasetURL) { if (datasetURL == null) return;/* www . j ava 2 s.c om*/ URL url; try { url = new URL(new URL(datasetURL), URL); } catch (MalformedURLException e1) { e1.printStackTrace(); return; } try { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost post = new HttpPost(url.toURI()); post.setHeader("Content-Type", "text/plain; charset=utf-8"); StringWriter stringWriter = new StringWriter(); properties.store(stringWriter, ""); HttpEntity entity = new StringEntity(stringWriter.toString()); post.setEntity(entity); HttpResponse response = client.execute(post); LOG.info("Uploading analytics: " + response.getStatusLine()); } catch (IOException | URISyntaxException e) { LOG.error(e.getMessage()); } }
From source file:com.hmiard.blackwater.projects.Builder.java
/** * Building a new project./*w w w .j a v a 2 s .c o m*/ * * @param projectName String * @param serverNames ArrayList * @param location String */ public static void buildNewProject(String projectName, ArrayList<String> serverNames, String location, ConsoleEmulator consoleListener) { try { consoleListener.clean(); consoleListener.push("Project creation started...\n\n"); projectName = projectName.substring(0, 1).toUpperCase() + projectName.substring(1); String projectUrl = location + "\\" + projectName; buildFolder(projectUrl); buildFolder(projectUrl + "\\bin"); buildFolder(projectUrl + "\\src"); buildFolder(projectUrl + "\\.blackwater"); ArrayList<String> realServerNames = new ArrayList<>(); for (String name : serverNames) realServerNames.add(name.replace("!", "")); // Creating the configuration Properties configuration = new Properties(); File tokens = new File(projectUrl + "\\.blackwater\\tokens.properties"); configuration.setProperty("PATH", projectUrl); configuration.setProperty("NAME", projectName); configuration.setProperty("SERVERS", Parser.parseArrayToStringList(",", realServerNames)); configuration.setProperty("LAST_UPDATE", new Date().toString()); configuration.store(new FileOutputStream(tokens), "Blackwater build version : " + Start.VERSION); consoleListener.push("Tokens generated.\n"); // Creating composer.json... JSONObject composerJSON = new JSONObject(); JSONObject autoload = new JSONObject(); JSONObject psr0 = new JSONObject(); JSONObject require = new JSONObject(); autoload.put("psr-0", psr0); composerJSON.put("autoload", autoload); composerJSON.put("require", require); require.put("blackwater/blackwaterp", Start.blackwaterpVersion); File composer = new File(projectUrl + "\\composer.json"); if (!composer.createNewFile()) { consoleListener.push("\nWeird composer stuff happened... Aborting.\n"); return; } BufferedWriter cw = new BufferedWriter(new FileWriter(composer.getAbsoluteFile())); String content = composerJSON.toString(4).replaceAll("\\\\", ""); cw.write(content); cw.close(); consoleListener.push("File created : composer.json\n"); // Creating the servers... consoleListener.push("Server creation started...\n"); for (String name : serverNames) if (name.charAt(0) == '!') appendServer(projectUrl, name.replace("!", ""), consoleListener, false); else appendServer(projectUrl, name, consoleListener, true); // Copying composer.phar consoleListener.push("Installing local composer wrapper...\n"); copyFile(new File("resources/packages/composer.phar"), new File(composer.getParent() + "\\bin\\composer.phar")); // Building... consoleListener.push("Building dependencies...\n"); new Thread(new ChildProcess("php bin/composer.phar install", composer.getParentFile(), consoleListener, () -> { NewProjectAppScreenPresenter presenter = (NewProjectAppScreenPresenter) consoleListener.app; presenter.projectCreatedCallback(projectUrl, consoleListener); })).start(); } catch (JSONException | IOException e) { e.printStackTrace(); } }
From source file:com.fluidops.iwb.api.ProviderServiceImpl.java
private static void saveProvidersProp(Properties providersProp) { FileOutputStream propertyFileStream = null; try {// w ww . j av a2 s .c om propertyFileStream = new FileOutputStream(PROVIDERS_PROP_PATH); providersProp.store(propertyFileStream, null); } catch (FileNotFoundException e) { // It has to be there as part of the default config, we don't create it if it's not there logger.error("Providers properties file not found", e); } catch (IOException e) { logger.error("Could not save the providers properties file", e); } finally { IOUtils.closeQuietly(propertyFileStream); } }