[jsword-svn] r1794 - trunk/jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Apr 11 03:48:42 MST 2008


Author: dmsmith
Date: 2008-04-11 03:48:41 -0700 (Fri, 11 Apr 2008)
New Revision: 1794

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
Log:
More incremental performance improvements to module content handling.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2008-04-10 21:18:07 UTC (rev 1793)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2008-04-11 10:48:41 UTC (rev 1794)
@@ -32,6 +32,7 @@
 import org.crosswire.common.activate.Lock;
 import org.crosswire.common.util.FileUtil;
 import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.BookException;
 import org.crosswire.jsword.passage.DefaultKeyList;
 import org.crosswire.jsword.passage.Key;
@@ -49,20 +50,10 @@
     /**
      * Simple ctor
      */
-    public GenBookBackend(SwordBookMetaData sbmd) throws BookException
+    public GenBookBackend(SwordBookMetaData sbmd)
     {
         super(sbmd);
-
         index = new TreeKeyIndex(sbmd);
-
-        URI path = getExpandedDataPath();
-        bdtFile = new File(path.getPath() + EXTENSION_BDT);
-
-        if (!bdtFile.canRead())
-        {
-            throw new BookException(UserMsg.READ_FAIL, new Object[] { bdtFile.getAbsolutePath() });
-        }
-
     }
 
     /* (non-Javadoc)
@@ -70,8 +61,29 @@
      */
     public final void activate(Lock lock)
     {
+        Activator.activate(index);
+
+        URI path = null;
         try
         {
+            path = getExpandedDataPath();
+        }
+        catch (BookException e)
+        {
+            Reporter.informUser(this, e);
+            return;
+        }
+
+        bdtFile = new File(path.getPath() + EXTENSION_BDT);
+
+        if (!bdtFile.canRead())
+        {
+            Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { bdtFile.getAbsolutePath() }));
+            return;
+        }
+
+        try
+        {
             bdtRaf = new RandomAccessFile(bdtFile, FileUtil.MODE_READ);
         }
         catch (IOException ex)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawBackend.java	2008-04-10 21:18:07 UTC (rev 1793)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawBackend.java	2008-04-11 10:48:41 UTC (rev 1794)
@@ -32,6 +32,7 @@
 import org.crosswire.common.util.FileUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
+import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.BookException;
 import org.crosswire.jsword.passage.Key;
 import org.crosswire.jsword.passage.KeyUtil;
@@ -50,15 +51,100 @@
     /**
      * Simple ctor
      */
-    public RawBackend(SwordBookMetaData sbmd, int datasize) throws BookException
+    public RawBackend(SwordBookMetaData sbmd, int datasize)
     {
         super(sbmd);
         this.datasize = datasize;
+        this.entrysize = OFFSETSIZE + datasize;
 
         assert (datasize == 2 || datasize == 4);
+    }
 
