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.jdom.axis.and.allies.model.GameSerializer.java

public String serialize(Game game) {
    Properties properties = new Properties();
    // Required for backwards compatibility
    if (game.version == null) {
        game.version = DEFAULT_VERSION;//from   w w w .  ja v a 2s .c  o  m
    }

    log.info("Serializing game with version: " + game.version);
    properties.setProperty(VERSION, game.version);

    Set<String> territoryNames = game.territoryMap.keySet();
    properties.put(TERRITORY_NAMES, StringUtils.join(territoryNames, SEPARATOR));
    properties.put(ACTIVE_PLAYER_NAME, game.activePlayer.toString());

    for (String territoryName : territoryNames) {
        Territory territory = game.territoryMap.get(territoryName);
        properties.put(territoryName + IPC_VALUES, "" + territory.getIpcValue());
        properties.put(territoryName + DAMAGE, "" + territory.getDamage());
    }

    List<String> countryNames = game.turnOrder;
    properties.put(PLAYABLE_COUNTRY_NAMES, StringUtils.join(countryNames, ','));

    for (String countryName : countryNames) {
        PlayableCountry playableCountry = game.playableCountryMap.get(countryName);

        properties.put(countryName + IPCS, "" + playableCountry.getIpcs());
        properties.put(countryName + TERRITORIES,
                convertCollectionToString(playableCountry.getOwnedTerritories()));

        if (playableCountry.getCapitalTerritories() != null) {
            properties.put(countryName + CAPITALS_SUFFIX,
                    StringUtils.join(Arrays.asList(playableCountry.getCapitalTerritories()), ','));

        }

    }

    Set<String> purchasableNames = game.purchasableMap.keySet();
    properties.put(PURCHASABLE_NAMES, StringUtils.join(purchasableNames, SEPARATOR));
    for (String purchasableName : purchasableNames) {
        Purchasable purchasable = game.purchasableMap.get(purchasableName);

        properties.put(purchasableName + IPC_VALUES, "" + purchasable.getIpcValue());
    }

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        properties.store(os, null);
    } catch (IOException e) {
        // Should never happen
    } finally {
        IOUtils.closeQuietly(os);
    }
    return os.toString();
}

From source file:database.DataLoader.java

/**
 *    ?   /*  ww  w  .  ja v a2 s  .co  m*/
 */
public String moveData() throws SQLException, ClassNotFoundException, Exception {
    String res = "";
    Properties props = new Properties();
    File fl = new File("/usr/local/vuz/logs/prop");
    if (!fl.exists()) {
        fl.createNewFile();
    }
    InputStream inputStream = new FileInputStream(fl);
    props.load(inputStream);
    inputStream.close();
    FileOutputStream fos = new FileOutputStream(fl);
    if (props.get("ready") == null) {
        props.setProperty("ready", "1");
        props.setProperty("state", "moveUsers");
        props.store(fos, "no comment");
        //moveUsers();
        props.setProperty("state", "moveOrderTypes");
        props.store(fos, "no comment");
        //moveOrderTypes();
        props.setProperty("state", "moveDirections");
        props.store(fos, "no comment");
        //moveDirections();
        props.setProperty("state", "moveOrders");
        props.store(fos, "no comment");
        //moveOrders();
        props.setProperty("state", "moveAdminMessages");
        props.store(fos, "no comment");
        //moveAdminMessages();
        props.setProperty("state", "moveAuthorToDirections");
        props.store(fos, "no comment");
        //moveAuthorToDirections();
        props.setProperty("state", "moveAuthorSalary");
        props.store(fos, "no comment");
        //moveAuthorSalary();
        props.setProperty("state", "moveOrdersToDirections");
        props.store(fos, "no comment");
        //moveOrdersToDirections();
        props.setProperty("state", "moveAuthorReject");
        props.store(fos, "no comment");
        //moveAuthorReject();
        props.setProperty("state", "moveAuthorViews");
        props.store(fos, "no comment");
        //moveAuthorViews();
        props.setProperty("state", "moveAuthorMessages");
        props.store(fos, "no comment");
        //moveAuthorMessages();
        props.setProperty("state", "addPaymentsToOrders");
        props.store(fos, "no comment");
        //addPaymentsToOrders();
        props.setProperty("state", "moveOrderFiles");
        props.store(fos, "no comment");
        //moveOrderFiles();
        props.setProperty("state", "moveOrderReadyFiles");
        props.store(fos, "no comment");
        //moveOrderReadyFiles();
        props.setProperty("state", "moveAdminMessageFiles");
        props.store(fos, "no comment");
        //moveAdminMessageFiles();
        props.setProperty("state", "moveAuthorMessageFiles");
        props.store(fos, "no comment");
        //moveAuthorMessageFiles();
        addAuthorRights();
        //res=updatePass();

    } else {
        res = "? , ??: " + props.getProperty("state");
    }
    fos.close();
    return res;
}

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

