package cucumber.runtime.io;

import cucumber.runtime.CucumberException;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

public class Helpers {
    static boolean hasSuffix(String suffix, String name) {
        return suffix == null || name.endsWith(suffix);
    }

    static String filePath(URL url) {
        try {
            return url.toURI().getSchemeSpecificPart();
        } catch (URISyntaxException e) {
            throw new CucumberException(e);
        }
    }

    static String jarFilePath(URL jarUrl) throws UnsupportedEncodingException, MalformedURLException {
        String urlFile = jarUrl.getFile();

        int separatorIndex = urlFile.indexOf("!/");
        if (separatorIndex == -1) {
            throw new CucumberException("Not a jar URL: " + jarUrl.toExternalForm());
        }
        return filePath(new URL(urlFile.substring(0, separatorIndex)));
    }
}

@@ -71,53 +71,8 @@
 n;%0A%0A
-import java.io.UnsupportedEncodingException;%0A
 impo
@@ -344,14 +344,173 @@
 URL 
-url) %7B
+fileUrl) %7B%0A        if (!%22file%22.equals(fileUrl.getProtocol())) %7B%0A            throw new CucumberException(%22Expected a file URL:%22 + fileUrl.toExternalForm());%0A        %7D
 %0A   
@@ -539,17 +539,21 @@
  return 
-u
+fileU
 rl.toURI
@@ -727,67 +727,8 @@
 Url)
- throws UnsupportedEncodingException, MalformedURLException
  %7B%0A 
@@ -903,11 +903,16 @@
 on(%22
-Not
+Expected
  a j
@@ -971,24 +971,40 @@
     
-return filePath(
+try %7B%0A            URL fileUrl = 
 new 
@@ -1044,18 +1044,153 @@
 rIndex))
-)
 ;
+%0A            return filePath(fileUrl);%0A        %7D catch (MalformedURLException e) %7B%0A            throw new CucumberException(e);%0A        %7D
 %0A    %7D%0A%7D

Clean up and make more robust. Ref #866