Example usage for java.util Properties store

List of usage examples for java.util Properties store

Introduction

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

Prototype

public void store(OutputStream out, String comments) throws IOException 

Source Link

Document

Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the #load(InputStream) load(InputStream) method.

Usage

From source file:com.cerebro.provevaadin.smtp.ConfigurazioneSMTP.java

public ConfigurazioneSMTP() {

    this.setMargin(true);

    TextField smtpHost = new TextField("SMTP Host Server");
    smtpHost.setRequired(true);/*from  www. ja v  a2s .c  o m*/
    TextField smtpPort = new TextField("SMTP Port");
    smtpPort.setRequired(true);
    TextField smtpUser = new TextField("SMTP Username");
    smtpUser.setRequired(true);
    TextField smtpPwd = new TextField("SMTP Password");
    smtpPwd.setRequired(true);
    TextField pwdConf = new TextField("Conferma la Password");
    pwdConf.setRequired(true);
    CheckBox security = new CheckBox("Sicurezza del server");

    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        System.out.println("Carico file di configurazione");
        try {
            props.load(config);
        } catch (IOException ex) {
            Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    smtpHost.setValue(props.getProperty("smtp_host"));
    smtpUser.setValue(props.getProperty("smtp_user"));
    security.setValue(Boolean.parseBoolean(props.getProperty("smtp_sec")));

    Button salva = new Button("Salva i parametri");
    salva.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Salvo i parametri SMTP");
        if (smtpHost.isValid() && smtpPort.isValid() && smtpUser.isValid() && smtpPwd.isValid()
                && smtpPwd.getValue().equals(pwdConf.getValue())) {
            props.setProperty("smtp_host", smtpHost.getValue());
            props.setProperty("smtp_port", smtpPort.getValue());
            props.setProperty("smtp_user", smtpUser.getValue());
            props.setProperty("smtp_pwd", smtpPwd.getValue());
            props.setProperty("smtp_sec", security.getValue().toString());
            String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext()
                    .getRealPath("WEB-INF");
            File f = new File(webInfPath + "/config.properties");
            try {
                OutputStream o = new FileOutputStream(f);
                try {
                    props.store(o, "Prova");
                } catch (IOException ex) {
                    Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }
            Notification.show("Parametri salvati");
        } else {
            Notification.show("Ricontrolla i parametri");
        }

    });

    TextField emailTest = new TextField("Destinatario Mail di Prova");
    emailTest.setImmediate(true);
    emailTest.addValidator(new EmailValidator("Mail non valida"));

    Button test = new Button("Invia una mail di prova");
    test.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Invio della mail di prova");
        if (emailTest.isValid()) {
            try {
                System.out.println("Invio mail di prova a " + emailTest.getValue());
                HtmlEmail email = new HtmlEmail();
                email.setHostName(props.getProperty("smtp_host"));
                email.setSmtpPort(Integer.parseInt(props.getProperty("smtp_port")));
                email.setSSLOnConnect(Boolean.parseBoolean(props.getProperty("smtp_sec")));
                email.setAuthentication(props.getProperty("smtp_user"), props.getProperty("smtp_pwd"));
                email.setFrom("prova@prova.it");
                email.setSubject("Mail di prova");
                email.addTo(emailTest.getValue());
                email.setHtmlMsg("This is the message");
                email.send();
            } catch (EmailException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            Notification.show("Controlla l'indirizzo mail del destinatario");
        }
    });

    this.addComponents(smtpHost, smtpPort, smtpUser, smtpPwd, pwdConf, security, salva, emailTest, test);

}

From source file:com.streamsets.datacollector.bundles.SupportBundleManager.java

private void generateNewBundleInternal(List<BundleContentGenerator> generators, BundleType bundleType,
        ZipOutputStream zipStream) {
    try {/*from w ww  .  j  a  va2  s .c om*/
        Properties runGenerators = new Properties();
        Properties failedGenerators = new Properties();

        // Let each individual content generator run to generate it's content
        for (BundleContentGenerator generator : generators) {
            BundleContentGeneratorDefinition definition = definitionMap
                    .get(generator.getClass().getSimpleName());
            BundleWriterImpl writer = new BundleWriterImpl(definition.getKlass().getName(), redactor,
                    zipStream);

            try {
                LOG.debug("Generating content with {} generator", definition.getKlass().getName());
                generator.generateContent(this, writer);
                runGenerators.put(definition.getKlass().getName(), String.valueOf(definition.getVersion()));
            } catch (Throwable t) {
                LOG.error("Generator {} failed", definition.getName(), t);
                failedGenerators.put(definition.getKlass().getName(), String.valueOf(definition.getVersion()));
                writer.ensureEndOfFile();
            }
        }

        // generators.properties
        zipStream.putNextEntry(new ZipEntry("generators.properties"));
        runGenerators.store(zipStream, "");
        zipStream.closeEntry();

        // failed_generators.properties
        zipStream.putNextEntry(new ZipEntry("failed_generators.properties"));
        failedGenerators.store(zipStream, "");
        zipStream.closeEntry();

        if (!bundleType.isAnonymizeMetadata()) {
            // metadata.properties
            zipStream.putNextEntry(new ZipEntry("metadata.properties"));
            getMetadata(bundleType).store(zipStream, "");
            zipStream.closeEntry();
        }

    } catch (Exception e) {
        LOG.error("Failed to generate resource bundle", e);
    } finally {
        // And that's it
        try {
            zipStream.close();
        } catch (IOException e) {
            LOG.error("Failed to finish generating the bundle", e);
        }
    }
}

