[jsword-svn] r1162 - trunk/jsword/src/main/java/org/crosswire/jsword/book/sword
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Mon Oct 16 18:28:08 MST 2006
Author: dmsmith
Date: 2006-10-16 18:28:02 -0700 (Mon, 16 Oct 2006)
New Revision: 1162
Modified:
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
Log:
fix some potential bugs.
Prepare ConfigEntryTable to be used to author a new config file.
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java 2006-10-15 22:37:25 UTC (rev 1161)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java 2006-10-17 01:28:02 UTC (rev 1162)
@@ -65,72 +65,103 @@
public class ConfigEntryTable
{
/**
- * Loads a sword config from a given file.
- * @throws IOException
+ * Create an empty Sword config for the named book.
+ * @param bookName the name of the book
*/
- public ConfigEntryTable(File file, String bookName) throws IOException
+ public ConfigEntryTable(String bookName)
{
- configFile = file;
+ table = new HashMap();
internal = bookName;
supported = true;
- table = new HashMap();
+ }
- BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_LATIN1));
- loadInitials(in);
- loadContents(in);
- in.close();
- if (getValue(ConfigEntryType.ENCODING).equals(ENCODING_UTF8))
+ /**
+ * Load the conf from a file.
+ * @param file the file to load
+ * @throws IOException
+ */
+ public void load(File file) throws IOException
+ {
+ configFile = file;
+
+ BufferedReader in = null;
+ try
{
- supported = true;
- bookType = null;
- questionable = false;
- readahead = null;
- table.clear();
- in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_UTF8));
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_LATIN1));
loadInitials(in);
loadContents(in);
in.close();
+ in = null;
+ if (getValue(ConfigEntryType.ENCODING).equals(ENCODING_UTF8))
+ {
+ supported = true;
+ bookType = null;
+ questionable = false;
+ readahead = null;
+ table.clear();
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(file), ENCODING_UTF8));
+ loadInitials(in);
+ loadContents(in);
+ in.close();
+ in = null;
+ }
+ adjustDataPath();
+ adjustLanguage();
+ adjustBookType();
+ adjustName();
+ validate();
}
- adjustDataPath();
- adjustLanguage();
- adjustBookType();
- adjustName();
- validate();
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+ }
}
/**
- * Loads a sword config from a given buffer.
+ * Load the conf from a buffer.
* This is used to load conf entries from the mods.d.tar.gz file.
- *
+ * @param buffer the buffer to load
* @throws IOException
*/
- public ConfigEntryTable(byte[] buffer, String bookName) throws IOException
+ public void load(byte[] buffer) throws IOException
{
- internal = bookName;
- supported = true;
- table = new HashMap();
-
- BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_LATIN1));
- loadInitials(in);
- loadContents(in);
- in.close();
- if (getValue(ConfigEntryType.ENCODING).equals(ENCODING_UTF8))
+ BufferedReader in = null;
+ try
{
- supported = true;
- bookType = null;
- questionable = false;
- readahead = null;
- table.clear();
- in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_UTF8));
+ in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_LATIN1));
loadInitials(in);
loadContents(in);
in.close();
+ in = null;
+ if (getValue(ConfigEntryType.ENCODING).equals(ENCODING_UTF8))
+ {
+ supported = true;
+ bookType = null;
+ questionable = false;
+ readahead = null;
+ table.clear();
+ in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer), ENCODING_UTF8));
+ loadInitials(in);
+ loadContents(in);
+ in.close();
+ in = null;
+ }
+ adjustDataPath();
+ adjustLanguage();
+ adjustBookType();
+ adjustName();
+ validate();
}
- adjustDataPath();
- adjustLanguage();
- adjustBookType();
- adjustName();
- validate();
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+ }
}
/**
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java 2006-10-15 22:37:25 UTC (rev 1161)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java 2006-10-17 01:28:02 UTC (rev 1162)
@@ -70,7 +70,8 @@
*/
public SwordBookMetaData(File file, String internal, URL bookRootPath) throws IOException
{
- cet = new ConfigEntryTable(file, internal);
+ cet = new ConfigEntryTable(internal);
+ cet.load(file);
cet.add(ConfigEntryType.LIBRARY_URL, bookRootPath.toExternalForm());
// Currently all DATA_PATH entries end in / to indicate dirs or not to indicate file prefixes
String datapath = getProperty(ConfigEntryType.DATA_PATH);
@@ -92,7 +93,8 @@
*/
public SwordBookMetaData(byte[] buffer, String internal) throws IOException
{
- cet = new ConfigEntryTable(buffer, internal);
+ cet = new ConfigEntryTable(internal);
+ cet.load(buffer);
buildProperties();
}
More information about the jsword-svn
mailing list