-        URI path = getExpandedDataPath();
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.sword.AbstractBackend#getRawText(org.crosswire.jsword.passage.Key, java.lang.String)
+     */
+    /* @Override */
+    public String getRawText(Key key) throws BookException
+    {
+        checkActive();
 
+        Verse verse = KeyUtil.getVerse(key);
+
+        try
+        {
+            int testament = SwordConstants.getTestament(verse);
+            long index = SwordConstants.getIndex(verse);
+
+            // If this is a single testament Bible, return nothing.
+            if (idxRaf[testament] == null)
+            {
+                return ""; //$NON-NLS-1$
+            }
+
+            return getEntry(key.getName(), testament, index);
+        }
+        catch (IOException ex)
+        {
+            throw new BookException(UserMsg.READ_FAIL, ex, new Object[] { verse.getName() });
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.sword.AbstractBackend#isWritable()
+     */
+    public boolean isWritable()
+    {
+        // For the module to be writable either the old testament or the new testament needs to be present
+        // (i.e. readable) and both the index and the data files need to be readable
+        if (idxFile[SwordConstants.TESTAMENT_OLD].canRead()
+            && (idxFile[SwordConstants.TESTAMENT_OLD].canWrite() || !txtFile[SwordConstants.TESTAMENT_OLD].canWrite()))
+        {
+            return false;
+        }
+        if (idxFile[SwordConstants.TESTAMENT_NEW].canRead()
+            && (idxFile[SwordConstants.TESTAMENT_NEW].canWrite() || !txtFile[SwordConstants.TESTAMENT_NEW].canWrite()))
+        {
+            return false;
+        }
+        return idxFile[SwordConstants.TESTAMENT_OLD].canRead() || idxFile[SwordConstants.TESTAMENT_NEW].canRead();
+    }
+
+    public void create(String path)
+    {
+        idxFile[SwordConstants.TESTAMENT_OLD] = new File(path + File.separator + SwordConstants.FILE_OT + SwordConstants.EXTENSION_VSS);
+        txtFile[SwordConstants.TESTAMENT_OLD] = new File(path + File.separator + SwordConstants.FILE_OT);
+
+        idxFile[SwordConstants.TESTAMENT_NEW] = new File(path + File.separator + SwordConstants.FILE_NT + SwordConstants.EXTENSION_VSS);
+        txtFile[SwordConstants.TESTAMENT_NEW] = new File(path + File.separator + SwordConstants.FILE_NT);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.sword.AbstractBackend#readIndex()
+     */
+    /* @Override */
+    public Key readIndex()
+    {
+        // PENDING(joe): refactor to get rid of this
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
+     */
+    public final void activate(Lock lock)
+    {
+
+        URI path = null;
+        try
+        {
+            path = getExpandedDataPath();
+        }
+        catch (BookException e)
+        {
+            Reporter.informUser(this, e);
+            return;
+        }
+
         URI otPath = NetUtil.lengthenURI(path, File.separator + SwordConstants.FILE_OT);
         txtFile[SwordConstants.TESTAMENT_OLD] = new File(otPath.getPath());
         idxFile[SwordConstants.TESTAMENT_OLD] = new File(otPath.getPath() + SwordConstants.EXTENSION_VSS);
@@ -70,15 +156,10 @@
         // It is an error to be neither OT nor NT
         if (!txtFile[SwordConstants.TESTAMENT_OLD].canRead() && !txtFile[SwordConstants.TESTAMENT_NEW].canRead())
         {
-            throw new BookException(Msg.MISSING_FILE, new Object[] { path });
+            Reporter.informUser(this, new BookException(Msg.MISSING_FILE, new Object[] { path }));
+            return;
         }
-    }
 
-    /* (non-Javadoc)
-     * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
-     */
-    public final void activate(Lock lock)
-    {
         String fileMode = isWritable() ? FileUtil.MODE_WRITE : FileUtil.MODE_READ;
  
         if (idxFile[SwordConstants.TESTAMENT_OLD].canRead())
@@ -145,82 +226,6 @@
         active = false;
     }
 
-    /* (non-Javadoc)
-     * @see org.crosswire.jsword.book.sword.AbstractBackend#getRawText(org.crosswire.jsword.passage.Key, java.lang.String)
-     */
-    /* @Override */
-    public String getRawText(Key key) throws BookException
-    {
-        checkActive();
-        String charset = getBookMetaData().getBookCharset();
-
-        Verse verse = KeyUtil.getVerse(key);
-
-        try
-        {
-            int testament = SwordConstants.getTestament(verse);
-            long index = SwordConstants.getIndex(verse);
-
-            // If this is a single testament Bible, return nothing.
-            if (idxRaf[testament] == null)
-            {
-                return ""; //$NON-NLS-1$
-            }
-
-            int entrysize = datasize + OFFSETSIZE;
-
-            // Read the next entry size bytes.
-            byte[] read = SwordUtil.readRAF(idxRaf[testament], index * entrysize, entrysize);
-            if (read == null || read.length == 0)
-            {
-                return ""; //$NON-NLS-1$
-            }
-
-            // The data is little endian - extract the start and size
-            long start = SwordUtil.decodeLittleEndian32(read, 0);
-            int size = -1;
-            switch (datasize)
-            {
-            case 2:
-                size = SwordUtil.decodeLittleEndian16(read, 4);
-                break;
-            case 4:
-                size = SwordUtil.decodeLittleEndian32(read, 4);
-                break;
-            default:
-                assert false : datasize;
-            }
-
-            if (size < 0)
-            {
-                log.error("In " + getBookMetaData().getInitials() + ": Verse " + verse.getName() + " has a bad index size of " + size); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-            }
-
-            // Read from the data file.
-            // I wonder if it would be safe to do a readLine() from here.
-            // Probably be safer not to risk it since we know how long it is.
-            byte[] data = SwordUtil.readRAF(txtRaf[testament], start, size);
-
-            decipher(data);
-
-            return SwordUtil.decode(key.getName(), data, charset);
-        }
-        catch (IOException ex)
-        {
-            throw new BookException(UserMsg.READ_FAIL, ex, new Object[] { verse.getName() });
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.crosswire.jsword.book.sword.AbstractBackend#readIndex()
-     */
-    /* @Override */
-    public Key readIndex()
-    {
-        // PENDING(joe): refactor to get rid of this
-        return null;
-    }
-
     /**
      * Helper method so we can quickly activate ourselves on access
      */
@@ -232,33 +237,65 @@
         }
     }
 
-    /* (non-Javadoc)
-     * @see org.crosswire.jsword.book.sword.AbstractBackend#isWritable()
+    /**
+     * Get the Index (that is offset and size) for an entry.
+     * @param entry
+     * @return
+     * @throws IOException 
      */
-    public boolean isWritable()
+    private DataIndex getIndex(RandomAccessFile raf, long entry) throws IOException
     {
-        // For the module to be writable either the old testament or the new testament needs to be present
-        // (i.e. readable) and both the index and the data files need to be readable
-        if (idxFile[SwordConstants.TESTAMENT_OLD].canRead()
-            && (idxFile[SwordConstants.TESTAMENT_OLD].canWrite() || !txtFile[SwordConstants.TESTAMENT_OLD].canWrite()))
+        // Read the offset and size for this key from the index
+        byte[] buffer = SwordUtil.readRAF(raf, entry * entrysize, entrysize);
+        if (buffer == null || buffer.length == 0)
         {
-            return false;
+            return new DataIndex(0, 0);
         }
-        if (idxFile[SwordConstants.TESTAMENT_NEW].canRead()
-            && (idxFile[SwordConstants.TESTAMENT_NEW].canWrite() || !txtFile[SwordConstants.TESTAMENT_NEW].canWrite()))
+
+        int entryOffset = SwordUtil.decodeLittleEndian32(buffer, 0);
+        int entrySize = -1;
+        switch (datasize)
         {
-            return false;
+        case 2:
+            entrySize = SwordUtil.decodeLittleEndian16(buffer, 4);
+            break;
+        case 4:
+            entrySize = SwordUtil.decodeLittleEndian32(buffer, 4);
+            break;
+        default:
+            assert false : datasize;
         }
-        return idxFile[SwordConstants.TESTAMENT_OLD].canRead() || idxFile[SwordConstants.TESTAMENT_NEW].canRead();
+        return new DataIndex(entryOffset, entrySize);
     }
 
-    public void create(String path)
+    /**
+     * Get the text for an indexed entry in the book.
+     * 
+     * @param index the entry to get
+     * @return the text for the entry.
+     * @throws IOException 
+     */
+    private String getEntry(String name, int testament, long index) throws IOException
     {
-        idxFile[SwordConstants.TESTAMENT_OLD] = new File(path + File.separator + SwordConstants.FILE_OT + SwordConstants.EXTENSION_VSS);
-        txtFile[SwordConstants.TESTAMENT_OLD] = new File(path + File.separator + SwordConstants.FILE_OT);
+        DataIndex dataIndex = getIndex(idxRaf[testament], index);
 
-        idxFile[SwordConstants.TESTAMENT_NEW] = new File(path + File.separator + SwordConstants.FILE_NT + SwordConstants.EXTENSION_VSS);
-        txtFile[SwordConstants.TESTAMENT_NEW] = new File(path + File.separator + SwordConstants.FILE_NT);
+        int size = dataIndex.getSize();
+        if (size == 0)
+        {
+            return ""; //$NON-NLS-1$
+        }
+
+        if (size < 0)
+        {
+            log.error("In " + getBookMetaData().getInitials() + ": Verse " + name + " has a bad index size of " + size); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+            return ""; //$NON-NLS-1$
+        }
+
+        byte[] data = SwordUtil.readRAF(txtRaf[testament], dataIndex.getOffset(), size);
+
+        decipher(data);
+
+        return SwordUtil.decode(name, data, getBookMetaData().getBookCharset());
     }
 
     /**
@@ -267,6 +304,16 @@
     private boolean active;
 
     /**
+     * How many bytes in the size count in the index
+     */
+    private int datasize;
+
+    /**
+     * The number of bytes for each entry in the index: either 6 or 8
+     */
+    private int entrysize;
+
+    /**
      * The log stream
      */
     private static final Logger log = Logger.getLogger(RawBackend.class);
@@ -295,9 +342,4 @@
      * How many bytes in the offset pointers in the index
      */
     private static final int OFFSETSIZE = 4;
-
-    /**
-     * How many bytes in the size count in the index
-     */
-    private int datasize = -1;
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-04-10 21:18:07 UTC (rev 1793)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-04-11 10:48:41 UTC (rev 1794)
@@ -65,74 +65,53 @@
 
     }
 
-    /* (non-Javadoc)
-     * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
+    /**
+     * Get the number of entries in the Book.
+     * @return the number of entries in the Book
+     * @throws IOException 
      */
-    public final void activate(Lock lock)
+    public long getSize() throws IOException
     {
-        try
+        checkActive();
+        if (size == -1)
         {
-            URI path = null;
-            try
-            {
-                path = getExpandedDataPath();
-            }
-            catch (BookException e)
-            {
-                Reporter.informUser(this, e);
-                return;
-            }
-
-            idxFile = new File(path.getPath() + SwordConstants.EXTENSION_INDEX);
-            datFile = new File(path.getPath() + SwordConstants.EXTENSION_DATA);
-
-            if (!idxFile.canRead())
-            {
-                Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { idxFile.getAbsolutePath() }));
-                return;
-            }
-
-            if (!datFile.canRead())
-            {
-                Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { datFile.getAbsolutePath() }));
-                return;
-            }
-
-            // Open the files
-            idxRaf = new RandomAccessFile(idxFile, FileUtil.MODE_READ);
-            datRaf = new RandomAccessFile(datFile, FileUtil.MODE_READ);
+            size = idxRaf.length() / entrysize;
         }
