Revision: 16630
http://sourceforge.net/p/gate/code/16630
Author: ian_roberts
Date: 2013-04-04 14:04:59 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
Added URL protocol handler for gz: URLs to un-gzip files on the fly. This is
useful for pulling a <documents> element into a batch definition from a .xml.gz
file via an external entity definition in the DTD.
Modified Paths:
--------------
gcp/trunk/cli/src/gate/cloud/cli/Main.java
Added Paths:
-----------
gcp/trunk/src/gate/cloud/util/protocols/
gcp/trunk/src/gate/cloud/util/protocols/gz/
gcp/trunk/src/gate/cloud/util/protocols/gz/Handler.java
Modified: gcp/trunk/cli/src/gate/cloud/cli/Main.java
===================================================================
--- gcp/trunk/cli/src/gate/cloud/cli/Main.java 2013-04-04 09:53:48 UTC (rev
16629)
+++ gcp/trunk/cli/src/gate/cloud/cli/Main.java 2013-04-04 14:04:59 UTC (rev
16630)
@@ -215,6 +215,7 @@
cmdline.add("-Xmx" + maxMem);
cmdline.addAll(javaOpts);
cmdline.add("-Dgcp.home=" + gcpHome.getAbsolutePath());
+ cmdline.add("-Djava.protocol.handler.pkgs=gate.cloud.util.protocols");
cmdline.add("gate.cloud.batch.BatchRunner");
cmdline.add(threads);
// this will be replaced with the right batch file path at run time
Added: gcp/trunk/src/gate/cloud/util/protocols/gz/Handler.java
===================================================================
--- gcp/trunk/src/gate/cloud/util/protocols/gz/Handler.java
(rev 0)
+++ gcp/trunk/src/gate/cloud/util/protocols/gz/Handler.java 2013-04-04
14:04:59 UTC (rev 16630)
@@ -0,0 +1,176 @@
+package gate.cloud.util.protocols.gz;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.Permission;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
+
+/**
+ * URLStreamHandler for the gz: protocol. Understands URLs of the form
+ * gz:URL (e.g. gz:file:/home/user/readme.txt.gz) and uncompresses them
+ * on the fly when reading.
+ */
+public class Handler extends URLStreamHandler {
+
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new GZURLConnection(u);
+ }
+
+ static class GZURLConnection extends URLConnection {
+
+ URLConnection delegate;
+
+ protected GZURLConnection(URL url) throws IOException {
+ super(url);
+ // url must start gz:, strip this off to find the real URL
+ URL delegateUrl = new URL(url.toExternalForm().substring(3));
+ delegate = delegateUrl.openConnection();
+ }
+
+ public void connect() throws IOException {
+ delegate.connect();
+ }
+
+
+ public InputStream getInputStream() throws IOException {
+ return new GzipCompressorInputStream(delegate.getInputStream());
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ return new GzipCompressorOutputStream(delegate.getOutputStream());
+ }
+
+
+
+ public void setConnectTimeout(int timeout) {
+ delegate.setConnectTimeout(timeout);
+ }
+
+ public int getConnectTimeout() {
+ return delegate.getConnectTimeout();
+ }
+
+ public void setReadTimeout(int timeout) {
+ delegate.setReadTimeout(timeout);
+ }
+
+ public int getReadTimeout() {
+ return delegate.getReadTimeout();
+ }
+
+ public String getContentType() {
+ return delegate.getContentType();
+ }
+
+ public long getExpiration() {
+ return delegate.getExpiration();
+ }
+
+ public long getDate() {
+ return delegate.getDate();
+ }
+
+ public long getLastModified() {
+ return delegate.getLastModified();
+ }
+
+ public String getHeaderField(String name) {
+ return delegate.getHeaderField(name);
+ }
+
+ public Map<String, List<String>> getHeaderFields() {
+ return delegate.getHeaderFields();
+ }
+
+ public int getHeaderFieldInt(String name, int Default) {
+ return delegate.getHeaderFieldInt(name, Default);
+ }
+
+ public long getHeaderFieldDate(String name, long Default) {
+ return delegate.getHeaderFieldDate(name, Default);
+ }
+
+ public String getHeaderFieldKey(int n) {
+ return delegate.getHeaderFieldKey(n);
+ }
+
+ public String getHeaderField(int n) {
+ return delegate.getHeaderField(n);
+ }
+
+ public Permission getPermission() throws IOException {
+ return delegate.getPermission();
+ }
+
+ public void setDoInput(boolean doinput) {
+ delegate.setDoInput(doinput);
+ }
+
+ public boolean getDoInput() {
+ return delegate.getDoInput();
+ }
+
+ public void setDoOutput(boolean dooutput) {
+ delegate.setDoOutput(dooutput);
+ }
+
+ public boolean getDoOutput() {
+ return delegate.getDoOutput();
+ }
+
+ public void setAllowUserInteraction(boolean allowuserinteraction) {
+ delegate.setAllowUserInteraction(allowuserinteraction);
+ }
+
+ public boolean getAllowUserInteraction() {
+ return delegate.getAllowUserInteraction();
+ }
+
+ public void setUseCaches(boolean usecaches) {
+ delegate.setUseCaches(usecaches);
+ }
+
+ public boolean getUseCaches() {
+ return delegate.getUseCaches();
+ }
+
+ public void setIfModifiedSince(long ifmodifiedsince) {
+ delegate.setIfModifiedSince(ifmodifiedsince);
+ }
+
+ public long getIfModifiedSince() {
+ return delegate.getIfModifiedSince();
+ }
+
+ public void setDefaultUseCaches(boolean defaultusecaches) {
+ delegate.setDefaultUseCaches(defaultusecaches);
+ }
+
+ public void setRequestProperty(String key, String value) {
+ delegate.setRequestProperty(key, value);
+ }
+
+ public void addRequestProperty(String key, String value) {
+ delegate.addRequestProperty(key, value);
+ }
+
+ public String getRequestProperty(String key) {
+ return delegate.getRequestProperty(key);
+ }
+
+ public Map<String, List<String>> getRequestProperties() {
+ return delegate.getRequestProperties();
+ }
+
+ }
+
+}
Property changes on: gcp/trunk/src/gate/cloud/util/protocols/gz/Handler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs