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:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java

private void saveBackupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBackupButtonActionPerformed
    DatabaseInfo info = (DatabaseInfo) competitionList.getSelectedValue();
    if (info == null || !info.local)
        return;/*from   w  w  w .  j av a2 s.c o  m*/
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileNameExtensionFilter("Event Manager Files", "evm"));
    if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (!file.getName().toLowerCase().endsWith(".evm"))
            file = new File(file.getAbsolutePath() + ".evm");
        if (file.exists()) {
            int result = JOptionPane.showConfirmDialog(rootPane,
                    file.getName() + " already exists. Overwrite file?", "Save Backup",
                    JOptionPane.YES_NO_OPTION);
            if (result != JOptionPane.YES_OPTION)
                return;
        }
        try {
            File tempDir = Files.createTempDirectory("event-manager").toFile();
            FileUtils.copyDirectory(info.localDirectory, tempDir);

            File lockFile = new File(tempDir, "update.dat.lock");
            lockFile.delete();

            /* change id */
            Properties props = new Properties();
            FileReader fr = new FileReader(new File(tempDir, "info.dat"));
            props.load(fr);
            fr.close();
            props.setProperty("old-UUID", props.getProperty("UUID", "none"));
            props.setProperty("UUID", UUID.randomUUID().toString());
            FileWriter fw = new FileWriter(new File(tempDir, "info.dat"));
            props.store(fw, "");
            fw.close();

            ZipUtils.zipFolder(tempDir, file, false);
        } catch (Exception e) {
            GUIUtils.displayError(this, "Failed to save file: " + e.getMessage());
        }
    }
}

From source file:com.htmlhifive.tools.jslint.configure.JSLintConfig.java

/**
 * ??.jslint???./*from   w w w  . j a va 2s .co  m*/
 */
void store() {

    Properties properties = new Properties();
    properties.setProperty(KEY_JSLINT_PATH, configBean.getJsLintPath());
    properties.setProperty(KEY_OPTION_PATH, configBean.getOptionFilePath());
    properties.setProperty(KEY_USE_OTHER_PROJECT, Boolean.toString(configBean.isUseOtherProject()));
    properties.setProperty(KEY_OTHER_PROJECT_PATH, configBean.getOtherProjectPath());
    properties.setProperty(KEY_INTERNAL_LIBRARY_LIST, StringUtils.join(configBean.getInternalLibPaths(), ','));
    properties.setProperty(KEY_EXTERNAL_LIBRARY_LIST, StringUtils.join(configBean.getExternalLibPaths(), ','));
    // properties.setProperty(KEY_LIBRARY_LIST,
    // StringUtils.join(configBean.getLibList(), ","));
    // properties.setProperty(KEY_USE_FILTER,
    // Boolean.toString(configBean.isUseFilter()));
    FilterBean[] beans = configBean.getFilterBeans();
    for (int i = 0; i < beans.length; i++) {
        properties.setProperty(KEY_FILTER_REGEX + i, beans[i].toString());
    }
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    InputStream input = null;
    try {
        properties.store(output, "");
        output.flush();
        input = new ByteArrayInputStream(output.toByteArray());
        configProp.refreshLocal(IResource.DEPTH_ZERO, null);

        if (configProp.exists()) {
            configProp.setContents(input, false, false, null);
        } else {
            configProp.create(input, false, null);
        }
    } catch (CoreException e) {
        logger.put(Messages.EM0100, e);
    } catch (IOException e) {
        logger.put(Messages.EM0100, e);
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
    }
}

From source file:com.google.dart.tools.core.DartCore.java

/**
 * Sets the value of the string-valued user-defined property for the given key.
 * <p>//from www  .j a  va 2  s  .co m
 * User-defined properties are defined in the <code>editor.properties</code> file located in the
 * eclipse installation directory.
 * 
 * @see DartCore#getEclipseInstallationDirectory()
 * @param key the name of the property
 * @param value the string-valued property
 */
public static void setUserDefinedProperty(String key, String value) {

    Properties properties = new Properties();

    File installDirectory = getEclipseInstallationDirectory();
    File file = new File(installDirectory, EDITOR_PROPERTIES);

    try {
        if (!file.exists()) {
            file.createNewFile();
        }
        properties.load(new FileReader(file));
        properties.setProperty(key, value);
        properties.store(new FileWriter(file), null);
    } catch (FileNotFoundException e) {
        logError(e);
    } catch (IOException e) {
        logError(e);
    }

}

