summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-07-28 11:45:21 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-07 11:17:50 (GMT)
commiteca0a80a7abb136094f252872499c59803999f85 (patch)
treed81af1e61d3b05567acc05199425829fc33320c8
parent0b55e5cf189e61d1dafbc011ee853d74509604d8 (diff)
downloadstroke-eca0a80a7abb136094f252872499c59803999f85.zip
stroke-eca0a80a7abb136094f252872499c59803999f85.tar.bz2
Using JZlib for compression, as features we need aren't in Java until 1.7
-rw-r--r--.gitignore1
-rw-r--r--Makefile28
-rw-r--r--README7
-rw-r--r--build-jzlib.xml32
-rw-r--r--build.xml2
-rw-r--r--src/com/isode/stroke/base/ByteArray.java9
-rw-r--r--src/com/isode/stroke/compress/ZLibCodecompressor.java44
-rw-r--r--src/com/isode/stroke/compress/ZLibCompressor.java36
-rw-r--r--src/com/isode/stroke/compress/ZLibDecompressor.java39
9 files changed, 149 insertions, 49 deletions
diff --git a/.gitignore b/.gitignore
index a89e539..d1c3d14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,5 +10,6 @@ isode/config.log
isode/config.status
isode/configure
test-results/
+third-party/
*.patch
.DS_Store \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..85de348
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+all: dist/lib/stroke.jar
+
+.PHONY : clean
+clean:
+ ant clean
+
+.PHONY : distclean
+distclean: clean
+ ant distclean
+ rm -rf third-party
+
+.PHONY : dist/lib/stroke.jar
+dist/lib/stroke.jar: third-party/xpp/xpp.jar third-party/jzlib/jzlib.jar
+ ant -Dxpp-dir=third-party/xpp -Djzlib-dir=third-party/jzlib
+
+third-party/xpp/xpp.jar: third-party
+ mkdir -p third-party/xpp
+ curl http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3-1.1.4c.jar -o third-party/xpp/xpp.jar
+
+third-party/jzlib/jzlib.jar: third-party
+ curl http://www.jcraft.com/jzlib/jzlib-1.0.7.tar.gz -o third-party/jzlib-1.0.7.tar.gz
+ tar -xvzf third-party/jzlib-1.0.7.tar.gz -C third-party/
+ mv third-party/jzlib-1.0.7 third-party/jzlib
+ cp build-jzlib.xml third-party/jzlib/build.xml
+ ant -f third-party/jzlib/build.xml
+
+third-party:
+ mkdir -p third-party \ No newline at end of file
diff --git a/README b/README
index 115735e..185d10a 100644
--- a/README
+++ b/README
@@ -5,6 +5,11 @@ The source is available from the Git repository at http://swift.im/git/stroke/
It depends on the XmlPullParser from http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/index.html. This is passed to Ant in the xpp-dir parameter. The passed folder should contain the XPP jar called xpp.jar (i.e. with no version numbering in the filename).
+It also depends upon http://www.jcraft.com/jzlib/, which is passed to ant in the jzlib-dir parameter. The passed folder should contain a jar called jzlib.jar.
+
To build, run:
-ant -Dxpp-dir=path/to/directory/containing/xpp
+ant -Dxpp-dir=path/to/directory/containing/xpp -Djzlib-dir=path/to/directory/containing/jzlib
+
+Easy version:
+The included Makefile should, on Unixes with make/curl installed, grab the dependencies (once only) and build. \ No newline at end of file
diff --git a/build-jzlib.xml b/build-jzlib.xml
new file mode 100644
index 0000000..31eeeea
--- /dev/null
+++ b/build-jzlib.xml
@@ -0,0 +1,32 @@
+<!--
+ * Copyright (c) 2010, Isode Limited, London, England.
+ * All rights reserved.
+ -->
+<project name="jzlib" default="dist" basedir=".">
+ <description>
+ Java zlib
+ </description>
+ <property name="src" location="com"/>
+ <property name="build" location="build"/>
+ <property name="dist" location="."/>
+ <property name="jar" value="${dist}/jzlib.jar"/>
+ <property name="compile.debug" value="true"/>
+
+ <target name="init">
+ <tstamp/>
+ <mkdir dir="${build}"/>
+ </target>
+
+ <target name="compile" depends="init"
+ description="compile the source " >
+ <javac srcdir="${src}" destdir="${build}" debug="${compile.debug}"/>
+ </target>
+
+ <target name="dist" depends="compile"
+ description="generate the distribution" >
+ <mkdir dir="${dist}"/>
+
+ <jar jarfile="${jar}" basedir="${build}"/>
+ </target>
+
+</project>
diff --git a/build.xml b/build.xml
index 4114302..709f20e 100644
--- a/build.xml
+++ b/build.xml
@@ -17,9 +17,11 @@
<property name="compile.debug" value="true"/>
<property name="testsuiteclass" value="com.isode.stroke.unittest.StrokeTestSuite" />
<property name="xpp-dir" value="../third-party/xpp"/>
+ <property name="jzlib-dir" value="third-party/jzlib"/>
<path id="classpath">
<fileset dir="${xpp-dir}" includes="xpp.jar"/>
+ <fileset dir="${jzlib-dir}" includes="jzlib.jar"/>
</path>
<target name="init">
<tstamp/>
diff --git a/src/com/isode/stroke/base/ByteArray.java b/src/com/isode/stroke/base/ByteArray.java
index 8b140ed..077c58c 100644
--- a/src/com/isode/stroke/base/ByteArray.java
+++ b/src/com/isode/stroke/base/ByteArray.java
@@ -149,8 +149,13 @@ public class ByteArray {
*
* @return a reference to the updated object
*/
- private ByteArray append(byte[] b) {
- for (int i = 0; i < b.length; i++) {
+ public ByteArray append(byte[] b) {
+ return append(b, b.length);
+ }
+
+ /** Mutable add */
+ public ByteArray append(byte[] b, int len) {
+ for (int i = 0; i < len; i++) {
append(b[i]);
}
return this;
diff --git a/src/com/isode/stroke/compress/ZLibCodecompressor.java b/src/com/isode/stroke/compress/ZLibCodecompressor.java
new file mode 100644
index 0000000..5f04442
--- /dev/null
+++ b/src/com/isode/stroke/compress/ZLibCodecompressor.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2010 Remko Tron¨on
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+/*
+ * Copyright (c) 2011, Isode Limited, London, England.
+ * All rights reserved.
+ */
+package com.isode.stroke.compress;
+
+import com.isode.stroke.base.ByteArray;
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZStream;
+
+public abstract class ZLibCodecompressor {
+ protected final int CHUNK_SIZE = 1024;
+ protected final ZStream stream_ = new ZStream();
+
+ public ByteArray process(ByteArray input) throws ZLibException {
+ ByteArray output = new ByteArray();
+ stream_.avail_in = input.getSize();
+ stream_.next_in = input.getData();
+ stream_.next_in_index = 0;
+ do {
+ byte[] outputArray = new byte[CHUNK_SIZE];
+ stream_.avail_out = CHUNK_SIZE;
+ stream_.next_out = outputArray;
+ stream_.next_out_index = 0;
+ int result = processZStream();
+ if (result != JZlib.Z_OK && result != JZlib.Z_BUF_ERROR) {
+ throw new ZLibException(/* stream_.msg */);
+ }
+ output.append(outputArray, CHUNK_SIZE - stream_.avail_out);
+ }
+ while (stream_.avail_out == 0);
+ if (stream_.avail_in != 0) {
+ throw new ZLibException();
+ }
+ return output;
+ }
+
+ protected abstract int processZStream();
+}
diff --git a/src/com/isode/stroke/compress/ZLibCompressor.java b/src/com/isode/stroke/compress/ZLibCompressor.java
index f5276c8..de22bee 100644
--- a/src/com/isode/stroke/compress/ZLibCompressor.java
+++ b/src/com/isode/stroke/compress/ZLibCompressor.java
@@ -1,33 +1,27 @@
/*
+ * Copyright (c) 2010 Remko Tron¨on
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+/*
* Copyright (c) 2011, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.compress;
-import com.isode.stroke.base.ByteArray;
-import java.util.zip.Deflater;
+import com.jcraft.jzlib.JZlib;
-/**
- *
- * @author Kev
- */
-public class ZLibCompressor {
+public class ZLibCompressor extends ZLibCodecompressor {
private static final int COMPRESSION_LEVEL = 9;
+
+
+ public ZLibCompressor() {
+ int result = stream_.deflateInit(COMPRESSION_LEVEL);
+ assert (result == JZlib.Z_OK);
+ }
- public ByteArray process(ByteArray data) throws ZLibException {
- Deflater compressor = new Deflater(COMPRESSION_LEVEL);
- compressor.setStrategy(Deflater.DEFAULT_STRATEGY);
- compressor.setInput(data.getData());
- compressor.finish();
- byte[] output = new byte[100];
- ByteArray result = new ByteArray();
- while (!compressor.finished()) {
- int size = compressor.deflate(output);
- for (int i = 0; i < size; i++) {
- result.append(output[i]); /* TODO: Terribly slow */
- }
- }
- return result;
+ protected int processZStream() {
+ return stream_.deflate(JZlib.Z_SYNC_FLUSH);
}
}
diff --git a/src/com/isode/stroke/compress/ZLibDecompressor.java b/src/com/isode/stroke/compress/ZLibDecompressor.java
index 2c78a57..82b9035 100644
--- a/src/com/isode/stroke/compress/ZLibDecompressor.java
+++ b/src/com/isode/stroke/compress/ZLibDecompressor.java
@@ -1,35 +1,24 @@
/*
+ * Copyright (c) 2010 Remko Tron¨on
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+/*
* Copyright (c) 2011, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.compress;
-import com.isode.stroke.base.ByteArray;
-import java.util.zip.DataFormatException;
-import java.util.zip.Inflater;
+import com.jcraft.jzlib.JZlib;
-/**
- *
- * @author Kev
- */
-public class ZLibDecompressor {
- Inflater inflater_ = new Inflater();
- public ByteArray process(ByteArray data) throws ZLibException {
- try {
- inflater_.setInput(data.getData());
- byte[] output = new byte[100];
- ByteArray result = new ByteArray();
- int size = 0;
- while ((size = inflater_.inflate(output)) != 0) {
- for (int i = 0; i < size; i++) {
- result.append(output[i]); /* TODO: Terribly slow */
- }
- }
- return result;
- }
- catch (DataFormatException e) {
- throw new ZLibException();
- }
+public class ZLibDecompressor extends ZLibCodecompressor {
+
+ public ZLibDecompressor() {
+ int result = stream_.inflateInit();
+ assert (result == JZlib.Z_OK);
}
+ protected int processZStream() {
+ return stream_.inflate(JZlib.Z_SYNC_FLUSH);
+ }
}