@TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "storeToXML",
      args = {java.io.OutputStream.class, java.lang.String.class})
  public void test_storeToXMLLjava_io_OutputStreamLjava_lang_String() throws IOException {
    Properties myProps = new Properties();
    myProps.put("Property A", "value 1");
    myProps.put("Property B", "value 2");
    myProps.put("Property C", "value 3");

    Properties myProps2 = new Properties();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    myProps.storeToXML(out, "A Header");
    out.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    myProps2.loadFromXML(in);
    in.close();

    Enumeration e = myProps.propertyNames();
    while (e.hasMoreElements()) {
      String nextKey = (String) e.nextElement();
      assertTrue(
          "Stored property list not equal to original",
          myProps2.getProperty(nextKey).equals(myProps.getProperty(nextKey)));
    }

    try {
      myProps.storeToXML(null, "String");
      fail("NullPointerException expected");
    } catch (NullPointerException ee) {
      // expected
    }
  }
 /**
  * Write map of sets to a file.
  *
  * <p>The serialization format is XML properties format where values are comma separated lists.
  *
  * @param m map to serialize
  * @param filename output filename
  */
 private void writeMapToXML(final Map<String, Set<String>> m, final String filename) {
   if (m == null) {
     return;
   }
   final Properties prop = new Properties();
   for (final Map.Entry<String, Set<String>> entry : m.entrySet()) {
     final String key = entry.getKey();
     final String value = StringUtils.assembleString(entry.getValue(), COMMA);
     prop.setProperty(key, value);
   }
   final File outputFile = new File(tempDir, filename);
   OutputStream os = null;
   try {
     os = new FileOutputStream(outputFile);
     prop.storeToXML(os, null);
     os.close();
   } catch (final IOException e) {
     this.logger.logException(e);
   } finally {
     if (os != null) {
       try {
         os.close();
       } catch (final Exception e) {
         logger.logException(e);
       }
     }
   }
 }
示例#3
0
  /**
   * Save the properties of all renderers to the specified filename.
   *
   * @param propertyFilename String
   */
  private static void saveReportProperties(String propertyFilename) {

    Properties props = new Properties();

    for (Renderer renderer : ReportManager.instance.allRenderers()) {
      Map<PropertyDescriptor<?>, Object> valuesByProp =
          renderer.getPropertiesByPropertyDescriptor();
      for (Map.Entry<PropertyDescriptor<?>, Object> entry : valuesByProp.entrySet()) {
        PropertyDescriptor desc = entry.getKey();
        props.put(keyOf(renderer, desc), desc.asDelimitedString(entry.getValue()));
      }
    }

    FileOutputStream fos = null;

    try {
      fos = new FileOutputStream(propertyFilename);
      props.storeToXML(fos, "asdf");

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      IOUtil.closeQuietly(fos);
    }
  }
示例#4
0
  public void storeClaimBackup(Claim claim, World world) {
    int baseX = getBase(claim.getX());
    long topX = claim.getX() >= 0 ? baseX + claimSize : baseX - claimSize;

    int baseZ = getBase(claim.getZ());
    long topZ = claim.getZ() >= 0 ? baseZ + claimSize : baseZ - claimSize;

    int maxY = world.getMaxHeight();

    Properties props = new Properties();

    for (int y = 0; y <= maxY; y++) {
      for (int z = baseZ; z <= topZ; z++) {
        for (int x = baseX; x <= topX; x++) {
          Block blockAt = world.getBlockAt(x, y, z);
          props.put(
              String.format("%d,%d,%d", x, y, z),
              String.format("%d:%d", blockAt.getTypeId(), blockAt.getData()));
        }
      }
    }

    File file = new File(backupFolder, String.format("claim-%d.xml"));

    try {
      props.storeToXML(
          new FileOutputStream(file), String.format("Claim backup for claim %d", claim.getId()));
    } catch (FileNotFoundException e) {
      logger.severe("Could not write backup to file" + file.getName());
    } catch (IOException e) {
      logger.severe("Could not write backup to file" + file.getName() + ": " + e.getMessage());
    }
  }
 public void storeToXML(String filename, String comments) {
   try {
     conf.storeToXML(new FileOutputStream(filename), comments);
   } catch (IOException e) {
     System.err.println("Cannot open " + filename + ".");
     e.printStackTrace();
   }
 }