From source file:org.jahia.services.usermanager.ldap.LdapProviderConfiguration.java

@Override
public void edit(String providerKey, Map<String, Object> parameters, Map<String, Object> flashScope)
        throws Exception {
    String[] propKeys = (String[]) parameters.get("propKey");
    String[] propValues = (String[]) parameters.get("propValue");
    if (propKeys == null || propValues == null) {
        throw new Exception("No property has been set");
    }//from   w  w w.  ja va2  s . c  om
    Properties properties = new Properties();
    for (int i = 0; i < propKeys.length; i++) {
        String propValue = propValues[i];
        if (StringUtils.isNotBlank(propValue)) {
            properties.put(propKeys[i], propValue);
        }
    }
    flashScope.put("ldapProperties", properties);
    if (!testConnection(properties)) {
        throw new Exception("Connection to the LDAP server impossible");
    }
    String configName;
    if (providerKey.equals("ldap")) {
        configName = jahiaLDAPConfigFactory.getName() + "-config.cfg";
    } else if (providerKey.startsWith("ldap.")) {
        configName = jahiaLDAPConfigFactory.getName() + "-" + providerKey.substring("ldap.".length()) + ".cfg";
    } else {
        throw new Exception("Wrong LDAP provider key: " + providerKey);
    }
    File file = new File(SettingsBean.getInstance().getJahiaModulesDiskPath(), configName);
    if (file.exists()) {
        FileOutputStream out = new FileOutputStream(file);
        try {
            properties.store(out, "");
        } finally {
            IOUtils.closeQuietly(out);
        }
    } else {
        String pid = jahiaLDAPConfigFactory.getConfigPID(providerKey);
        if (pid == null) {
            throw new Exception("Cannot find LDAP provider " + providerKey);
        }
        Configuration configuration = configurationAdmin.getConfiguration(pid);
        properties.put(JahiaLDAPConfig.LDAP_PROVIDER_KEY_PROP, providerKey);
        configuration.update((Dictionary) properties);
    }
}

From source file:com.cloudera.knittingboar.conf.cmdline.ModelTrainerCmdLineDriver.java

private void BuildPropertiesFile() throws Exception {

    // Setup app.properties
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("app.properties");
    if (is == null)
        throw new RuntimeException("Could not find 'app.properties' template file in classpath");

    Properties props = new Properties();
    props.load(is);//from w  ww .jav  a2 s  .  c o  m
    props.put(ConfigFields.JAR_PATH, "/dev/null"); // what about these?
    props.put(ConfigFields.APP_JAR_PATH, "/dev/null"); // what about these?
    props.put(ConfigFields.APP_INPUT_PATH, ModelTrainerCmdLineDriver.input_dir);
    props.put(ConfigFields.APP_OUTPUT_PATH, ModelTrainerCmdLineDriver.output_dir);
    props.put(ConfigFields.YARN_MASTER, "com.cloudera.knittingboar.sgd.iterativereduce.POLRMasterNode");
    props.put(ConfigFields.YARN_WORKER, "com.cloudera.knittingboar.sgd.iterativereduce.POLRWorkerNode");

    props.put("com.cloudera.knittingboar.setup.FeatureVectorSize", 10000);

    props.put("com.cloudera.knittingboar.setup.numCategories", 20);

    props.put("com.cloudera.knittingboar.setup.BatchSize", 200);

    props.put("com.cloudera.knittingboar.setup.NumberPasses", 1);

    // local input split path
    // props.put( "com.cloudera.knittingboar.setup.LocalInputSplitPath",
    // "hdfs://127.0.0.1/input/0" );

    // setup 20newsgroups
    props.put("com.cloudera.knittingboar.setup.RecordFactoryClassname",
            "com.cloudera.knittingboar.records.TwentyNewsgroupsRecordFactory");

    props.store(new FileOutputStream("app.properties"), null);

}

