Revision: 7670
Author: victormote
Date: 2006-06-17 07:10:55 -0700 (Sat, 17 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7670&view=rev
Log Message:
-----------
Add new class contributed by Vincent Hennebert (patch 1506271) for accessing the contents of a jar file with a URL.
Added Paths:
-----------
trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java
Added: trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java (rev 0)
+++ trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-17 14:10:55 UTC (rev 7670)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2006 The aXSL Project.
+ * http://www.axsl.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* $Id$ */
+
+/* Known contributors:
+ * Vincent Hennebert (original author)
+ */
+
+package org.foray.common;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+/**
+ * Stream handler for URLs with the <code>classpath</code> protocol. Such URLs
+ * are used to refer to resources in the CLASSPATH. The two following syntaxes
+ * are allowed, but the first one is preferred:
+ * <ul>
+ * <li><code>classpath:/path/to/the/resource</code></li>
+ * <li><code>classpath:path/to/the/resource</code></li>
+ * </ul>
+ */
+public class ClasspathHandler extends URLStreamHandler {
+
+ protected URLConnection openConnection(URL u) {
+ return new URLConnection(u) {
+ public void connect() {}
+
+ public InputStream getInputStream() {
+ String path = url.getPath();
+ String resourcePath =
+ (path.charAt(0) == '/')? path.substring(1): path;
+ return getClass().getClassLoader().
+ getResourceAsStream(resourcePath);
+ }
+ };
+ }
+}
Property changes on: trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java
___________________________________________________________________
Name: svn:keywords
+ "Author Id Rev Date URL"
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|