示例#6
0
 public void save() throws XLException {
   FileOutputStream fos;
   try {
     fos = new FileOutputStream(this.configPath);
     props.storeToXML(fos, "3XL Configuration", "UTF-8");
   } catch (Exception e) {
     throw new XLException(e);
   }
 }
示例#7
0
 protected void setProperties(Properties props) {
   try {
     Resource projectProperties = getProjectRoot().createRelative(PROJECT_PROPERTIES);
     OutputStream os = getFileSystem().getOutputStream(projectProperties);
     props.storeToXML(os, "Project Properties", getEncoding());
     os.close();
   } catch (IOException e) {
     throw new WMRuntimeException(e);
   }
 }
  public void writeFile(File localeFile) throws IOException {
    if (!localeFile.getParentFile().exists()) localeFile.getParentFile().mkdirs();

    try (FileOutputStream out = new FileOutputStream(localeFile)) {
      dict.storeToXML(out, null);
    } /* catch (IOException e) {
      	System.err.format(Locale.act().get("err.ioerror"), configFile.getAbsolutePath());
      	System.err.println();
      	e.printStackTrace();
      }*/
  }
示例#9
0
 public final void setResourceAsProperties(String sName, Properties p) {
   if (p == null) {
     setResource(sName, 0, null); // texto
   } else {
     try {
       ByteArrayOutputStream o = new ByteArrayOutputStream();
       p.storeToXML(o, AppLocal.APP_NAME, "UTF8");
       setResource(sName, 0, o.toByteArray()); // El texto de las propiedades
     } catch (IOException e) { // no deberia pasar nunca
     }
   }
 }
  private String toXML(Properties props) {
    if (props == null || props.isEmpty()) return null;

    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream(props.size() * 20);
      props.storeToXML(out, null, "ISO-8859-1");
      String xml = out.toString("ISO-8859-1");
      return xml.replaceAll(StringUtil.REGEX_CRLF, "");
    } catch (Throwable th) {
      LogMgr.logError(
          "IniProfileStorage.toXM()", "Could not convert connection properties to XML", th);
      return null;
    }
  }
  /**
   * @throws IOException
   * @tests java.util.Properties#loadFromXML(java.io.InputStream)
   */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "loadFromXML",
      args = {java.io.InputStream.class})
  @KnownFailure("Expected Exception is not thrown.")
  public void test_loadFromXMLLjava_io_InputStream() throws IOException {
    Properties myProps = new Properties();
    myProps.put("Property A", " aye\\\f\t\n\r\b");
    myProps.put("Property B", "b ee#!=:");
    myProps.put("Property C", "see");
    Properties myProps2 = new Properties();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    myProps.storeToXML(out, "A Header");
    out.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    try {
      myProps2.loadFromXML(in);
      fail("InvalidPropertiesFormatException expected");
    } catch (InvalidPropertiesFormatException e) {
      // expected
    }
    in.close();

    Properties prop = new Properties();
    InputStream is = new ByteArrayInputStream(writePropertiesXML("UTF-8"));
    prop.loadFromXML(is);
    is.close();

    assertEquals("Failed to load correct properties", "value3", prop.getProperty("key3"));
    assertEquals("Failed to load correct properties", "value1", prop.getProperty("key1"));

    prop = new Properties();
    is = new ByteArrayInputStream(writePropertiesXML("ISO-8859-1"));
    prop.loadFromXML(is);
    is.close();

    assertEquals("Failed to load correct properties", "value2", prop.getProperty("key2"));
    assertEquals("Failed to load correct properties", "value1", prop.getProperty("key1"));

    try {
      prop.loadFromXML(null);
      fail("NullPointerException expected");
    } catch (NullPointerException e) {
      // expected
    }
  }