From source file:UI.SecurityDashboard.java

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    //Saving location where to get CSV files from                                              
    selectDatabaseLocation = new JFileChooser();
    selectDatabaseLocation.setCurrentDirectory(new java.io.File("."));
    selectDatabaseLocation.setDialogTitle(databaseFileLocationDialogTitle);
    selectDatabaseLocation.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    selectDatabaseLocation.setAcceptAllFileFilterUsed(false);

    if (selectDatabaseLocation.showDialog(sourceFolder,
            databaseFileLocationDialogButton) == JFileChooser.APPROVE_OPTION) {
        System.out.println("getCurrentDirectory(): " + selectDatabaseLocation.getCurrentDirectory());
        System.out.println("getSelectedFile() : " + selectDatabaseLocation.getSelectedFile());
    } else {//from  w  ww  . ja v  a2s . c o m
        System.out.println("No Selection ");
    }
    //
    //        TreeModel model = new FileTreeModel((new File("/")));
    //        final JTree tree = new JTree(model);
    //        final JFrame treeFrame = new JFrame();
    //        JScrollPane scrollPane = new JScrollPane(tree);
    //        JPanel treePanel = new JPanel();
    //        treePanel.setLayout(new BorderLayout());
    //        treePanel.add(scrollPane, BorderLayout.CENTER);
    //
    //        treeFrame.setAlwaysOnTop(true);
    //        JButton selectButton = new JButton();
    //        selectButton.setText("Select");
    //        selectButton.addActionListener(new ActionListener() {
    //
    //            public void actionPerformed(ActionEvent e)
    //            {
    //                //Execute when button is pressed
    //                treeFrame.setVisible(false);
    //                TreePath s = tree.getSelectionPath();
    //                System.out.println(s.toString());
    //            }
    //        });
    //        treeFrame.add(selectButton, BorderLayout.SOUTH);
    //        treeFrame.add(treePanel);
    //        treeFrame.setVisible(true);
    //        treeFrame.setSize(400, 400);
    //

    System.out.println(selectDatabaseLocation.getCurrentDirectory().getPath());
    File currentFile = selectDatabaseLocation.getCurrentDirectory();

    Properties prop = new Properties();
    OutputStream output = null;

    try {

        output = new FileOutputStream("config.properties");

        // set the properties value
        prop.setProperty("location", currentFile.getAbsolutePath());

        // save properties to project root folder
        prop.store(output, null);

    } catch (IOException io) {
        io.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}

From source file:de.fhg.iais.asc.commons.AscConfiguration.java

/**
 * writing the current properties in memory back to disk
 * /*ww w.ja  va  2  s.  c o  m*/
 * @param globalpropertiesFilepath
 * @param providerspezificpropertiesFilepath
 */
public void writeOutPropertiesToFile(String globalpropertiesFilepath,
        String providerspezificpropertiesFilepath) {
    // global properties
    Properties globalProperties = new Properties();
    // provider properties
    Properties providerProperties = new Properties();

    for (Object keyobject : this.propertiesMap.keySet()) {
        String key = (String) keyobject;
        boolean dropped = false;
        for (String oneProp : FIXEDGLOBALPROPERTIES) {
            if (key.equals(oneProp)) {
                globalProperties.put(key, this.propertiesMap.get(key).toString());
                dropped = true;
                break;
            }
        }

        if (!dropped) {
            providerProperties.put(key, this.propertiesMap.get(key).toString());
        }
    }

    if (globalpropertiesFilepath != null) {
        File globalPropertiesFile = new File(globalpropertiesFilepath);
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(globalPropertiesFile);
            globalProperties.store(fileOutputStream, "Global ASC properties");
        } catch (IOException e) {
            throw new DbcException(e);
        } finally {
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new DbcException(e);
                }
            }
        }
    }

    if (providerspezificpropertiesFilepath != null) {
        File providerspezificPropertiesFile = new File(providerspezificpropertiesFilepath);
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(providerspezificPropertiesFile);
            providerProperties.store(fileOutputStream, "Provider specific ASC properties");
        } catch (IOException e) {
            throw new DbcException(e);
        } finally {
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new DbcException(e);
                }
            }
        }
    }
}

From source file:name.livitski.databag.cli.Launcher.java

