1 11 package org.eclipse.help.internal.base.util; 12 13 import java.io.*; 14 import java.util.Properties ; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.help.internal.*; 18 19 22 public class HelpProperties extends Properties { 23 24 private static final long serialVersionUID = 1L; 25 26 private File file = null; 27 28 protected String name = null; 29 30 38 public HelpProperties(String name, Plugin plugin) { 39 this(name, plugin.getStateLocation().toFile()); 40 } 41 42 50 public HelpProperties(String name, File dir) { 51 super(); 52 this.name = name; 53 file = new File(dir, name); 54 } 55 56 61 public boolean restore() { 62 InputStream in = null; 63 boolean loaded = false; 64 clear(); 65 if (!file.exists()) 69 return loaded; 70 try { 71 in = new FileInputStream(file); 72 super.load(in); 73 loaded = true; 74 } catch (IOException ioe00) { 75 HelpPlugin.logError("File " + file.getName() + " cannot be read."); } finally { 77 if (in != null) 78 try { 79 in.close(); 80 } catch (IOException ioe10) { 81 } 82 } 83 return loaded; 84 } 85 86 91 public boolean save() { 92 OutputStream out = null; 93 boolean ret = false; 94 try { 95 out = new FileOutputStream(file); 96 super.store(out, "This is a generated file; do not edit."); ret = true; 98 } catch (IOException ioe00) { 99 HelpPlugin.logError("Exception occurred while saving table " + name + " to file " + file.getAbsolutePath() + ".", ioe00); } finally { 102 try { 103 if (out != null) { 104 out.close(); 105 } 106 } catch (IOException ioe01) { 107 } 108 } 109 return ret; 110 } 111 } 112 | Popular Tags |