[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/sword s
jswordcvs at crosswire.org
jswordcvs at crosswire.org
Mon Apr 18 15:10:40 MST 2005
Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword
In directory www.crosswire.org:/tmp/cvs-serv24079/java/jsword/org/crosswire/jsword/book/sword
Modified Files:
RawLDBackend.java GZIPBackend.java SwordUtil.java
SwordConstants.java RawBackend.java
Log Message:
Gen 12 bug fix and minor optimization.
Index: RawBackend.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/RawBackend.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** RawBackend.java 6 Mar 2005 20:21:47 -0000 1.22
--- RawBackend.java 18 Apr 2005 22:10:38 -0000 1.23
***************
*** 133,137 ****
{
int testament = SwordConstants.getTestament(verse);
! long index = SwordConstants.getIndex(verse);
// If this is a single testament Bible, return nothing.
--- 133,137 ----
{
int testament = SwordConstants.getTestament(verse);
! int index = SwordConstants.getIndex(verse);
// If this is a single testament Bible, return nothing.
***************
*** 149,155 ****
// The data is little endian - extract the start and size
! long start = SwordUtil.decodeLittleEndian32(read, 0);
int size = SwordUtil.decodeLittleEndian16(read, 4);
// Read from the data file.
// I wonder if it would be safe to do a readLine() from here.
--- 149,160 ----
// The data is little endian - extract the start and size
! int start = SwordUtil.decodeLittleEndian32(read, 0);
int size = SwordUtil.decodeLittleEndian16(read, 4);
+ if (size < 1)
+ {
+ log.error("Verse " + verse.getName() + " has a bad index size of " + size); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
// Read from the data file.
// I wonder if it would be safe to do a readLine() from here.
Index: GZIPBackend.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/GZIPBackend.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** GZIPBackend.java 18 Mar 2005 15:43:51 -0000 1.30
--- GZIPBackend.java 18 Apr 2005 22:10:38 -0000 1.31
***************
*** 220,224 ****
{
int testament = SwordConstants.getTestament(verse);
! long index = SwordConstants.getIndex(verse);
// If Bible does not contain the desired testament, return nothing.
--- 220,224 ----
{
int testament = SwordConstants.getTestament(verse);
! int index = SwordConstants.getIndex(verse);
// If Bible does not contain the desired testament, return nothing.
***************
*** 240,245 ****
// The data is little endian - extract the blockNum, verseStart and verseSize
! int blockNum = SwordUtil.decodeLittleEndian32AsInt(temp, 0);
! int verseStart = SwordUtil.decodeLittleEndian32AsInt(temp, 4);
int verseSize = SwordUtil.decodeLittleEndian16(temp, 8);
--- 240,245 ----
// The data is little endian - extract the blockNum, verseStart and verseSize
! int blockNum = SwordUtil.decodeLittleEndian32(temp, 0);
! int verseStart = SwordUtil.decodeLittleEndian32(temp, 4);
int verseSize = SwordUtil.decodeLittleEndian16(temp, 8);
***************
*** 259,265 ****
}
! long blockStart = SwordUtil.decodeLittleEndian32(temp, 0);
! int blockSize = SwordUtil.decodeLittleEndian32AsInt(temp, 4);
! int uncompressedSize = SwordUtil.decodeLittleEndian32AsInt(temp, 8);
// Read from the data file.
--- 259,265 ----
}
! int blockStart = SwordUtil.decodeLittleEndian32(temp, 0);
! int blockSize = SwordUtil.decodeLittleEndian32(temp, 4);
! int uncompressedSize = SwordUtil.decodeLittleEndian32(temp, 8);
// Read from the data file.
Index: SwordConstants.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/SwordConstants.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** SwordConstants.java 5 Apr 2005 00:33:40 -0000 1.29
--- SwordConstants.java 18 Apr 2005 22:10:38 -0000 1.30
***************
*** 113,117 ****
* Get the sword index of the given verse
*/
! static long getIndex(Verse v)
{
int ord = v.getOrdinal();
--- 113,117 ----
* Get the sword index of the given verse
*/
! static int getIndex(Verse v)
{
int ord = v.getOrdinal();
***************
*** 133,138 ****
}
! int bookOffset = SwordConstants.bks[testament][book];
! long chapOffset = SwordConstants.cps[testament][bookOffset + chapter];
return verse + chapOffset;
--- 133,138 ----
}
! short bookOffset = SwordConstants.bks[testament][book];
! short chapOffset = SwordConstants.cps[testament][bookOffset + chapter];
return verse + chapOffset;
***************
*** 160,163 ****
--- 160,171 ----
* initialise our LUTs with data shamelessly stolen from our sister project (Sword)
* taken from canon.h.
+ *
+ * The basic feature of an index is that starting at 4 for Gen 1.1 and Mat 1.1,
+ * increment 1 for each subsequent verse. At a chapter boundary, skip 1. At a book
+ * boundary skip 1 for the book and 1 for the chapter.
+ *
+ * Book 0.0 gives the index for the book's info. ( == index of Book 1.1 - 2)
+ * Book ch.0 gives the index for the chapter's info in the book. ( == index of Book 1.1 - 1)
+ *
* There are arrays of data like this in BibleInfo. I guess we could merge
* them at some stage.
***************
*** 195,199 ****
0, 2, 3, 35, 61, 86,
113, 146, 169, 194, 217, 247, 280,
! 413, 334, 353, 378, 400, 417, 445,
479, 518, 537, 572, 597, 618, 686,
721, 757, 804, 827, 863, 907, 963,
--- 203,207 ----
0, 2, 3, 35, 61, 86,
113, 146, 169, 194, 217, 247, 280,
! 313, 334, 353, 378, 400, 417, 445,
479, 518, 537, 572, 597, 618, 686,
721, 757, 804, 827, 863, 907, 963,
Index: SwordUtil.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/SwordUtil.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** SwordUtil.java 14 Apr 2005 01:27:43 -0000 1.17
--- SwordUtil.java 18 Apr 2005 22:10:38 -0000 1.18
***************
*** 52,56 ****
* @return the read data
*/
! protected static byte[] readRAF(RandomAccessFile raf, long offset, int size) throws IOException
{
if (offset + size > raf.length())
--- 52,56 ----
* @return the read data
*/
! protected static byte[] readRAF(RandomAccessFile raf, int offset, int size) throws IOException
{
if (offset + size > raf.length())
***************
*** 62,66 ****
if (size < 1)
{
! DataPolice.report("Nothing to read returning empty because size=" + size); //$NON-NLS-1$
return new byte[0];
}
--- 62,66 ----
if (size < 1)
{
! DataPolice.report("Nothing to read at offset = " + offset + " returning empty because size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
return new byte[0];
}
***************
*** 74,83 ****
/**
! * Decode little endian data from a byte array
* @param data the byte[] from which to read 4 bytes
* @param offset the offset into the array
* @return The decoded data
*/
! protected static long decodeLittleEndian32(byte[] data, int offset)
{
// long byte1 = SwordUtil.un2complement(data[0 + offset]);
--- 74,86 ----
/**
! * Decode little endian data from a byte array.
! * This assumes that the high order bit is not set as this is used solely
! * for an offset in a file in bytes. For a practical limit, 2**31 is way
! * bigger than any document that we can have.
* @param data the byte[] from which to read 4 bytes
* @param offset the offset into the array
* @return The decoded data
*/
! protected static int decodeLittleEndian32(byte[] data, int offset)
{
// long byte1 = SwordUtil.un2complement(data[0 + offset]);
***************
*** 87,94 ****
// Convert from a byte to an int, but prevent sign extension.
// So -16 becomes 240
! long byte1 = data[0 + offset] & 0xFF;
! long byte2 = (data[1 + offset] & 0xFF) << 8;
! long byte3 = (data[2 + offset] & 0xFF) << 16;
! long byte4 = (data[3 + offset] & 0xFF) << 24;
return byte4 | byte3 | byte2 | byte1;
--- 90,97 ----
// Convert from a byte to an int, but prevent sign extension.
// So -16 becomes 240
! int byte1 = data[0 + offset] & 0xFF;
! int byte2 = (data[1 + offset] & 0xFF) << 8;
! int byte3 = (data[2 + offset] & 0xFF) << 16;
! int byte4 = (data[3 + offset] & 0xFF) << 24;
return byte4 | byte3 | byte2 | byte1;
***************
*** 101,122 ****
* @return The decoded data
*/
- protected static int decodeLittleEndian32AsInt(byte[] data, int offset)
- {
- long result = decodeLittleEndian32(data, offset);
-
- if (result > Integer.MAX_VALUE)
- {
- log.warn("loss of precision converting to integer from " + result + " to " + ((int) result)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- return (int) result;
- }
-
- /**
- * Decode little endian data from a byte array
- * @param data the byte[] from which to read 4 bytes
- * @param offset the offset into the array
- * @return The decoded data
- */
protected static int decodeLittleEndian16(byte[] data, int offset)
{
--- 104,107 ----
***************
*** 132,143 ****
/**
- * Un 2-s complement a byte
- */
- protected static int un2complement(byte data)
- {
- return data & 0xFF; //>= 0 ? data : 256 + data;
- }
-
- /**
* Find a byte of data in an array
* @param data The array to search
--- 117,120 ----
Index: RawLDBackend.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/sword/RawLDBackend.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** RawLDBackend.java 1 Apr 2005 17:09:46 -0000 1.16
--- RawLDBackend.java 18 Apr 2005 22:10:38 -0000 1.17
***************
*** 145,149 ****
// Read the offset and size for this key from the index
byte[] buffer = SwordUtil.readRAF(idxRaf, entry * entrysize, entrysize);
! long offset = SwordUtil.decodeLittleEndian32(buffer, 0);
int size = -1;
switch (datasize)
--- 145,149 ----
// Read the offset and size for this key from the index
byte[] buffer = SwordUtil.readRAF(idxRaf, entry * entrysize, entrysize);
! int offset = SwordUtil.decodeLittleEndian32(buffer, 0);
int size = -1;
switch (datasize)
***************
*** 153,157 ****
break;
case 4:
! size = SwordUtil.decodeLittleEndian32AsInt(buffer, 4);
break;
default:
--- 153,157 ----
break;
case 4:
! size = SwordUtil.decodeLittleEndian32(buffer, 4);
break;
default:
***************
*** 305,309 ****
* Setup with the key name and positions of data in the file
*/
! protected IndexKey(String text, long offset, int size, Key parent)
{
super(text, text, parent);
--- 305,309 ----
* Setup with the key name and positions of data in the file
*/
! protected IndexKey(String text, int offset, int size, Key parent)
{
super(text, text, parent);
***************
*** 321,325 ****
}
! protected long offset;
protected int size;
}
--- 321,325 ----
}
! protected int offset;
protected int size;
}
More information about the jsword-svn
mailing list