summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkitfox2007-07-18 17:54:46 +0200
committerkitfox2007-07-18 17:54:46 +0200
commit16d8eb9f09b92887d743f114455329811d7ee960 (patch)
treefce126ff8ba08d16bbff1e09ae773d77b8f66006
parentPartially added inflationi of zipped files. (diff)
downloadsvg-salamander-core-16d8eb9f09b92887d743f114455329811d7ee960.tar.gz
svg-salamander-core-16d8eb9f09b92887d743f114455329811d7ee960.tar.xz
svg-salamander-core-16d8eb9f09b92887d743f114455329811d7ee960.zip
Added parsing of gzipped svg files.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@41 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r--hotspot.log25
-rw-r--r--src/main/java/com/kitfox/svg/SVGUniverse.java33
-rw-r--r--src/test/java/com/kitfox/svg/zip/ZipTestMain.java76
-rw-r--r--src/test/res/missing.svgzbin0 -> 15968 bytes
4 files changed, 114 insertions, 20 deletions
diff --git a/hotspot.log b/hotspot.log
new file mode 100644
index 0000000..ce1ff2f
--- /dev/null
+++ b/hotspot.log
@@ -0,0 +1,25 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<hotspot_log version='160 1' process='3344' time_ms='1184734480014'>
+<vm_version>
+<name>
+Java HotSpot(TM) Client VM
+</name>
+<release>
+1.6.0-rc-fastdebug-b99-debug
+</release>
+<info>
+Java HotSpot(TM) Client VM (1.6.0-rc-fastdebug-b99) for windows-x86, built on Sep 15 2006 02:26:51 by &quot;java_re&quot; with unknown MS VC++:1310
+</info>
+</vm_version>
+<vm_arguments>
+<args>
+-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,address=localhost:4663
+</args>
+<command>
+com.kitfox.svg.zip.ZipTestMain
+</command>
+<launcher>
+SUN_STANDARD
+</launcher>
+</vm_arguments>
+<tty>
diff --git a/src/main/java/com/kitfox/svg/SVGUniverse.java b/src/main/java/com/kitfox/svg/SVGUniverse.java
index ac285dd..13c8988 100644
--- a/src/main/java/com/kitfox/svg/SVGUniverse.java
+++ b/src/main/java/com/kitfox/svg/SVGUniverse.java
@@ -50,8 +50,7 @@ import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.HashMap;
import java.util.Iterator;
-
-import java.util.zip.InflaterInputStream;
+import java.util.zip.GZIPInputStream;
import javax.imageio.ImageIO;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.EntityResolver;
@@ -319,29 +318,23 @@ public class SVGUniverse implements Serializable
}
- private InputStreamReader createDocumentReader(InputStream is)
+ private InputStreamReader createDocumentReader(InputStream is) throws IOException
{
BufferedInputStream bin = new BufferedInputStream(is);
- bin.mark(4);
-
- byte[] buf = new byte[4];
- try
- {
- bin.read(buf, 0, buf.length);
- bin.reset();
- } catch (IOException ex)
- {
- ex.printStackTrace();
- }
-
-
- if (buf[0] == 0x1f)
+ bin.mark(2);
+ int b0 = bin.read();
+ int b1 = bin.read();
+ bin.reset();
+
+ //Check for gzip magic number
+ if ((b1 << 8 | b0) == GZIPInputStream.GZIP_MAGIC)
{
- InflaterInputStream iis = new InflaterInputStream(bin);
+ GZIPInputStream iis = new GZIPInputStream(bin);
return new InputStreamReader(iis);
}
else
{
+ //Plain text
return new InputStreamReader(bin);
}
}
@@ -378,12 +371,12 @@ public class SVGUniverse implements Serializable
}
- public URI loadSVG(InputStream is, String name)
+ public URI loadSVG(InputStream is, String name) throws IOException
{
return loadSVG(is, name, false);
}
- public URI loadSVG(InputStream is, String name, boolean forceLoad)
+ public URI loadSVG(InputStream is, String name, boolean forceLoad) throws IOException
{
return loadSVG(createDocumentReader(is), name, forceLoad);
}
diff --git a/src/test/java/com/kitfox/svg/zip/ZipTestMain.java b/src/test/java/com/kitfox/svg/zip/ZipTestMain.java
new file mode 100644
index 0000000..7192908
--- /dev/null
+++ b/src/test/java/com/kitfox/svg/zip/ZipTestMain.java
@@ -0,0 +1,76 @@
+/*
+ * ZipTestMain.java
+ *
+ * Created on July 18, 2007, 12:44 AM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package com.kitfox.svg.zip;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.zip.GZIPInputStream;
+
+/**
+ *
+ * @author kitfox
+ */
+public class ZipTestMain
+{
+
+ /** Creates a new instance of ZipTestMain */
+ public ZipTestMain() throws IOException
+ {
+ URL url = ZipTestMain.class.getResource("/missing.svgz");
+// URL url = ZipTestMain.class.getResource("/AdamTagletClasses.svg");
+ InputStream is = url.openStream();
+ BufferedInputStream bin = new BufferedInputStream(is);
+
+ bin.mark(2);
+ int b0 = bin.read();
+ int b1 = bin.read();
+ bin.reset();
+
+ InputStreamReader reader;
+
+ //Check for gzip magic number
+ if ((b1 << 8 | b0) == GZIPInputStream.GZIP_MAGIC)
+ {
+ GZIPInputStream iis = new GZIPInputStream(bin);
+ reader = new InputStreamReader(iis);
+ }
+ else
+ {
+ //Plain text
+ reader = new InputStreamReader(bin);
+ }
+
+
+ BufferedReader br = new BufferedReader(reader);
+ for (String s = br.readLine(); s != null; s = br.readLine())
+ {
+ System.err.println(s);
+ }
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ new ZipTestMain();
+ } catch (IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/test/res/missing.svgz b/src/test/res/missing.svgz
new file mode 100644
index 0000000..051d5e7
--- /dev/null
+++ b/src/test/res/missing.svgz
Binary files differ