/// <summary> /// Write the properties to the output stream. /// </summary> /// <param name="stream">The output stream where the properties are written.</param> /// <param name="comments">Optional comments that are placed at the beginning of the output.</param> public void Write(java.io.Writer stream, String comments ) { // Create a writer to output to an ISO-8859-1 encoding (code page 28592). //StreamWriter writer = new StreamWriter( stream, System.Text.Encoding.GetEncoding( 28592 ) ); java.io.BufferedWriter writer = new java.io.BufferedWriter(stream); if( comments != null) { comments = "# " + comments; } writer.write(comments); writer.newLine(); writer.write( "# " + DateTime.Now.ToString() ); writer.newLine(); writer.flush(); for( IEnumerator e = hashtable.Keys.GetEnumerator(); e.MoveNext(); ) { String key = e.Current.ToString(); String val = hashtable[ key ].ToString(); writer.write( escapeKey( key ) + "=" + escapeValue( val ) ); writer.newLine(); writer.flush(); } }
/* * Utilities for Preferences export */ internal static void exportPrefs(Preferences prefs, java.io.OutputStream stream, bool withSubTree) { //throws IOException, BackingStoreException { indent = -1; java.io.BufferedWriter outJ = new java.io.BufferedWriter(new java.io.OutputStreamWriter(stream, "UTF-8")); outJ.write(HEADER); outJ.newLine(); outJ.newLine(); outJ.write(DOCTYPE); outJ.write(" '"); outJ.write(PREFS_DTD_NAME); outJ.write("'>"); outJ.newLine(); outJ.newLine(); flushStartTag("preferences", new String[] { "EXTERNAL_XML_VERSION" }, new String[] { java.lang.StringJ.valueOf(XML_VERSION) }, outJ); flushStartTag("root", new String[] { "type" }, new String[] { prefs .isUserNode() ? "user" : "system" }, outJ); flushEmptyElement("map", outJ); StringTokenizer ancestors = new StringTokenizer(prefs.absolutePath(), "/"); exportNode(ancestors, prefs, withSubTree, outJ); flushEndTag("root", outJ); flushEndTag("preferences", outJ); outJ.flush(); outJ = null; }
static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs) { //throws IOException { java.io.BufferedWriter outJ = null; java.nio.channels.FileLock lockJ = null; try { java.io.FileOutputStream ostream = new java.io.FileOutputStream(file); outJ = new java.io.BufferedWriter(new java.io.OutputStreamWriter(ostream, "UTF-8")); //$NON-NLS-1$ java.nio.channels.FileChannel channel = ostream.getChannel(); lockJ = channel.lockJ(); outJ.write(HEADER); outJ.newLine(); outJ.write(FILE_PREFS); outJ.newLine(); if (prefs.size() == 0) { exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, outJ); } else { String[] keys = prefs.keySet() .toArray(new String[prefs.size()]); int length = keys.Length; String[] values = new String[length]; for (int i = 0; i < length; i++) { values [i] = prefs.getProperty(keys [i]); } exportEntries(keys, values, outJ); } outJ.flush(); } finally { releaseQuietly(lockJ); closeQuietly(outJ); } }
private static void flushIndent(int ind, java.io.BufferedWriter outJ) { //throws IOException { for (int i = 0; i < ind; i++) { outJ.write(" "); //$NON-NLS-1$ } }
/// <summary> /// Write the properties to the output stream. /// </summary> /// <param name="stream">The output stream where the properties are written.</param> /// <param name="comments">Optional comments that are placed at the beginning of the output.</param> public void Write(java.io.Writer stream, String comments) { // Create a writer to output to an ISO-8859-1 encoding (code page 28592). //StreamWriter writer = new StreamWriter( stream, System.Text.Encoding.GetEncoding( 28592 ) ); java.io.BufferedWriter writer = new java.io.BufferedWriter(stream); if (comments != null) { comments = "# " + comments; } writer.write(comments); writer.newLine(); writer.write("# " + DateTime.Now.ToString()); writer.newLine(); writer.flush(); for (IEnumerator e = hashtable.Keys.GetEnumerator(); e.MoveNext();) { String key = e.Current.ToString(); String val = hashtable[key].ToString(); writer.write(escapeKey(key) + "=" + escapeValue(val)); writer.newLine(); writer.flush(); } }
private static void flushStartTag(String tagName, java.io.BufferedWriter outJ) { //throws IOException { flushIndent(++indent, outJ); outJ.write("<"); //$NON-NLS-1$ outJ.write(tagName); outJ.write(">"); //$NON-NLS-1$ outJ.newLine(); }
private static void exportEntries(Preferences prefs, java.io.BufferedWriter outJ) { //throws BackingStoreException, IOException { String[] keys = prefs.keys(); String[] values = new String[keys.Length]; for (int i = 0; i < keys.Length; i++) { values [i] = prefs.get(keys [i], null); } exportEntries(keys, values, outJ); }
private static void flushEmptyElement(String tagName, String[] attrKeys, String[] attrValues, java.io.BufferedWriter outJ) { // throws IOException { flushIndent(++indent, outJ); outJ.write("<"); //$NON-NLS-1$ outJ.write(tagName); flushPairs(attrKeys, attrValues, outJ); outJ.write(" />"); //$NON-NLS-1$ outJ.newLine(); indent--; }
private static void flushPairs(String[] attrKeys, String[] attrValues, java.io.BufferedWriter outJ) { // throws IOException { for (int i = 0; i < attrKeys.Length; i++) { outJ.write(" "); //$NON-NLS-1$ outJ.write(attrKeys [i]); outJ.write("=\""); //$NON-NLS-1$ outJ.write(htmlEncode(attrValues [i])); outJ.write("\""); //$NON-NLS-1$ } }
private static void exportSubTree(Preferences prefs, java.io.BufferedWriter outJ) { //throws BackingStoreException, IOException { String[] names = prefs.childrenNames(); if (names.Length > 0) { for (int i = 0; i < names.Length; i++) { Preferences child = prefs.node(names [i]); flushStartTag( "node", new String[] { "name" }, new String[] { names [i] }, outJ); //$NON-NLS-1$ //$NON-NLS-2$ exportEntries(child, outJ); exportSubTree(child, outJ); flushEndTag("node", outJ); //$NON-NLS-1$ } } }
private static void exportEntries(String[] keys, String[] values, java.io.BufferedWriter outJ) { // throws IOException { if (keys.Length == 0) { flushEmptyElement("map", outJ); //$NON-NLS-1$ return; } flushStartTag("map", outJ); //$NON-NLS-1$ for (int i = 0; i < keys.Length; i++) { if (values [i] != null) { flushEmptyElement( "entry", new String[] { "key", "value" }, new String[] { keys [i], values [i] }, outJ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } flushEndTag("map", outJ); //$NON-NLS-1$ }
private static void exportNode(StringTokenizer ancestors, Preferences prefs, bool withSubTree, java.io.BufferedWriter outJ) { //throws IOException, BackingStoreException { if (ancestors.hasMoreTokens()) { String name = ancestors.nextToken(); flushStartTag( "node", new String[] { "name" }, new String[] { name }, outJ); //$NON-NLS-1$ //$NON-NLS-2$ if (ancestors.hasMoreTokens()) { flushEmptyElement("map", outJ); //$NON-NLS-1$ exportNode(ancestors, prefs, withSubTree, outJ); } else { exportEntries(prefs, outJ); if (withSubTree) { exportSubTree(prefs, outJ); } } flushEndTag("node", outJ); //$NON-NLS-1$ } }
static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs) { //throws IOException { java.io.BufferedWriter outJ = null; java.nio.channels.FileLock lockJ = null; try { java.io.FileOutputStream ostream = new java.io.FileOutputStream (file); outJ = new java.io.BufferedWriter (new java.io.OutputStreamWriter (ostream, "UTF-8")); //$NON-NLS-1$ java.nio.channels.FileChannel channel = ostream.getChannel (); lockJ = channel.lockJ (); outJ.write (HEADER); outJ.newLine (); outJ.write (FILE_PREFS); outJ.newLine (); if (prefs.size () == 0) { exportEntries (EMPTY_SARRAY, EMPTY_SARRAY, outJ); } else { String[] keys = prefs.keySet () .toArray (new String[prefs.size ()]); int length = keys.Length; String[] values = new String[length]; for (int i = 0; i < length; i++) { values [i] = prefs.getProperty (keys [i]); } exportEntries (keys, values, outJ); } outJ.flush (); } finally { releaseQuietly (lockJ); closeQuietly (outJ); } }
/* * Utilities for Preferences export */ internal static void exportPrefs(Preferences prefs, java.io.OutputStream stream, bool withSubTree) { //throws IOException, BackingStoreException { indent = -1; java.io.BufferedWriter outJ = new java.io.BufferedWriter (new java.io.OutputStreamWriter (stream, "UTF-8")); outJ.write (HEADER); outJ.newLine (); outJ.newLine (); outJ.write (DOCTYPE); outJ.write (" '"); outJ.write (PREFS_DTD_NAME); outJ.write ("'>"); outJ.newLine (); outJ.newLine (); flushStartTag ("preferences", new String[] { "EXTERNAL_XML_VERSION" }, new String[] { java.lang.StringJ.valueOf (XML_VERSION) }, outJ); flushStartTag ("root", new String[] { "type" }, new String[] { prefs .isUserNode () ? "user" : "system" }, outJ); flushEmptyElement ("map", outJ); StringTokenizer ancestors = new StringTokenizer (prefs.absolutePath (), "/"); exportNode (ancestors, prefs, withSubTree, outJ); flushEndTag ("root", outJ); flushEndTag ("preferences", outJ); outJ.flush (); outJ = null; }