示例#12
0
 private void createConfig(String filename) {
   String path = getPath(filename);
   config.setProperty("PatronDB", Configure.getPath("Patrons.dbflat"));
   config.setProperty("ItemDB", Configure.getPath("Items.dbflat"));
   config.setProperty("FineDB", Configure.getPath("Fines.dbflat"));
   config.setProperty("AvailabilityDB", Configure.getPath("ItemAvailability.dbflat"));
   try {
     FileOutputStream propFile = new FileOutputStream(path);
     config.storeToXML(propFile, "");
   } catch (FileNotFoundException fnfe) {
     UserInterface.Error(104);
   } catch (IOException ioe) {
     UserInterface.Error(104);
   }
 }
 public static void saveConfigInts(String key, int value) {
   try {
     File file = new File(path);
     boolean exist = file.exists();
     if (!exist) {
       file.createNewFile();
     }
     OutputStream write = new FileOutputStream(path);
     prop.setProperty(key, Integer.toString(value));
     prop.storeToXML(write, "Frames per Second");
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
   }
 }
 public static void write(
     String filePath, Properties properties, String comment, OutputStream out) {
   if (properties != null) {
     if (out != null) {
       try {
         properties.storeToXML(out, comment);
       } catch (IOException e) {
         logger.severe(ExceptionHelper.printStackTrace(e));
       }
     } else {
       logger.info("There is no valid output stream, since the outputstream is null! ");
     }
   } else {
     logger.info("There is no properties file written, since the properties are null! ");
   }
 }
 private void writeProperties(final Properties props, final File ditaList, final boolean isXML)
     throws IOException {
   OutputStream out = null;
   try {
     out = new FileOutputStream(ditaList);
     if (isXML) {
       props.storeToXML(out, null);
     } else {
       props.store(out, null);
     }
   } finally {
     if (out != null) {
       out.close();
     }
   }
 }
示例#16
0
 /** Save user preferences. */
 public void save() {
   try {
     OutputStream os = m_context.openFileOutput(PREFS_FILENAME, Context.MODE_PRIVATE);
     Properties properties = new Properties();
     properties.setProperty(PREF_PARANOID, Paranoid ? "true" : "false");
     properties.setProperty(PREF_INVERT_COLOR, InvertBg ? "true" : "false");
     properties.setProperty(PREF_GLOBAL_PWD, Global_pwd ? "true" : "false");
     properties.setProperty(PREF_SHOW_PAT, ShowPat ? "true" : "false");
     properties.setProperty(PREF_SHOW_PWD, ShowPwd ? "true" : "false");
     properties.setProperty(PREF_TEXT_SCALE, String.valueOf(TextScale));
     properties.storeToXML(os, "EncrypNotes properties");
     os.close();
   } catch (FileNotFoundException ex) {
     ex.printStackTrace();
   } catch (IOException ex) {
     ex.printStackTrace();
   }
 }