-        catch (IOException ex)
-        {
-            log.error("failed to open files", ex); //$NON-NLS-1$
-
-            idxRaf = null;
-            datRaf = null;
-        }
-
-        active = true;
+        return size;
     }
 
-    /* (non-Javadoc)
-     * @see org.crosswire.common.activate.Activatable#deactivate(org.crosswire.common.activate.Lock)
+    /*
+     * (non-Javadoc)
+     * @see org.crosswire.jsword.book.sword.AbstractBackend#getRawText(org.crosswire.jsword.passage.Key, java.lang.String)
      */
-    public final void deactivate(Lock lock)
+    /* @Override */
+    public String getRawText(Key key) throws BookException
     {
+        return getRawText(key.getName());
+    }
+
+    public String getRawText(String key) throws BookException
+    {
+        checkActive();
+
         try
         {
-            idxRaf.close();
-            datRaf.close();
+            long pos = search(key);
+            if (pos >= 0)
+            {
+                DataEntry entry = getEntry(key, pos, true);
+                if (entry.isLinkEntry())
+                {
+                    return getRawText(entry.getLinkTarget());
+                }
+                return entry.getRawText();
+            }
+            throw new BookException(UserMsg.READ_FAIL);
         }
         catch (IOException ex)
         {
-            log.error("failed to close files", ex); //$NON-NLS-1$
+            throw new BookException(UserMsg.READ_FAIL, ex);
         }
-
-        idxRaf = null;
-        datRaf = null;
-        size   = -1;
-
-        active = false;
     }
 
     /* (non-Javadoc)
@@ -204,19 +183,85 @@
         return reply;
     }
 
+    /* (non-Javadoc)
+     * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
+     */
+    public final void activate(Lock lock)
+    {
+        try
+        {
+            URI path = null;
+            try
+            {
+                path = getExpandedDataPath();
+            }
+            catch (BookException e)
+            {
+                Reporter.informUser(this, e);
+                return;
+            }
+
+            idxFile = new File(path.getPath() + SwordConstants.EXTENSION_INDEX);
+            datFile = new File(path.getPath() + SwordConstants.EXTENSION_DATA);
+
+            if (!idxFile.canRead())
+            {
+                Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { idxFile.getAbsolutePath() }));
+                return;
+            }
+
+            if (!datFile.canRead())
+            {
+                Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { datFile.getAbsolutePath() }));
+                return;
+            }
+
+            // Open the files
+            idxRaf = new RandomAccessFile(idxFile, FileUtil.MODE_READ);
+            datRaf = new RandomAccessFile(datFile, FileUtil.MODE_READ);
+        }
+        catch (IOException ex)
+        {
+            log.error("failed to open files", ex); //$NON-NLS-1$
+
+            idxRaf = null;
+            datRaf = null;
+        }
+
+        active = true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.common.activate.Activatable#deactivate(org.crosswire.common.activate.Lock)
+     */
+    public final void deactivate(Lock lock)
+    {
+        try
+        {
+            idxRaf.close();
+            datRaf.close();
+        }
+        catch (IOException ex)
+        {
+            log.error("failed to close files", ex); //$NON-NLS-1$
+        }
+
+        idxRaf = null;
+        datRaf = null;
+        size   = -1;
+
+        active = false;
+    }
+
     /**
-     * Get the number of entries in the Book.
-     * @return the number of entries in the Book
-     * @throws IOException 
+     * Helper method so we can quickly activate ourselves on access
      */
