1 33 34 package edu.rice.cs.drjava.config; 35 36 import java.io.*; 37 import java.util.Iterator ; 38 import java.util.Date ; 39 40 43 public class SavableConfiguration extends Configuration { 44 48 public SavableConfiguration(OptionMap map) { super(map); } 49 50 56 public void loadConfiguration(InputStream is) throws IOException { 57 new OptionMapLoader(is).loadInto(map); 58 } 59 60 66 public void saveConfiguration(OutputStream os, String header) throws IOException { 67 Writer w = new BufferedWriter(new OutputStreamWriter(os)); 68 Iterator <OptionParser<?>> keys = map.keys(); 69 74 Date date = new Date (); 76 w.write((int)'#'); 77 w.write(header, 0, header.length()); 78 w.write((int)'\n'); 79 w.write((int)'#'); 80 w.write(date.toString(), 0, date.toString().length()); 81 w.write((int)'\n'); 82 83 while (keys.hasNext()) { 85 86 OptionParser<?> key = keys.next(); 87 88 if (!key.getDefault().equals(map.getOption(key))) { 89 90 String tmpString = key.getName(); 92 w.write(tmpString, 0, tmpString.length()); 93 94 tmpString = " = "; 96 w.write(tmpString, 0, 3); 97 98 tmpString = map.getString(key); 100 int index = 0; 102 int pos; 103 while (index < tmpString.length() && 104 ((pos = tmpString.indexOf('\\', index)) >= 0)) { 105 final StringBuilder buff = new StringBuilder (tmpString); buff.insert(pos, '\\'); 107 index = pos + 2; 108 tmpString = buff.toString(); 109 } 110 w.write(tmpString, 0, tmpString.length()); 111 w.write((int)'\n'); 112 113 } 115 } 116 w.close(); 117 } 119 } 120 | Popular Tags |