[Arakhnę-Dev] [157] Bug fix: FileSystem URL string to URL convertion. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 157
Author: galland
Date: 2010-06-15 09:27:23 +0200 (Tue, 15 Jun 2010)
Log Message:
-----------
Bug fix: FileSystem URL string to URL convertion.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/URISchemeType.java
trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileURLConnectionTest.java
trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourceURLConnectionTest.java
Added Paths:
-----------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactory.java
trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactoryStub.java
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactory.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactory.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactory.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.vmutil;
+
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+/**
+ * This class defines a factory for <code>URL</code> stream
+ * "resource" and "file" protocol handlers.
+ * <p>
+ * It is used by the <code>URL</code> class to create a
+ * <code>URLStreamHandler</code> for a "resource" protocol.
+ * <p>
+ * To use this factory, invoke the following code only ONCE time:
+ * <code>URL.setURLStreamHandlerFactory(new FileResourceURLStreamHandlerFactory());</code>.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid org.arakhne.afc
+ * @mavenartifactid arakhneVmutils
+ * @see URLStreamHandlerFactory
+ * @see URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)
+ * @since 4.2
+ */
+public class FileResourceURLStreamHandlerFactory
+implements URLStreamHandlerFactory {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public URLStreamHandler createURLStreamHandler(String protocol) {
+ if (URISchemeType.RESOURCE.isScheme(protocol))
+ return new ResourceURLStreamHandler();
+ if (URISchemeType.FILE.isScheme(protocol))
+ return new FileURLStreamHandler();
+ // Force the default factory to retreive stream handler.
+ return null;
+ }
+
+}
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-06-09 07:37:14 UTC (rev 156)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -177,7 +177,7 @@
*/
public static URL toJarURL(URL jarFile, String insideFile) throws MalformedURLException {
if (jarFile==null || insideFile==null) return null;
- StringBuffer buf = new StringBuffer(URISchemeType.JAR.toString());
+ StringBuffer buf = new StringBuffer();
buf.append(jarFile.toExternalForm());
buf.append(JAR_URL_FILE_ROOT);
String path = insideFile.replace(File.separatorChar, URL_PATH_SEPARATOR_CHAR);
@@ -187,7 +187,7 @@
else {
buf.append(path);
}
- return new URL(buf.toString());
+ return new URL(URISchemeType.JAR.name(), "", buf.toString()); //$NON-NLS-1$
}
/** Replies if the current operating system uses case-sensitive filename.
@@ -1232,46 +1232,81 @@
* @see Resources#getResource(String)
*/
public static URL convertStringToUrl(String urlDescription, boolean allowResourceSearch, boolean repliesFileURL) {
- if (urlDescription==null || urlDescription.length()==0) return null;
-
- try {
- return new URL(urlDescription);
- }
- catch (MalformedURLException _) {
- // ignore error
- }
-
- URL url;
-
- if (allowResourceSearch) {
-
- String resourceName;
-
- if (urlDescription.toLowerCase().startsWith(URISchemeType.RESOURCE.toString())) {
- resourceName = urlDescription.substring(9);
- return Resources.getResource(resourceName);
+ URL url = null;
+
+ if (urlDescription!=null && urlDescription.length()>0) {
+
+ if (URISchemeType.FILE.isScheme(urlDescription)) {
+ File file = new File(URISchemeType.FILE.removeScheme(urlDescription));
+ try {
+ url = new URL(URISchemeType.FILE.name(), "", file.getPath()); //$NON-NLS-1$
+ }
+ catch (MalformedURLException e) {
+ //
+ }
}
+ else {
+ try {
+ url = new URL(urlDescription);
+ }
+ catch (MalformedURLException _) {
+ // ignore error
+ }
+ }
- resourceName = urlDescription;
- url = Resources.getResource(resourceName);
- if (url!=null) return url;
- }
- else if (urlDescription.toLowerCase().startsWith(URISchemeType.RESOURCE.toString())) {
- return null;
- }
-
- if (repliesFileURL) {
- try {
- File file = new File(urlDescription);
- URI uri = file.toURI();
- return uri.toURL();
+ if (url==null) {
+ if (allowResourceSearch) {
+
+ String resourceName;
+
+ if (URISchemeType.RESOURCE.isScheme(urlDescription)) {
+ resourceName = urlDescription.substring(9);
+ url = Resources.getResource(resourceName);
+ }
+
+ if (url==null) {
+ resourceName = urlDescription;
+ url = Resources.getResource(resourceName);
+ }
+ }
+ else if (urlDescription.toLowerCase().startsWith(URISchemeType.RESOURCE.toString())) {
+ return null;
+ }
+
+ if (url==null && repliesFileURL) {
+ String urlPart = URISchemeType.removeAnyScheme(urlDescription);
+ // Try to parse a malformed JAR url:
+ // jar:{malformed-url}!/{entry}
+ if (URISchemeType.JAR.isScheme(urlDescription)) {
+ int idx = urlPart.indexOf(JAR_URL_FILE_ROOT);
+ if (idx>0) {
+ URL jarURL = convertStringToUrl(urlPart.substring(0, idx), allowResourceSearch);
+ if (jarURL!=null) {
+ try {
+ url = toJarURL(jarURL, urlPart.substring(idx+2));
+ }
+ catch (MalformedURLException _) {
+ //
+ }
+ }
+ }
+ }
+
+ // Standard local file
+ if (url==null) {
+ try {
+ File file = new File(urlPart);
+ url = new URL(URISchemeType.FILE.name(), "", file.getPath()); //$NON-NLS-1$
+ }
+ catch (MalformedURLException e) {
+ // ignore error
+ }
+ }
+ }
}
- catch (MalformedURLException e) {
- // ignore error
- }
}
- return null;
+ return url;
}
/**
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/URISchemeType.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/URISchemeType.java 2010-06-09 07:37:14 UTC (rev 156)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/URISchemeType.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -310,30 +310,81 @@
public boolean isScheme(String string) {
return getSchemeType(string)==this;
}
+
+ /** Remove this URI scheme from the given string.
+ *
+ * @param string
+ * @return the <var>string</var> without the URI scheme.
+ */
+ public String removeScheme(String string) {
+ if (string!=null) {
+ int idx = string.indexOf(':');
+ if (idx>=0) {
+ String p = string.substring(0, idx+1);
+ if (toString().equalsIgnoreCase(p)) {
+ p = string.substring(idx+1);
+ if (p.startsWith("//")) { //$NON-NLS-1$
+ return p.substring(2);
+ }
+ return p;
+ }
+ }
+ }
+ return string;
+ }
+ /** Remove any supported URI scheme from the given string.
+ *
+ * @param string
+ * @return the <var>string</var> without the URI scheme.
+ */
+ public static String removeAnyScheme(String string) {
+ if (string!=null) {
+ int idx = string.indexOf(':');
+ if (idx>=0) {
+ String p = string.substring(0, idx+1);
+ for(URISchemeType type : values()) {
+ if (type.toString().equalsIgnoreCase(p)) {
+ p = string.substring(idx+1);
+ if (p.startsWith("//")) { //$NON-NLS-1$
+ return p.substring(2);
+ }
+ return p;
+ }
+ }
+ }
+ }
+ return string;
+ }
+
private static URISchemeType getSchemeType(String protocol) {
- if (protocol==null
+ String p = protocol;
+ int idx = protocol.indexOf(':');
+ if (idx>=0) {
+ p = protocol.substring(0, idx);
+ }
+ if (p==null
|| "".equals(protocol) //$NON-NLS-1$
- || "file".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ || "file".equalsIgnoreCase(p)) //$NON-NLS-1$
return FILE;
- if ("http".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("http".equalsIgnoreCase(p)) //$NON-NLS-1$
return HTTP;
- if ("https".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("https".equalsIgnoreCase(p)) //$NON-NLS-1$
return HTTPS;
- if ("ftp".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("ftp".equalsIgnoreCase(p)) //$NON-NLS-1$
return FTP;
- if ("mailto".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("mailto".equalsIgnoreCase(p)) //$NON-NLS-1$
return MAILTO;
- if ("news".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("news".equalsIgnoreCase(p)) //$NON-NLS-1$
return NEWS;
- if ("ssh".equalsIgnoreCase(protocol) //$NON-NLS-1$
- || "sftp".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("ssh".equalsIgnoreCase(p) //$NON-NLS-1$
+ || "sftp".equalsIgnoreCase(p)) //$NON-NLS-1$
return SSH;
- if ("telnet".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("telnet".equalsIgnoreCase(p)) //$NON-NLS-1$
return TELNET;
- if ("jar".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("jar".equalsIgnoreCase(p)) //$NON-NLS-1$
return JAR;
- if ("resource".equalsIgnoreCase(protocol)) //$NON-NLS-1$
+ if ("resource".equalsIgnoreCase(p)) //$NON-NLS-1$
return RESOURCE;
return URISchemeType.UNSUPPORTED;
}
Added: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactoryStub.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactoryStub.java (rev 0)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileResourceURLStreamHandlerFactoryStub.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -0,0 +1,67 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.vmutil;
+
+import java.net.URLStreamHandler;
+
+/**
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid org.arakhne.afc
+ * @mavenartifactid arakhneVmutils
+ */
+class FileResourceURLStreamHandlerFactoryStub
+extends FileResourceURLStreamHandlerFactory {
+
+ /** Singleton.
+ */
+ public static final FileResourceURLStreamHandlerFactoryStub SINGLETON = new FileResourceURLStreamHandlerFactoryStub();
+
+ private volatile boolean used = false;
+
+ /**
+ */
+ private FileResourceURLStreamHandlerFactoryStub() {
+ //
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public URLStreamHandler createURLStreamHandler(String protocol) {
+ if (this.used) return super.createURLStreamHandler(protocol);
+ return null;
+ }
+
+ /** Enable this factory.
+ */
+ public void enable() {
+ this.used = true;
+ }
+
+ /** Disable this factory.
+ */
+ public void disable() {
+ this.used = false;
+ }
+
+}
Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java 2010-06-09 07:37:14 UTC (rev 156)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -534,41 +534,62 @@
* @throws Exception
*/
public void testConvertStringToUrl() throws Exception {
+ URL rr;
+
+ // The following test permits to check if a specifical behaviour of URL
+ // is still present in the JRE.
+ rr = new URL("file://marbre.jpg"); //$NON-NLS-1$
+ assertEquals("file", rr.getProtocol()); //$NON-NLS-1$
+ assertEquals("marbre.jpg", rr.getAuthority()); //$NON-NLS-1$
+ assertEquals("", rr.getPath()); //$NON-NLS-1$
+ //-----
+
assertNull(FileSystem.convertStringToUrl(null, true));
assertNull(FileSystem.convertStringToUrl("", true)); //$NON-NLS-1$
assertNull(FileSystem.convertStringToUrl(null, false));
assertNull(FileSystem.convertStringToUrl("", false)); //$NON-NLS-1$
- assertEquals(new URL("http://www.arakhne.org/"), //$NON-NLS-1$
+ rr = FileSystem.convertStringToUrl("file://marbre.jpg", false); //$NON-NLS-1$
+ assertNotNull(rr);
+ assertEquals("file", rr.getProtocol()); //$NON-NLS-1$
+ assertEquals("", rr.getAuthority()); //$NON-NLS-1$
+ assertEquals("", rr.getHost()); //$NON-NLS-1$
+ assertNull(rr.getQuery());
+ assertEquals("marbre.jpg", rr.getPath()); //$NON-NLS-1$
+
+ assertEquals(new URL("http", "www.arakhne.org", "/"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("http://www.arakhne.org/", true)); //$NON-NLS-1$
- assertEquals(new URL("http://www.arakhne.org/"), //$NON-NLS-1$
+ assertEquals(new URL("http", "www.arakhne.org", "/"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("http://www.arakhne.org/", false)); //$NON-NLS-1$
- assertEquals(new URL("file:"+f1.getAbsolutePath()), //$NON-NLS-1$
+ assertEquals(new URL("file", "", f1.getAbsolutePath()), //$NON-NLS-1$ //$NON-NLS-2$
FileSystem.convertStringToUrl("file:"+f1.getAbsolutePath(), true)); //$NON-NLS-1$
- assertEquals(new URL("file:"+f1.getAbsolutePath()), //$NON-NLS-1$
+ assertEquals(new URL("file", "", f1.getAbsolutePath()), //$NON-NLS-1$ //$NON-NLS-2$
FileSystem.convertStringToUrl("file:"+f1.getAbsolutePath(), false)); //$NON-NLS-1$
- assertEquals(new URL("file:./toto"), //$NON-NLS-1$
+ assertEquals(new URL("file", "", "./toto"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("file:./toto", false)); //$NON-NLS-1$
- assertEquals(new File("jar:/home/test/j.jar").toURI().toURL(), //$NON-NLS-1$
+ // CAUTION: testing right-formed jar URL.
+ assertEquals(new URL("jar", "", "file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FileSystem.convertStringToUrl("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", true)); //$NON-NLS-1$
+ assertEquals(new URL("jar", "", "file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FileSystem.convertStringToUrl("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", false)); //$NON-NLS-1$
+
+ // CAUTION: testing malformed jar URL. Right syntax is: jar:{url}!/{entry}
+ assertEquals(new URL("file", "", "/home/test/j.jar"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("jar:/home/test/j.jar", true)); //$NON-NLS-1$
- assertEquals(new File("jar:/home/test/j.jar").toURI().toURL(), //$NON-NLS-1$
+ assertEquals(new URL("file", "", "/home/test/j.jar"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("jar:/home/test/j.jar", false)); //$NON-NLS-1$
- assertEquals(new File("jar:/home/test/j.jar!/org/arakhne/vmutil/ff.properties").toURI().toURL(), //$NON-NLS-1$
+ // CAUTION: testing malformed jar URL. Right syntax is: jar:{url}!/{entry}
+ assertEquals(new URL("jar", "", "file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("jar:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", true)); //$NON-NLS-1$
- assertEquals(new File("jar:/home/test/j.jar!/org/arakhne/vmutil/ff.properties").toURI().toURL(), //$NON-NLS-1$
+ assertEquals(new URL("jar", "", "file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileSystem.convertStringToUrl("jar:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", false)); //$NON-NLS-1$
- assertEquals(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$
- FileSystem.convertStringToUrl("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", true)); //$NON-NLS-1$
- assertEquals(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$
- FileSystem.convertStringToUrl("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties", false)); //$NON-NLS-1$
-
URL testResource = Resources.getResource("/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
assertNotNull(testResource);
- URL testResourceFileRel = new File("org/arakhne/vmutil/test.txt").toURI().toURL(); //$NON-NLS-1$
+ URL testResourceFileRel = new URL("file","", "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
URL testResourceFileAbs = new File("/org/arakhne/vmutil/test.txt").toURI().toURL(); //$NON-NLS-1$
assertEquals(testResource,
Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileURLConnectionTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileURLConnectionTest.java 2010-06-09 07:37:14 UTC (rev 156)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileURLConnectionTest.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -48,7 +48,7 @@
static {
try {
- URL.setURLStreamHandlerFactory(new FileURLStreamHandlerFactory());
+ URL.setURLStreamHandlerFactory(FileResourceURLStreamHandlerFactoryStub.SINGLETON);
}
catch(Error _) {
// Duplicate registration of the factory.
@@ -61,6 +61,7 @@
@Override
public void setUp() throws Exception {
super.setUp();
+ FileResourceURLStreamHandlerFactoryStub.SINGLETON.enable();
URL resourceUrl = Resources.getResource("org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
assertNotNull(resourceUrl);
this.connection = new FileURLConnection(resourceUrl);
@@ -72,6 +73,7 @@
@Override
public void tearDown() throws Exception {
this.connection = null;
+ FileResourceURLStreamHandlerFactoryStub.SINGLETON.disable();
super.tearDown();
}
Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourceURLConnectionTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourceURLConnectionTest.java 2010-06-09 07:37:14 UTC (rev 156)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourceURLConnectionTest.java 2010-06-15 07:27:23 UTC (rev 157)
@@ -40,19 +40,20 @@
static {
try {
- URL.setURLStreamHandlerFactory(new FileURLStreamHandlerFactory());
+ URL.setURLStreamHandlerFactory(FileResourceURLStreamHandlerFactoryStub.SINGLETON);
}
catch(Error _) {
// Duplicate registration of the factory.
}
}
-
+
/**
* {@inheritDoc}
*/
@Override
public void setUp() throws Exception {
super.setUp();
+ FileResourceURLStreamHandlerFactoryStub.SINGLETON.enable();
URL resourceUrl = new URL("resource:org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
assertNotNull(resourceUrl);
this.connection = new ResourceURLConnection(resourceUrl);
@@ -64,6 +65,7 @@
@Override
public void tearDown() throws Exception {
this.connection = null;
+ FileResourceURLStreamHandlerFactoryStub.SINGLETON.disable();
super.tearDown();
}