示例#17
0
  /**
   * Save the preferences state in memory (i.e for the current session) to file.
   *
   * @param comment comment to be included in the preference file.
   * @throws PreferencesException if the preference file could not be written.
   */
  public final void saveToFile(final String comment) throws PreferencesException {
    // Store current Preference object revision number
    setPreference(JMCS_STRUCTURE_VERSION_NUMBER_ID, getJmcsStructureVersionNumber());
    setPreference(PREFERENCES_VERSION_NUMBER_ID, getPreferencesVersionNumber());

    OutputStream outputFile = null;
    try {
      outputFile = new BufferedOutputStream(new FileOutputStream(_fullFilepath));

      _logger.info("Saving '{}' preference file.", _fullFilepath);

      _currentProperties.storeToXML(outputFile, comment);

    } catch (IOException ioe) {
      throw new PreferencesException("Cannot store preferences to file " + _fullFilepath, ioe);
    } finally {
      FileUtils.closeStream(outputFile);
    }
  }
  private Properties writeDefaultDesktopAgentPropertiesFile(File objPropertiesFile)
      throws InvalidPropertiesFormatException, IOException {
    Properties tempProps = new Properties();
    FileOutputStream fos = new FileOutputStream(objPropertiesFile);

    tempProps.put("desktop_agent_left", "0");
    tempProps.put("desktop_agent_top", "0");
    tempProps.put("desktop_agent_width", "300");
    tempProps.put("desktop_agent_height", "450");
    tempProps.put("desktop_agent_use_custom_window_controls", "false");
    tempProps.put("desktop_agent_background_color", "808080");
    tempProps.put("desktop_agent_buttons_background_color", "808080");

    tempProps.put("agents_directory", "Desktop Agent Agents");
    tempProps.put("number_of_agents", "1");
    tempProps.put("agent_files", "GreetingAgent.agent");

    tempProps.storeToXML(fos, "Desktop Agent Properties File", "UTF-8");

    return tempProps;
  }
  @Override
  public void run() {
    Provider[] ps = java.security.Security.getProviders();
    for (Provider p : ps) {
      System.out.println("=========================================================");
      System.out.println(p);
      p.list(System.out);
    }

    try {
      System.out.println();
      System.out.println("=========================================================");
      System.out.println("a test of " + Properties.class);
      Properties ppt = new Properties();
      ppt.setProperty("hello", "world");
      ppt.list(System.out);
      ppt.store(System.out, "[some comments]");
      ppt.storeToXML(System.out, "[some comments]", "utf-8");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#20
0
  public static void saveFileContent(String filePath, Properties content) throws JDependException {

    assert filePath != null && filePath.length() != 0;
    FileOutputStream fis = null;
    try {
      fis = new FileOutputStream(filePath);
      content.storeToXML(fis, null);
    } catch (FileNotFoundException e) {
      LogUtil.getInstance(FileUtil.class).systemError("文件[" + filePath + "]保存失败。");
      throw new JDependException("文件[" + filePath + "]保存失败。", e);
    } catch (IOException e) {
      LogUtil.getInstance(FileUtil.class).systemError("文件[" + filePath + "]保存失败。");
      throw new JDependException("文件[" + filePath + "]保存失败。", e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
示例#21
0
 public static void save() throws IOException {
   FileOutputStream fos = new FileOutputStream(CONFIG_FILE_NAME);
   properties.storeToXML(fos, "This is the configuration file for Hightail.", "utf-8");
 }
 public void save() throws Exception {
   File prefFile = _getPrefFile();
   m_prefs.storeToXML(new FileOutputStream(prefFile), "Preferences for '" + m_name + "'", "UTF-8");
 }
  /**
   * @throws IOException
   * @tests java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String,
   *     java.lang.String)
   */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "storeToXML",
      args = {java.io.OutputStream.class, java.lang.String.class, java.lang.String.class})
  public void test_storeToXMLLjava_io_OutputStreamLjava_lang_StringLjava_lang_String()
      throws IOException {
    Properties myProps = new Properties();
    myProps.setProperty("key1", "value1");
    myProps.setProperty("key2", "value2");
    myProps.setProperty("key3", "value3");
    myProps.setProperty("<a>key4</a>", "\"value4");
    myProps.setProperty("key5   ", "<h>value5</h>");
    myProps.setProperty("<a>key6</a>", "   <h>value6</h>   ");
    myProps.setProperty("<comment>key7</comment>", "value7");
    myProps.setProperty("  key8   ", "<comment>value8</comment>");
    myProps.setProperty("&lt;key9&gt;", "\u0027value9");
    myProps.setProperty("key10\"", "&lt;value10&gt;");
    myProps.setProperty("&amp;key11&amp;", "value11");
    myProps.setProperty("key12", "&amp;value12&amp;");
    myProps.setProperty("<a>&amp;key13&lt;</a>", "&amp;&value13<b>&amp;</b>");

    // store in UTF-8 encoding
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    myProps.storeToXML(out, "comment");
    out.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Properties myProps2 = new Properties();
    myProps2.loadFromXML(in);
    in.close();

    Enumeration e = myProps.propertyNames();
    while (e.hasMoreElements()) {
      String nextKey = (String) e.nextElement();
      assertTrue(
          "Stored property list not equal to original",
          myProps2.getProperty(nextKey).equals(myProps.getProperty(nextKey)));
    }

    // store in ISO-8859-1 encoding
    out = new ByteArrayOutputStream();
    myProps.storeToXML(out, "comment", "ISO-8859-1");
    out.close();

    in = new ByteArrayInputStream(out.toByteArray());
    myProps2 = new Properties();
    myProps2.loadFromXML(in);
    in.close();

    e = myProps.propertyNames();
    while (e.hasMoreElements()) {
      String nextKey = (String) e.nextElement();
      assertTrue(
          "Stored property list not equal to original",
          myProps2.getProperty(nextKey).equals(myProps.getProperty(nextKey)));
    }

    out = new ByteArrayOutputStream();
    myProps.storeToXML(out, "comment", "ISO-8859-1");
    myProps.storeToXML(out, null, "ISO-8859-1");
    out.close();

    try {
      myProps.storeToXML(out, "comment", null);
      fail("NulPointerException expected");
    } catch (NullPointerException ee) {
      // expected
    }

    try {
      myProps.storeToXML(null, "comment", "ISO-8859-1");
      fail("NulPointerException expected");
    } catch (NullPointerException ee) {
      // expected
    }
  }
示例#24
0
 public void storeToXML(OutputStream os, String comment) throws IOException {
   p.storeToXML(os, comment);
 }
 public void writeProperties() throws InvalidPropertiesFormatException, IOException {
   FileOutputStream fos = new FileOutputStream(propertiesFile);
   properties.storeToXML(fos, "Desktop Agent Properties File", "UTF-8");
 }