Example #1
0
        /// <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();
            }
        }
Example #2
0
 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);
     }
 }
Example #3
0
        /*
         * 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;
        }