protected void create() throws DBException {
    File medium = getMedium();// w ww .j a  v  a2 s  .c o  m
    File mpath = getMpath();
    String path = null == mpath ? Manager.DB_NAMES[0] : mpath.getPath();
    if (!medium.exists() && medium.mkdir())
        log().info("Created directory \"" + medium + "\" to store the new bag.");
    File location = new File(medium, path);
    initDb(location);
    db.create();
    File locFile = new File(medium, LOCATOR_PROPERTIES_FILE);
    if (!locFile.exists()) {
        Properties locator = new Properties();
        locator.setProperty(DEFAULT_LOCATOR_PROPERTY, '@' + path);
        OutputStream locStream = null;
        try {
            locStream = new FileOutputStream(locFile);
            locator.store(locStream, "data-bag storage locator");
        } catch (IOException e) {
            log().log(Level.WARNING, "Could not write the database locator to medium " + medium, e);
        } finally {
            if (null != locStream)
                try {
                    locStream.close();
                } catch (IOException thrown) {
                    log().log(Level.FINE, "Error closing " + locFile, thrown);
                }
        }
    }
}

From source file:com.streamsets.datacollector.cluster.BaseClusterProvider.java

private boolean copyDpmTokenIfEnabled(Properties props, File etcStagingDir, String include) throws IOException {
    Object isDPMEnabled = props.get(RemoteSSOService.DPM_ENABLED);
    if (isDPMEnabled != null) {
        if (Boolean.parseBoolean(((String) isDPMEnabled).trim())) {
            copyDpmTokenIfAbsolute(props, etcStagingDir);
            if (include != null) {
                try (OutputStream outputStream = new FileOutputStream(new File(etcStagingDir, include))) {
                    props.store(outputStream, null);
                }//ww  w .  j ava  2  s  . c o m
            }
            return true;
        }
    }
    return false;
}

From source file:com.orange.mmp.dao.flf.DeliveryTicketDaoFlfImpl.java

public DeliveryTicket createOrUdpdate(DeliveryTicket deliveryTicket) throws MMPDaoException {
    if (deliveryTicket == null) {
        throw new MMPDaoException("missing or bad data access object");
    }/*from   w w w  .  j  a  va 2 s.c  o m*/

    OutputStream outProps = null;

    try {
        this.lock.lock();
        File temp;
        if (deliveryTicket.getId() != null) {
            temp = new File(this.path, deliveryTicket.getId().concat(TMP_FILE_EXT));
            if (!temp.exists())
                throw new MMPDaoException("Invalid ticket id " + deliveryTicket.getId());
        } else {
            temp = File.createTempFile(String.valueOf(Math.round(Math.random() * 10000)), null,
                    new File(this.path));
        }
        deliveryTicket.setId(temp.getName().split("\\.")[0]);
        deliveryTicket.setCreationDate(temp.lastModified());
        Properties clientProps = new Properties();
        if (deliveryTicket.getMsisdn() != null) {
            clientProps.setProperty(ND_PARAMETER, deliveryTicket.getMsisdn());
        }
        if (deliveryTicket.getServiceId() != null) {
            clientProps.setProperty(SERVICE_PARAMETER, deliveryTicket.getServiceId());
        }
        if (deliveryTicket.getUaKey() != null) {
            clientProps.setProperty(UAKEY_PARAMETER, deliveryTicket.getUaKey());
        }
        if (deliveryTicket.getCallback() != null) {
            clientProps.setProperty(CALLBACK_PARAMETER, deliveryTicket.getCallback());
        }
        if (deliveryTicket.getServiceSpecific() != null) {
            Map<String, String> serviceSpecificMap = deliveryTicket.getServiceSpecific();
            for (String key : serviceSpecificMap.keySet()) {
                clientProps.setProperty(JAD_PREFIX_ENTRY.concat(key), serviceSpecificMap.get(key).toString());
            }
        }

        outProps = new FileOutputStream(temp);
        clientProps.store(outProps, null);
        outProps.close();

        FileUtils.touch(new File(this.path));

    } catch (IOException ioe) {
        throw new MMPDaoException("failed to add ticket : " + ioe.getMessage());
    } finally {
        try {
            if (outProps != null)
                outProps.close();
        } catch (IOException ioe) {
            //Nop
        }
        this.lock.unlock();
    }

    return deliveryTicket;
}