private void rewriteProperties(File sdcPropertiesFile, Map<String, String> sourceConfigs,
        Map<String, String> sourceInfo, String clusterToken, Optional<String> mesosURL) throws IOException {
    InputStream sdcInStream = null;
    OutputStream sdcOutStream = null;
    Properties sdcProperties = new Properties();
    try {/*from   ww w. j av a2 s . com*/
        sdcInStream = new FileInputStream(sdcPropertiesFile);
        sdcProperties.load(sdcInStream);
        sdcProperties.remove(Configuration.CONFIG_INCLUDES);
        sdcProperties.setProperty(WebServerTask.HTTP_PORT_KEY, "0");
        sdcProperties.setProperty(WebServerTask.HTTPS_PORT_KEY, "-1");
        sdcProperties.setProperty(RuntimeModule.PIPELINE_EXECUTION_MODE_KEY, ExecutionMode.SLAVE.name());
        sdcProperties.setProperty(WebServerTask.REALM_FILE_PERMISSION_CHECK, "false");
        sdcProperties.remove(RuntimeModule.DATA_COLLECTOR_BASE_HTTP_URL);
        if (runtimeInfo != null) {
            String id = String.valueOf(runtimeInfo.getId());
            sdcProperties.setProperty(Constants.SDC_ID, id);
            sdcProperties.setProperty(Constants.PIPELINE_CLUSTER_TOKEN_KEY, clusterToken);
            sdcProperties.setProperty(Constants.CALLBACK_SERVER_URL_KEY, runtimeInfo.getClusterCallbackURL());
        }

        if (mesosURL.isPresent()) {
            sdcProperties.setProperty(Constants.MESOS_JAR_URL, mesosURL.get());
        }
        addClusterConfigs(sourceConfigs, sdcProperties);
        addClusterConfigs(sourceInfo, sdcProperties);

        sdcOutStream = new FileOutputStream(sdcPropertiesFile);
        sdcProperties.store(sdcOutStream, null);
        LOG.debug("sourceConfigs = {}", sourceConfigs);
        LOG.debug("sourceInfo = {}", sourceInfo);
        LOG.debug("sdcProperties = {}", sdcProperties);
        sdcOutStream.flush();
        sdcOutStream.close();
    } finally {
        if (sdcInStream != null) {
            IOUtils.closeQuietly(sdcInStream);
        }
        if (sdcOutStream != null) {
            IOUtils.closeQuietly(sdcOutStream);
        }
    }
}

From source file:com.edgenius.wiki.installation.UpgradeServiceImpl.java

/**
 * Upgrade from version 1.0 to 1.01/*from   w ww  .jav a2s .  c om*/
 * @throws Exception 
 */