From source file:net.sf.nmedit.nordmodular.Installer.java

private void saveCurrentSession() {
    DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager();

    List<NMPatch> patches = new ArrayList<NMPatch>();

    for (Document doc : dm.getDocuments()) {
        if (doc instanceof PatchDocument) {
            patches.add(((PatchDocument) doc).getPatch());
        }/*ww  w  .  jav a 2s . c o  m*/
    }

    TempDir tmpDir = TempDir.forObject(this);

    Properties props = new Properties();
    int pcount = 0;

    for (NMPatch patch : patches) {
        File saveAs = getPatchTmpFile(tmpDir, pcount);

        try {
            OutputStream out = new BufferedOutputStream(new FileOutputStream(saveAs));

            PatchFileWriter pfw = new PatchFileWriter(out);
            PatchExporter export = new PatchExporter();
            export.export(patch, pfw);

            out.flush();
            out.close();
        } catch (Exception e) {
            Log log = LogFactory.getLog(getClass());
            if (log.isDebugEnabled()) {
                log.debug("exception while storing session file", e);
            }

            e.printStackTrace();
            continue;
        }

        // tmp file written
        File sourceFile = patch.getFile();
        if (sourceFile != null)
            props.put(getSourceFileKey(pcount), sourceFile.getAbsolutePath());
        else {
            // source file unknown, since patch file contains no title we have to remember it
            String name = patch.getName();
            if (name != null)
                props.put(getTitleKey(pcount), name);
        }
        pcount++;
    }

    props.put(SESSION_PATCHCOUNT, String.valueOf(pcount));

    File sessionFile = getSessionFile(tmpDir);

    try {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(sessionFile));
        props.store(out, "generated file - do not edit manually");
        out.close();
    } catch (Exception e) {
        Log log = LogFactory.getLog(getClass());
        if (log.isDebugEnabled()) {
            log.debug("exception while storing session file", e);
        }

        e.printStackTrace();
        // ignore   
    }

}

From source file:de.ingrid.admin.Config.java

public void writeCommunicationToProperties() {
    Resource override = getOverrideConfigResource();
    try (InputStream is = new FileInputStream(override.getFile().getAbsolutePath())) {

        Properties props = new Properties() {
            private static final long serialVersionUID = 6956076060462348684L;

            @Override/*w  ww.j a  v a 2  s . c  om*/
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<Object>(super.keySet()));
            }
        };
        props.load(is);
        // ---------------------------
        props.setProperty("communication.clientName", communicationProxyUrl);

        String communications = "";
        for (int i = 0; i < ibusses.size(); i++) {
            CommunicationCommandObject ibus = ibusses.get(i);
            communications += ibus.getBusProxyServiceUrl() + "," + ibus.getIp() + "," + ibus.getPort();
            if (i != (ibusses.size() - 1))
                communications += "##";
        }
        props.setProperty("communications.ibus", communications);

        // ---------------------------
        try (OutputStream os = new FileOutputStream(override.getFile().getAbsolutePath())) {
            props.store(os, "Override configuration written by the application");
        }
    } catch (Exception e) {
        log.error("Error writing properties: ", e);
    }
}

From source file:com.pearson.dashboard.util.Util.java

