diff src/org/tmatesoft/hg/internal/ConfigFile.java @ 295:981f9f50bb6c

Issue 11: Error log facility. SessionContext to share common facilities
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Sep 2011 05:35:32 +0200
parents 947bf231acbb
children a37ce7145c3f
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ConfigFile.java	Wed Sep 14 04:41:57 2011 +0200
+++ b/src/org/tmatesoft/hg/internal/ConfigFile.java	Fri Sep 16 05:35:32 2011 +0200
@@ -36,10 +36,10 @@
 	private List<String> sections;
 	private List<Map<String,String>> content;
 
-	ConfigFile() {
+	public ConfigFile() {
 	}
 
-	public void addLocation(File path) {
+	public void addLocation(File path) throws IOException {
 		read(path);
 	}
 	
@@ -92,7 +92,7 @@
 
 	// TODO handle %include and %unset directives
 	// TODO "" and lists
-	private void read(File f) {
+	private void read(File f) throws IOException {
 		if (f == null || !f.canRead()) {
 			return;
 		}
@@ -100,8 +100,9 @@
 			sections = new ArrayList<String>();
 			content = new ArrayList<Map<String,String>>();
 		}
+		BufferedReader br = null;
 		try {
-			BufferedReader br = new BufferedReader(new FileReader(f));
+			br = new BufferedReader(new FileReader(f));
 			String line;
 			String sectionName = "";
 			Map<String,String> section = new LinkedHashMap<String, String>();
@@ -140,12 +141,13 @@
 					section.put(key, value);
 				}
 			}
-			br.close();
-		} catch (IOException ex) {
-			ex.printStackTrace(); // XXX shall outer world care?
+		} finally {
+			((ArrayList<?>) sections).trimToSize();
+			((ArrayList<?>) content).trimToSize();
+			if (br != null) {
+				br.close();
+			}
 		}
-		((ArrayList<?>) sections).trimToSize();
-		((ArrayList<?>) content).trimToSize();
 		assert sections.size() == content.size();
 	}
 }