@SuppressWarnings("unused")
private void up1000To1010() throws Exception {
    log.info("Version 1.0 to 1.01 is upgarding");

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // dateabase
    String root = DataRoot.getDataRoot();
    if (FileUtil.exist(root + Server.FILE)) {
        Server server = new Server();
        Properties prop = FileUtil.loadProperties(root + Server.FILE);
        server.syncFrom(prop);
        String type = server.getDbType();
        String migrateSQL = type + "-1000-1010.sql";
        DBLoader loader = new DBLoader();
        ConnectionProxy con = loader.getConnection(type, server.getDbUrl(), server.getDbSchema(),
                server.getDbUsername(), server.getDbPassword());
        loader.runSQLFile(type, migrateSQL, con);
        con.close();
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Global.xml : add new DefaultNotifyMail
    String gfile = DataRoot.getDataRoot() + Global.FILE;
    GlobalSetting gs = GlobalSetting.loadGlobalSetting(FileUtil.getFileInputStream(gfile));
    gs.setDefaultNotifyMail(
            Global.DefaultNotifyMail == null ? "notify@geniuswiki.com" : Global.DefaultNotifyMail);
    gs.saveTo(gfile);
    Global.syncTo(gs);

    Server server = new Server();
    Properties prop = FileUtil.loadProperties(root + Server.FILE);
    server.syncFrom(prop);
    server.setDbJNDI("");
    server.setMqServerEmbedded("true");
    //save
    server.syncTo(prop);
    prop.store(FileUtil.getFileOutputStream(root + Server.FILE), "save by server");

}

From source file:dk.dma.aisvirtualnet.Settings.java

public void save() {
    int count;//from  w  w  w.jav a 2  s  . c om
    Properties saveProps = new Properties();
    Map<String, AisSerialReader> serialSources = new HashMap<String, AisSerialReader>();
    Map<String, AisTcpReader> tcpSources = new HashMap<String, AisTcpReader>();
    Map<String, Transponder> transponders = new HashMap<String, Transponder>();

    count = 0;
    for (Transponder transponder : AisVirtualNet.getTransponders()) {
        transponders.put("TRANS" + (count++), transponder);
    }

    count = 0;
    for (AisReader aisReader : AisVirtualNet.getSourceReader().getReaders()) {
        String name = "SOURCE" + (count++);
        if (aisReader instanceof AisTcpReader) {
            tcpSources.put(name, (AisTcpReader) aisReader);
        } else {
            serialSources.put(name, (AisSerialReader) aisReader);
        }
    }

    saveProps.put("serial_sources", StringUtils.join(serialSources.keySet(), ","));
    for (String name : serialSources.keySet()) {
        AisSerialReader aisSerialReader = serialSources.get(name);
        saveProps.put("serial_port." + name, aisSerialReader.getPortName());
    }

    saveProps.put("tcp_sources", StringUtils.join(tcpSources.keySet(), ","));
    for (String name : tcpSources.keySet()) {
        AisTcpReader aisTcpReader = tcpSources.get(name);
        saveProps.put("tcp_source_host." + name, aisTcpReader.getHostname());
        saveProps.put("tcp_source_port." + name, Integer.toString(aisTcpReader.getPort()));
    }

    saveProps.put("transponders", StringUtils.join(transponders.keySet(), ","));
    for (String name : transponders.keySet()) {
        Transponder transponder = transponders.get(name);
        saveProps.put("transponder_mmsi." + name, Long.toString(transponder.getMmsi()));
        saveProps.put("transponder_tcp_port." + name, Integer.toString(transponder.getTcpPort()));
        saveProps.put("transponder_own_message_force." + name,
                Integer.toString(transponder.getForceOwnInterval()));
    }

    try {
        FileWriter outFile = new FileWriter(filename);
        saveProps.store(outFile, "AisVirtualNet settings");
        outFile.close();
    } catch (IOException e) {
        LOG.error("Failed to save settings: " + e.getMessage());
    }
}

From source file:com.yourmediashelf.fedora.cargo.FedoraHome.java

private void configureSpringProperties() throws InstallationFailedException {
    Properties springProps = new Properties();

    /* Set up ssl configuration */
    springProps.put("fedora.port", _opts.getValue(InstallOptions.TOMCAT_HTTP_PORT, "8080"));
    if (_opts.getBooleanValue(InstallOptions.SSL_AVAILABLE, false)) {
        springProps.put("fedora.port.secure", _opts.getValue(InstallOptions.TOMCAT_SSL_PORT, "8443"));
    } else {/*from w w w .ja va 2 s . co  m*/
        springProps.put("fedora.port.secure", _opts.getValue(InstallOptions.TOMCAT_HTTP_PORT, "8080"));
    }

    springProps.put("security.ssl.api.access",
            _opts.getBooleanValue(InstallOptions.APIA_SSL_REQUIRED, false) ? "REQUIRES_SECURE_CHANNEL"
                    : "ANY_CHANNEL");
    springProps.put("security.ssl.api.management",
            _opts.getBooleanValue(InstallOptions.APIM_SSL_REQUIRED, false) ? "REQUIRES_SECURE_CHANNEL"
                    : "ANY_CHANNEL");
    springProps.put("security.ssl.api.default", "ANY_CHANNEL");

    springProps.put("security.fesl.authN.jaas.apia.enabled",
            _opts.getValue(InstallOptions.APIA_AUTH_REQUIRED, "false"));

    springProps.put("security.fesl.authZ.enabled", _opts.getValue(InstallOptions.FESL_AUTHZ_ENABLED, "false"));

    /* Set up authN, authZ filter configuration */
    StringBuilder filters = new StringBuilder();
    if (_opts.getBooleanValue(InstallOptions.FESL_AUTHN_ENABLED, true)) {
        filters.append("AuthFilterJAAS");
    } else {
        filters.append("SetupFilter,XmlUserfileFilter,EnforceAuthnFilter,FinalizeFilter");
    }

    if (_opts.getBooleanValue(InstallOptions.FESL_AUTHZ_ENABLED, false)) {
        filters.append(",PEPFilter");
    }

    springProps.put("security.auth.filters", filters.toString());

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(_installDir, "server/config/spring/web/web.properties"));
        springProps.store(out, "Spring override properties");
    } catch (IOException e) {
        throw new InstallationFailedException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:de.innovationgate.wga.model.WGADesignConfigurationModel.java

public void exportDesign(File file, Properties buildProperties)
        throws FileNotFoundException, PersistentKeyException, GeneralSecurityException, IOException {
    ZipOutputStream stream = createZIP(file, false, null);
    ZipEntry buildPropertiesEntry = new ZipEntry("files/system/build.properties");
    stream.putNextEntry(buildPropertiesEntry);
    ByteArrayOutputStream propertiesContent = new ByteArrayOutputStream();
    buildProperties.store(propertiesContent, null);
    stream.write(propertiesContent.toByteArray());
    stream.close();/*from   w ww.ja va 2  s . c  om*/
}

From source file:com.athena.meerkat.controller.web.provisioning.TomcatProvisioningControllerTest.java

@Test
public void testInstall() {

    File workingDir = new File(commanderDir);
    String serverIp = "192.168.0.157";
    MDC.put("serverIp", serverIp);
    String userId = "centos";

    Properties prop = new Properties(); //build-ssh.properties
    prop.setProperty("server.ip", serverIp);
    prop.setProperty("server.id", "6");
    prop.setProperty("server.port", "22");
    prop.setProperty("user.id", userId);
    prop.setProperty("user.passwd", userId);
    prop.setProperty("key.file", commanderDir + "/ssh/svn_key.pem");

    Properties targetProps = new Properties(); //build.properties
    targetProps.setProperty("agent.deploy.dir", "/home/" + userId + "/athena-meerkat-agent");
    targetProps.setProperty("agent.name", "athena-meerkat-agent-1.0.0-SNAPSHOT");
    targetProps.setProperty("tomcat.unzip.pah", "/home/" + userId + "/app");
    targetProps.setProperty("catalina.base", "/home/" + userId + "/app/instance1");

    OutputStream output = null;/*from  w  ww  . j a  v  a 2s  .com*/

    try {
        int jobNum = ProvisioningUtil.getJobNum(
                new File(workingDir.getAbsolutePath() + File.separator + "jobs" + File.separator + serverIp));
        targetProps.setProperty("job.number", String.valueOf(jobNum));

        /*
         * 1. make job dir & copy build.xml.
         */
        File jobDir = new File(workingDir.getAbsolutePath() + File.separator + "jobs" + File.separator
                + serverIp + File.separator + String.valueOf(jobNum));
        if (jobDir.exists() == false) {
            jobDir.mkdirs();
        }
        LOGGER.debug("JOB_DIR : " + jobDir.getAbsolutePath());

        FileUtils.copyFileToDirectory(new File(workingDir.getAbsolutePath() + File.separator + "build.xml"),
                jobDir);

        /*
         * 2. generate agentenv.sh
         */
        createAgentEnvSHFile(jobDir, targetProps.getProperty("agent.deploy.dir"),
                targetProps.getProperty("agent.name"));
        generateTomcatEnvFile(jobDir, createTomcatConfig(userId));

        /*
         * 3. generate build properties
         */
        output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build-ssh.properties");
        prop.store(output, "desc");
        LOGGER.debug("generated build-ssh.properties");

        IOUtils.closeQuietly(output);

        output = new FileOutputStream(jobDir.getAbsolutePath() + File.separator + "build.properties");
        targetProps.store(output, "desc");
        LOGGER.debug("generated build.properties");

        /*
         * 4. deploy agent
         */
        ProvisioningUtil.runDefaultTarget(workingDir, jobDir, "deploy-agent");

        /*
         * 5. send cmd.
         */
        ProvisioningUtil.sendCommand(workingDir, jobDir);

    } catch (Exception e) {
        //fail(e.toString());
        e.printStackTrace();
    } finally {
        MDC.remove("serverIp");
        IOUtils.closeQuietly(output);
    }

}

From source file:domain.Proceso.java

public void subirArchivo_2(String archivo) {

    Properties filesProperties = new Properties();
    Integer countfiles;//from w  w  w  .  ja  v  a 2s .c o m
    Integer cantidad_carpetas;
    FileInputStream file;
    // rutaOrigenArchivo = ruta;
    //nombreArchivo = archivo;

    cantidad_carpetas = Integer.parseInt(properties.getProperty("number_up"));

    for (int i = 0; i < cantidad_carpetas; i++) {

        try {
            ftp.uploadpath = properties.getProperty("uploadpath" + (i + 1));
            ftp.subirArchivo(archivo);

            File fichero = new File(files);

            if (fichero.delete()) {

                log.log("Archivo properties de " + ftp.uploadpath + " eliminado", false);
            } else {
                log.log("Error al Eliminar el archivo Files properties de carpeta a subir, en directorio local",
                        true);
            }

            //descargar Archivo properties de la carpeta
            ftp.downloadpath = ftp.uploadpath;
            ftp.descargarArchivo(files);
            file = new FileInputStream(files);
            filesProperties.load(file);
            file.close();
            //Obtener el valor countfiles
            countfiles = Integer.parseInt(filesProperties.getProperty("countfiles"));
            //Actualizar el valor countfiles en el archivo + 1
            countfiles += 1;
            filesProperties.replace("countfiles", countfiles + "");
            //Insertar valor de "file+[countfiles + 1] = export.nombreArchivo"
            filesProperties.setProperty("file" + countfiles, archivo);
            //Insertar valor de "fileStatus +[countfile  + 1]
            filesProperties.setProperty("fileStatus" + countfiles, "S");

            // filesProperties.store(file, "");
            FileOutputStream fos = new FileOutputStream(files);
            filesProperties.store(fos, null);

            ftp.subirArchivo(files);

            filesProperties.clear();
            fos.close();

        } catch (IOException ex) {

            log.log("Error: " + ex.getMessage(), true);
            Logger.getLogger(Proceso.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.flagleader.builder.BuilderConfig.java

public void save() {
    Properties localProperties = null;
    try {/*w  ww  .j  a v a 2 s . c  o  m*/
        localProperties = new Properties();
        if (this.c == null)
            this.c = new File(SystemUtils.USER_HOME + File.separator + ".visualrules", "builder.conf");
        if (!this.c.exists())
            this.c.createNewFile();
        localProperties.setProperty("autosave", new Boolean(this.h).toString());
        localProperties.setProperty("userName", this.k);
        localProperties.setProperty("licenseKey", this.l);
        localProperties.setProperty("demoKey", this.j);
        localProperties.setProperty("autosaveTime", new Long(this.i).toString());
        localProperties.setProperty("tomcatLogFile", this.n);
        localProperties.setProperty("projPath", this.q);
        localProperties.setProperty("updateUrl", this.r);
        localProperties.setProperty("emailServer", this.w);
        localProperties.setProperty("emailUser", this.x);
        localProperties.setProperty("emailPasswd", ConnectionFactory.encrypt(this.y));
        localProperties.setProperty("emailAuthor", this.z);
        localProperties.setProperty("emailAuthorName", this.A);
        localProperties.setProperty("emailTo", this.B);
        localProperties.setProperty("emailToName", this.C);
        localProperties.setProperty("firstLogin", new Boolean(this.s).toString());
        localProperties.setProperty("loadDefault", new Boolean(this.t).toString());
        localProperties.setProperty("autoCheckVersion", new Boolean(this.u).toString());
        localProperties.setProperty("autoCheckVersionTime", new Long(this.v).toString());
        localProperties.setProperty("compositeBuffer", this.m);
        localProperties.setProperty("fontname", this.g.getFontData()[0].getName());
        localProperties.setProperty("fontheight", String.valueOf(this.g.getFontData()[0].getHeight()));
        localProperties.setProperty("fontstyle", String.valueOf(this.g.getFontData()[0].getStyle()));
        localProperties.store(new FileOutputStream(this.c), "Business Rule Builder Config File");
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}