public void configureTestSet() {
    try {/*from w  w  w .  jav  a2 s  . c  o m*/
        Properties props = new Properties();
        props.setProperty("ServerAddress", "");
        props.setProperty("ServerPort", "" + "");
        props.setProperty("ThreadCount", "" + "");
        File f = new File("server.properties");
        OutputStream out = new FileOutputStream(f);
        props.store(out, "This is an optional header comment string");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.shootoff.config.Configuration.java

public void writeConfigurationFile() throws ConfigurationException, IOException {
    validateConfiguration();/*from  ww  w . ja  va2  s.c o m*/

    Properties prop = new Properties();

    StringBuilder webcamList = new StringBuilder();
    for (String webcamName : webcams.keySet()) {
        if (webcamList.length() > 0)
            webcamList.append(",");
        webcamList.append(webcamName);
        webcamList.append(":");
        webcamList.append(webcams.get(webcamName).getName());
    }

    prop.setProperty(WEBCAMS_PROP, webcamList.toString());
    prop.setProperty(DETECTION_RATE_PROP, String.valueOf(detectionRate));
    prop.setProperty(LASER_INTENSITY_PROP, String.valueOf(laserIntensity));
    prop.setProperty(MARKER_RADIUS_PROP, String.valueOf(markerRadius));
    prop.setProperty(IGNORE_LASER_COLOR_PROP, ignoreLaserColorName);
    prop.setProperty(USE_RED_LASER_SOUND_PROP, String.valueOf(useRedLaserSound));
    prop.setProperty(RED_LASER_SOUND_PROP, redLaserSound.getPath());
    prop.setProperty(USE_GREEN_LASER_SOUND_PROP, String.valueOf(useGreenLaserSound));
    prop.setProperty(GREEN_LASER_SOUND_PROP, greenLaserSound.getPath());
    prop.setProperty(USE_VIRTUAL_MAGAZINE_PROP, String.valueOf(useVirtualMagazine));
    prop.setProperty(VIRTUAL_MAGAZINE_CAPACITY_PROP, String.valueOf(virtualMagazineCapacity));
    prop.setProperty(USE_MALFUNCTIONS_PROP, String.valueOf(useMalfunctions));
    prop.setProperty(MALFUNCTIONS_PROBABILITY_PROP, String.valueOf(malfunctionsProbability));

    OutputStream outputStream = new FileOutputStream(configName);
    prop.store(outputStream, "ShootOFF Configuration");
}

From source file:com.cerebro.provevaadin.smtp.ConfigurazioneSMTPSpring.java

public ConfigurazioneSMTPSpring() {

    TextField smtpHost = new TextField("SMTP Host Server");
    smtpHost.setRequired(true);//from   www  . j  ava2 s. co  m
    TextField smtpPort = new TextField("SMTP Port");
    smtpPort.setRequired(true);
    TextField smtpUser = new TextField("SMTP Username");
    smtpUser.setRequired(true);
    PasswordField smtpPwd = new PasswordField("SMTP Password");
    smtpPwd.setRequired(true);
    PasswordField pwdConf = new PasswordField("Conferma la Password");
    pwdConf.setRequired(true);
    CheckBox security = new CheckBox("Sicurezza del server");

    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        System.out.println("Carico file di configurazione");
        try {
            props.load(config);
        } catch (IOException ex) {
            Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    smtpHost.setValue(props.getProperty("mail.smtp.host"));
    smtpUser.setValue(props.getProperty("smtp_user"));
    security.setValue(Boolean.parseBoolean(props.getProperty("smtp_sec")));

    Button salva = new Button("Salva i parametri");
    salva.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Salvo i parametri SMTP");
        if (smtpHost.isValid() && smtpPort.isValid() && smtpUser.isValid() && smtpPwd.isValid()
                && smtpPwd.getValue().equals(pwdConf.getValue())) {
            System.out.println(smtpHost.getValue() + smtpPort.getValue() + smtpUser.getValue()
                    + smtpPwd.getValue() + security.getValue().toString());
            props.setProperty("mail.smtp.host", smtpHost.getValue());
            props.setProperty("mail.smtp.port", smtpPort.getValue());
            props.setProperty("smtp_user", smtpUser.getValue());
            props.setProperty("smtp_pwd", smtpPwd.getValue());
            props.setProperty("mail.smtp.ssl.enable", security.getValue().toString());
            String webInfPath = VaadinServlet.getCurrent().getServletConfig().getServletContext()
                    .getRealPath("WEB-INF");
            File f = new File(webInfPath + "/config.properties");
            try {
                OutputStream o = new FileOutputStream(f);
                try {
                    props.store(o, "Prova");
                } catch (IOException ex) {
                    Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ConfigurazioneSMTP.class.getName()).log(Level.SEVERE, null, ex);
            }
            Notification.show("Parametri salvati");
        } else {
            Notification.show("Ricontrolla i parametri");
        }

    });

    TextField emailTest = new TextField("Destinatario Mail di Prova");
    emailTest.setImmediate(true);
    emailTest.addValidator(new EmailValidator("Mail non valida"));

    Button test = new Button("Invia una mail di prova");
    test.addClickListener((Button.ClickEvent event) -> {
        System.out.println("Invio della mail di prova");
        if (emailTest.isValid() && !emailTest.isEmpty()) {
            System.out.println("Invio mail di prova a " + emailTest.getValue());
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
            mailSender.setJavaMailProperties(props);
            mailSender.setUsername(props.getProperty("smtp_user"));
            mailSender.setPassword(props.getProperty("smtp_pwd"));
            MimeMessage message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message);
            try {
                helper.setFrom("dottmatteocasagrande@gmail.com");
                helper.setSubject("Subject");
                helper.setText("It works!");
                helper.addTo(emailTest.getValue());
                mailSender.send(message);
            } catch (MessagingException ex) {
                Logger.getLogger(ConfigurazioneSMTPSpring.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else {
            Notification.show("Controlla l'indirizzo mail del destinatario");
        }
    });

    this.addComponents(smtpHost, smtpPort, smtpUser, smtpPwd, pwdConf, security, salva, emailTest, test);

}

From source file:twitterGateway_v2_06.java

public void SaveProperties() {
    try {//from  w  ww.  j a  va2s .  com
        Properties props = new Properties();
        props.setProperty("osc.receiving.port", "" + OscRecvPort);

        props.setProperty("osc.destination.host", "" + OscDestHost);
        props.setProperty("osc.destination.port", "" + OscDestPort);

        props.setProperty("osc.address.recv", OscRecvAddress);
        props.setProperty("osc.address.send", OscSendAddress);

        //props.setProperty("twitter.username", TwitterUsername);
        //props.setProperty("twitter.password", TwitterPassword);
        props.setProperty("twitter.ConsumerKey", TwitterConsumerKey);
        props.setProperty("twitter.ConsumerSecret", TwitterConsumerSecret);
        props.setProperty("twitter.AccessToken", TwitterAccessToken);
        props.setProperty("twitter.AccessTokenSecret", TwitterAccessTokenSecret);

        String TwitterFollowIDsString = "";

        if (TwitterFollowIDs.length > 0) {
            for (int i = 0; i < TwitterFollowIDs.length; i++) {
                TwitterFollowIDsString += String.valueOf(TwitterFollowIDs[i]) + " ";
            }
        }

        props.setProperty("twitter.followIDs", TwitterFollowIDsString);

        String TwitterTrackwordsString = "";
        for (int i = 0; i < TwitterTrackWords.length; i++) {
            TwitterTrackwordsString += TwitterTrackWords[i] + " ";
        }
        props.setProperty("twitter.trackwords", TwitterTrackwordsString);

        //File f = new File("config.properties");
        //OutputStream out = new FileOutputStream( f );
        props.store(createOutput("gateway.properties"), " TWITTER gateway configuration");
        println("NEW propeties written");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.unc.lib.dl.util.IngestProperties.java

public void save() {
    if (log.isDebugEnabled()) {
        log.debug("saving ingest properties to " + this.propFile.getAbsolutePath());
    }/*  w  ww  .jav a 2s . c o  m*/
    Properties props = new Properties();
    if (this.submitter != null)
        props.put("submitter", this.submitter);
    if (this.submitterGroups != null) {
        props.put("submitterGroups", this.submitterGroups);
    }
    if (this.emailRecipients != null && this.emailRecipients.length > 0) {
        StringBuilder sb = new StringBuilder();
        sb.append(this.emailRecipients[0]);
        for (int i = 1; i < this.emailRecipients.length; i++) {
            sb.append(",").append(this.emailRecipients[i]);
        }
        props.put("email.recipients", sb.toString());
    }
    if (this.message != null)
        props.put("message", this.message);
    if (this.originalDepositId != null)
        props.put("originalDepositId", this.originalDepositId);
    if (this.managedBytes != -1) {
        props.put("managedBytes", String.valueOf(this.managedBytes));
    }
    if (this.submissionTime != -1) {
        props.put("submissionTime", String.valueOf(this.submissionTime));
    }
    if (this.finishedTime != -1) {
        props.put("finishedTime", String.valueOf(this.finishedTime));
    }
    if (this.startTime != -1) {
        props.put("startTime", String.valueOf(this.startTime));
    }
    if (this.containerPlacements != null && this.containerPlacements.size() > 0) {
        int count = 0;
        for (ContainerPlacement p : this.containerPlacements.values()) {
            StringBuilder sb = new StringBuilder();
            sb.append(p.pid).append(',').append(p.parentPID).append(',').append(p.designatedOrder).append(',')
                    .append(p.sipOrder).append(",").append(p.label);
            props.put("placement." + count, sb.toString());
            count++;
        }
    }
    FileOutputStream f = null;
    try {
        f = new FileOutputStream(this.propFile);
        props.store(f, "This file provides properties to the batch ingest service.");
    } catch (IOException e) {
        throw new Error("Unexpected", e);
    } finally {
        if (f != null) {
            try {
                f.flush();
                f.close();
            } catch (IOException ignored) {
            }
        }
    }
}