Example usage for java.util Properties storeToXML

List of usage examples for java.util Properties storeToXML

Introduction

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

Prototype

public void storeToXML(OutputStream os, String comment, Charset charset) throws IOException 

Source Link

Document

Emits an XML document representing all of the properties contained in this table, using the specified encoding.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties prop = new Properties();

    prop.put("Chapter Count", "200");
    prop.put("Tutorial Count", "15");
    prop.put("tutorial", "java2s.com");

    // create a output and input as a xml file
    FileOutputStream fos = new FileOutputStream("properties.xml");
    FileInputStream fis = new FileInputStream("properties.xml");

    prop.storeToXML(fos, "Properties Example", "ISO 8859");

    while (fis.available() > 0) {
        System.out.print((char) fis.read());
    }//from  w w  w.java 2  s. c o m

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties properties = new Properties();
    properties.setProperty("database.type", "mysql");
    properties.setProperty("database.url", "jdbc:mysql://localhost/mydb");
    properties.setProperty("database.username", "root");
    properties.setProperty("database.password", "root");

    FileOutputStream fos = new FileOutputStream("database-configuration.xml");
    properties.storeToXML(fos, "Database Configuration", "UTF-8");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
      Properties properties = new Properties();
      properties.setProperty("database.type", "mysql");
      properties.setProperty("database.url", "jdbc:mysql://localhost/mydb");
      properties.setProperty("database.username", "root");
      properties.setProperty("database.password", "root");

      FileOutputStream fos = new FileOutputStream("database-configuration.xml");
      properties.storeToXML(fos, "Database Configuration", "UTF-8");
  }/*from w w w.j a  v a 2s.co  m*/

From source file:eu.planets_project.tb.gui.backing.exp.ExpTypeMigrate.java

public static void main(String args[]) {

    Properties p = System.getProperties();

    ByteArrayOutputStream byos = new ByteArrayOutputStream();
    try {//from  w ww  . j  a  v a2  s .  c om
        p.storeToXML(byos, "Automatically generated for PLANETS Service ", "UTF-8");
        String res = byos.toString("UTF-8");
        System.out.println(res);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // This.
    List<String> pl = new ArrayList<String>();
    for (Object key : p.keySet()) {
        pl.add((String) key);
    }
    Collections.sort(pl);

    //
    for (String key : pl) {
        System.out.println(key + " = " + p.getProperty(key));
    }

    /*
     * http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ThreadMXBean.html#getCurrentThreadCpuTime()
     * 
     * http://www.java-forums.org/new-java/5303-how-determine-cpu-usage-using-java.html
     * 
     */

    ThreadMXBean TMB = ManagementFactory.getThreadMXBean();
    int mscale = 1000000;
    long time = 0, time2 = 0;
    long cput = 0, cput2 = 0;
    double cpuperc = -1;

    //Begin loop.
    for (int i = 0; i < 10; i++) {

        if (TMB.isThreadCpuTimeSupported()) {
            if (!TMB.isThreadCpuTimeEnabled()) {
                TMB.setThreadCpuTimeEnabled(true);
            }

            //                if(new Date().getTime() * mscale - time > 1000000000) //Reset once per second
            //                {
            System.out.println("Resetting...");
            time = System.currentTimeMillis() * mscale;
            cput = TMB.getCurrentThreadCpuTime();
            //                cput = TMB.getCurrentThreadUserTime();
            //                }

        }

        //Do cpu intensive stuff
        for (int k = 0; k < 10; k++) {
            for (int j = 0; j < 100000; j++) {
                double a = Math.pow(i, j);
                double b = a / j + Math.random();
                a = b * Math.random();
                b = a * Math.random();
            }

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        if (TMB.isThreadCpuTimeSupported()) {
            //                if(new Date().getTime() * mscale - time != 0) {
            cput2 = TMB.getCurrentThreadCpuTime();
            System.out.println("cpu: " + (cput2 - cput) / (1000.0 * mscale));
            //                cput2 = TMB.getCurrentThreadUserTime();

            time2 = System.currentTimeMillis() * mscale;
            System.out.println("time: " + (time2 - time) / (1000.0 * mscale));

            cpuperc = 100.0 * (cput2 - cput) / (double) (time2 - time);
            System.out.println("cpu perc = " + cpuperc);
            //                }
        }
        //End Loop
    }
    System.out.println("Done.");
}

From source file:net.sourceforge.jaulp.lang.PropertiesUtils.java

/**
 * Converts the given properties InputStream to the given xml OutputStream.
 * //from   w w  w.j a va 2  s. c  o  m
 * @param properties
 *            the properties InputStream.
 * @param xml
 *            the xml OutputStream to write in.
 * @param comment
 *            the comment
 * @param encoding
 *            the encoding for the xml file.
 * @throws FileNotFoundException
 *             the file not found exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void toXml(InputStream properties, OutputStream xml, String comment, String encoding)
        throws FileNotFoundException, IOException {
    Properties prop = new Properties();
    prop.load(properties);
    prop.storeToXML(xml, comment, encoding);
}

From source file:de.alpharogroup.lang.PropertiesUtils.java

/**
 * Converts the given properties InputStream to the given xml OutputStream.
 * /*from   w  ww.  j a v  a  2s.c o  m*/
 * @param properties
 *            the properties InputStream.
 * @param xml
 *            the xml OutputStream to write in.
 * @param comment
 *            the comment
 * @param encoding
 *            the encoding for the xml file.
 * @throws FileNotFoundException
 *             the file not found exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void toXml(final InputStream properties, final OutputStream xml, final String comment,
        final String encoding) throws FileNotFoundException, IOException {
    final Properties prop = new Properties();
    prop.load(properties);
    prop.storeToXML(xml, comment, encoding);
}

From source file:com.benasmussen.maven.plugin.i18n.io.XmlResourceWriter.java

@Override
protected void after(ResourceEntry resourceEntry) {
    super.after(resourceEntry);

    Set<String> keySet = output.keySet();
    for (String locale : keySet) {
        String filename = getFilename(resourceEntry, locale);

        OutputStream os = null;/* www  . j  a v  a  2s.  c  o  m*/
        try {
            File outputFile = new File(outputFolder, filename);
            os = new FileOutputStream(outputFile);

            Properties properties = output.get(locale);
            properties.storeToXML(os, "Generated file " + filename, getOutputEnconding());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(os);
        }

    }

}

From source file:org.jenkinsci.plugins.exportparams.serializer.XMLSerializer.java

@Override
public void doStore(Properties props, Writer writer) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    props.storeToXML(os, null, CharEncoding.UTF_8);
    writer.write(os.toString(CharEncoding.UTF_8));
    writer.flush();/* www.  ja v  a2s .co  m*/
    os.close();
}

From source file:com.xiongyingqi.util.DefaultPropertiesPersister.java

@Override
public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException {
    props.storeToXML(os, header, encoding);
}

From source file:com.opensource.frameworks.processframework.utils.DefaultPropertiesPersister.java

public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException {
    try {// www . j av a  2 s.  c om
        props.storeToXML(os, header, encoding);
    } catch (NoSuchMethodError err) {
        throw new IOException(
                "Cannot store properties XML file - not running on JDK 1.5+: " + err.getMessage());
    }
}