-    public long getSize() throws IOException
+    protected final void checkActive()
     {
-        checkActive();
-        if (size == -1)
+        if (!active)
         {
-            size = idxRaf.length() / entrysize;
+            Activator.activate(this);
         }
-        return size;
     }
 
     /**
@@ -225,7 +270,7 @@
      * @return
      * @throws IOException 
      */
-    public DataIndex getIndex(long entry) throws IOException
+    private DataIndex getIndex(long entry) throws IOException
     {
         // Read the offset and size for this key from the index
         byte[] buffer = SwordUtil.readRAF(idxRaf, entry * entrysize, entrysize);
@@ -252,7 +297,7 @@
      * @return the text for the entry.
      * @throws IOException 
      */
-    public DataEntry getEntry(String reply, long index, boolean decipher) throws IOException
+    private DataEntry getEntry(String reply, long index, boolean decipher) throws IOException
     {
         DataIndex dataIndex = getIndex(index);
         // Now read the data file for this key using the offset and size
@@ -266,59 +311,6 @@
         return new DataEntry(reply, data, getBookMetaData().getBookCharset());
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.crosswire.jsword.book.sword.AbstractBackend#getRawText(org.crosswire.jsword.passage.Key, java.lang.String)
-     */
-    /* @Override */
-    public String getRawText(Key key) throws BookException
-    {
-        checkActive();
-
-        try
-        {
-            long pos = search(key.getName());
-            if (pos >= 0)
-            {
-                DataEntry entry = getEntry(key.getName(), pos, true);
-                if (entry.isLinkEntry())
-                {
-                    return getRawText(entry.getLinkTarget());
-                }
-                return entry.getRawText();
-            }
-            throw new BookException(UserMsg.READ_FAIL);
-        }
-        catch (IOException ex)
-        {
-            throw new BookException(UserMsg.READ_FAIL, ex);
-        }
-    }
-
-    public String getRawText(String key) throws BookException
-    {
-        checkActive();
-
-        try
-        {
-            long pos = search(key);
-            if (pos >= 0)
-            {
-                DataEntry entry = getEntry(key, pos, true);
-                if (entry.isLinkEntry())
-                {
-                    return getRawText(entry.getLinkTarget());
-                }
-                return entry.getRawText();
-            }
-            throw new BookException(UserMsg.READ_FAIL);
-        }
-        catch (IOException ex)
-        {
-            throw new BookException(UserMsg.READ_FAIL, ex);
-        }
-    }
-
     /**
      * Find a matching entry, returning it's index. Otherwise return < 0, such that
      * (-pos - 1) gives the insertion index.
@@ -397,17 +389,6 @@
     }
 
     /**
-     * Helper method so we can quickly activate ourselves on access
-     */
-    protected final void checkActive()
-    {
-        if (!active)
-        {
-            Activator.activate(this);
-        }
-    }
-
-    /**
      * How many bytes in the offset pointers in the index
      */
     private static final int OFFSETSIZE = 4;

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java	2008-04-10 21:18:07 UTC (rev 1793)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKeyIndex.java	2008-04-11 10:48:41 UTC (rev 1794)
@@ -32,6 +32,7 @@
 import org.crosswire.common.util.FileUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
+import org.crosswire.common.util.Reporter;
 import org.crosswire.jsword.book.BookException;
 import org.crosswire.jsword.passage.DefaultKeyList;
 import org.crosswire.jsword.passage.Key;
@@ -52,25 +53,9 @@
      * Simple ctor
      * @throws BookException
      */
-    public TreeKeyIndex(SwordBookMetaData sbmd) throws BookException
+    public TreeKeyIndex(SwordBookMetaData sbmd)
     {
         bmd = sbmd;
-
-        String path = getExpandedDataPath();
-
-        idxFile = new File(path + EXTENSION_INDEX);
-        datFile = new File(path + EXTENSION_DATA);
-
-        if (!idxFile.canRead())
-        {
-            throw new BookException(UserMsg.READ_FAIL, new Object[] { idxFile.getAbsolutePath() });
-        }
-
-        if (!datFile.canRead())
-        {
-            throw new BookException(UserMsg.READ_FAIL, new Object[] { datFile.getAbsolutePath() });
-        }
-
     }
 
     /**
@@ -180,8 +165,34 @@
      */
     public final void activate(Lock lock)
     {
+        String path = null;
         try
         {
+            path = getExpandedDataPath();
+        }
+        catch (BookException e)
+        {
+            Reporter.informUser(this, e);
+            return;
+        }
+
+        idxFile = new File(path + EXTENSION_INDEX);
+        datFile = new File(path + EXTENSION_DATA);
+
+        if (!idxFile.canRead())
+        {
+            Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { idxFile.getAbsolutePath() }));
+            return;
+        }
+
+        if (!datFile.canRead())
+        {
+            Reporter.informUser(this, new BookException(UserMsg.READ_FAIL, new Object[] { datFile.getAbsolutePath() }));
+            return;
+        }
+
+        try
+        {
             idxRaf = new RandomAccessFile(idxFile, FileUtil.MODE_READ);
             datRaf = new RandomAccessFile(datFile, FileUtil.MODE_READ);
         }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2008-04-10 21:18:07 UTC (rev 1793)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java	2008-04-11 10:48:41 UTC (rev 1794)
@@ -99,7 +99,7 @@
      * Simple ctor
      * @throws BookException
      */
-    public ZLDBackend(SwordBookMetaData sbmd) throws BookException
+    public ZLDBackend(SwordBookMetaData sbmd)
     {
         super(sbmd);
 




More information about the jsword-svn mailing list