[jsword-svn] r1359 - in trunk: jsword jsword/src/main/java/org/crosswire/jsword/book/sword jsword-web
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Wed May 30 13:05:37 MST 2007
Author: dmsmith
Date: 2007-05-30 13:05:37 -0700 (Wed, 30 May 2007)
New Revision: 1359
Modified:
trunk/jsword-web/
trunk/jsword/
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GZIPBackend.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java
Log:
Changed properties.
Modified JSword to use new common...compress code.
Property changes on: trunk/jsword
___________________________________________________________________
Name: svn:ignore
- tmp.ser
jsword.keystore
.build.xml.swp
buildlog.txt
jcoverage.ser
target
jsword.cfg
jsword.saj
jsword.qsp
bin
+ buildlog.txt
target
bin
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GZIPBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GZIPBackend.java 2007-05-30 20:04:20 UTC (rev 1358)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GZIPBackend.java 2007-05-30 20:05:37 UTC (rev 1359)
@@ -25,10 +25,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
-import java.util.zip.DataFormatException;
import org.crosswire.common.activate.Activator;
import org.crosswire.common.activate.Lock;
+import org.crosswire.common.compress.CompressorType;
import org.crosswire.common.util.FileUtil;
import org.crosswire.common.util.Logger;
import org.crosswire.jsword.book.BookException;
@@ -37,8 +37,8 @@
import org.crosswire.jsword.passage.Verse;
/**
- * A backend to read GZIPped data files. While the text file contains
- * data compressed with GZIP, it cannot be uncompressed using a stand
+ * A backend to read compressed data verse based files. While the text file contains
+ * data compressed with ZIP or LZSS, it cannot be uncompressed using a stand
* alone zip utility, such as WinZip or gzip. The reason for this is
* that the data file is a concatenation of blocks of compressed data.
*
@@ -47,25 +47,25 @@
* to uncompress a block into memory. Having it at the book level is
* very memory expensive. Having it at the verse level is very disk
* expensive, but takes the least amount of memory. The most common is
- * chapter.
+ * chapter.</p>
*
* <p>In order to find the data in the text file, we need to find the
* block. The first index (comp) is used for this. Each verse is indexed
* to a tuple (block number, verse start, verse size). This data allows
* us to find the correct block, and to extract the verse from the
- * uncompressed block, but it does not help us uncompress the block.
+ * uncompressed block, but it does not help us uncompress the block.</p>
*
* <p>Once the block is known, then the next index (idx) gives the location
- * of the compressed block, its compressed size and its uncompressed size.
+ * of the compressed block, its compressed size and its uncompressed size.</p>
*
* <p>There are 3 files for each testament, 2 (comp and idx) are indexes into
* the third (text) which contains the data. The key into each index is the
* verse index within that testament, which is determined by book, chapter
- * and verse of that key.
+ * and verse of that key.</p>
*
- * <p>All numbers are stored 2-complement, little endian.
+ * <p>All numbers are stored 2-complement, little endian.</p>
* <p>Then proceed as follows, at all times working on the set of files for the
- * testament in question:
+ * testament in question:</p>
*
* <pre>
* in the comp file, seek to the index * 10
@@ -81,7 +81,7 @@
*
* in the text file seek to the text-block-index
* read data-size bytes
- * //decipher them if they are encrypted
+ * decipher them if they are encrypted
* unGZIP them into a byte array of uncompressed-size
* </pre>
*
@@ -227,7 +227,9 @@
{
checkActive();
- String charset = getBookMetaData().getBookCharset();
+ SwordBookMetaData sbmd = getBookMetaData();
+ String charset = sbmd.getBookCharset();
+ String compressType = sbmd.getProperty(ConfigEntryType.COMPRESS_TYPE);
Verse verse = KeyUtil.getVerse(key);
@@ -282,7 +284,7 @@
decipher(data);
- uncompressed = SwordUtil.uncompress(data, uncompressedSize);
+ uncompressed = CompressorType.fromString(compressType).getCompressor(data).uncompress(uncompressedSize);
// cache the uncompressed data for next time
lastBlockNum = blockNum;
@@ -295,44 +297,11 @@
System.arraycopy(uncompressed, verseStart, chopped, 0, verseSize);
return SwordUtil.decode(key, chopped, charset);
-
- /* The code converted from Sword looked like this, but we can do better
- // buffer number
- comp_raf[testament].seek(offset);
- long buffernum = comp_raf[testament - 1].readInt();
- buffernum = swordtoarch32(buffernum);
-
- // verse offset within buffer
- // long versestart =
- comp_raf[testament - 1].readInt();
- // versestart = swordtoarch32(versestart);
- // short versesize =
- comp_raf[testament - 1].readShort();
- //versesize = swordtoarch16(versesize);
-
- idx_raf[testament].seek(buffernum * 12);
-
- // compressed buffer start
- long start = idx_raf[testament - 1].readInt();
- start = swordtoarch32(start);
-
- // buffer size compressed (was long but can't use long as array index)
- int size = idx_raf[testament - 1].readInt();
- size = swordtoarch32(size);
-
- // buffer size uncompressed (was long but can't use long as array index)
- int endsize = idx_raf[testament - 1].readInt();
- endsize = swordtoarch32(endsize);
- /**/
}
catch (IOException e)
{
throw new BookException(Msg.READ_FAIL, e, new Object[] { verse.getName() });
}
- catch (DataFormatException e)
- {
- throw new BookException(Msg.READ_FAIL, e, new Object[] { verse.getName() });
- }
}
/* (non-Javadoc)
@@ -392,7 +361,7 @@
private RandomAccessFile[] textRaf = new RandomAccessFile[3];
/**
- * The array of compressed random access files?
+ * The array of compressed random access files
*/
private RandomAccessFile[] compRaf = new RandomAccessFile[3];
@@ -407,7 +376,7 @@
private File[] textFile = new File[3];
/**
- * The array of compressed random access files?
+ * The array of compressed random access files
*/
private File[] compFile = new File[3];
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java 2007-05-30 20:04:20 UTC (rev 1358)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordUtil.java 2007-05-30 20:05:37 UTC (rev 1359)
@@ -21,18 +21,11 @@
*/
package org.crosswire.jsword.book.sword;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
-import java.util.zip.DataFormatException;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterInputStream;
import org.crosswire.common.util.Logger;
-import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.book.DataPolice;
import org.crosswire.jsword.passage.Key;
@@ -195,56 +188,6 @@
}
/**
- * Uncompress a block of (G)ZIP compressed data
- * @param compressed The data to uncompress
- * @param endsize The expected resultant data size
- * @return The uncompressed data
- */
- public static byte[] uncompress(byte[] compressed, int endsize) throws DataFormatException, BookException
- {
- // Create the decompressor and give it the data to compress
- Inflater decompressor = new Inflater();
- decompressor.setInput(compressed);
-
- // Decompress the data
- byte[] uncompressed = new byte[endsize];
- int realendsize = decompressor.inflate(uncompressed);
-
- if (!decompressor.finished() || realendsize != endsize)
- {
- throw new BookException(Msg.GZIP_FORMAT);
- }
-
- return uncompressed;
- }
-
- /**
- * Uncompress a block of (G)ZIP compressed data,
- * when the resulting size is not known.
- *
- * @param compressed The data to uncompress
- * @return The uncompressed data
- * @throws IOException
- */
- public static byte[] uncompress(byte[] compressed) throws IOException
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- BufferedOutputStream out = new BufferedOutputStream(bos, ZBUF_SIZE);
- ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
- InflaterInputStream in = new InflaterInputStream(bis, new Inflater(), ZBUF_SIZE);
- byte[] buf = new byte[ZBUF_SIZE];
-
- for (int count = in.read(buf); count != -1; count = in.read(buf))
- {
- out.write(buf, 0, count);
- }
- in.close();
- out.flush();
- out.close();
- return bos.toByteArray();
- }
-
- /**
* Transform a byte array into a string given the encoding.
* If the encoding is bad then it just does it as a string.
* @param data The byte array to be converted
@@ -321,9 +264,4 @@
* The log stream
*/
private static final Logger log = Logger.getLogger(SwordUtil.class);
-
- /**
- * The size to read/write when unzipping a compressed byte array of unknown size.
- */
- private static final int ZBUF_SIZE = 2048;
}
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 2007-05-30 20:04:20 UTC (rev 1358)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ZLDBackend.java 2007-05-30 20:05:37 UTC (rev 1359)
@@ -30,6 +30,7 @@
import org.crosswire.common.activate.Activator;
import org.crosswire.common.activate.Lock;
+import org.crosswire.common.compress.CompressorType;
import org.crosswire.common.util.ClassUtil;
import org.crosswire.common.util.FileUtil;
import org.crosswire.common.util.Logger;
@@ -291,8 +292,11 @@
public String getRawText(Key key) throws BookException
{
checkActive();
- String charset = getBookMetaData().getBookCharset();
+ SwordBookMetaData sbmd = getBookMetaData();
+ String charset = sbmd.getBookCharset();
+ String compressType = sbmd.getProperty(ConfigEntryType.COMPRESS_TYPE);
+
if (!(key instanceof IndexKey))
{
throw new BookException(Msg.BAD_KEY, new Object[] { ClassUtil.getShortClassName(key.getClass()), key.getName() });
@@ -347,7 +351,7 @@
decipher(temp);
- uncompressed = SwordUtil.uncompress(temp);
+ uncompressed = CompressorType.fromString(compressType).getCompressor(temp).uncompress();
// cache the uncompressed data for next time
lastBlockNum = blockNum;
Property changes on: trunk/jsword-web
___________________________________________________________________
Name: svn:ignore
- target
*jcoverage.ser
junit*.properties
jcoverage.log
bin
+ target
bin
More information about the jsword-svn
mailing list