All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cucumber.runtime.io.Helpers Maven / Gradle / Ivy

There is a newer version: 1.2.6
Show newest version
package cucumber.runtime.io;

import cucumber.runtime.CucumberException;

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 fileUrl) {
        if (!"file".equals(fileUrl.getProtocol())) {
            throw new CucumberException("Expected a file URL:" + fileUrl.toExternalForm());
        }
        try {
            return fileUrl.toURI().getSchemeSpecificPart();
        } catch (URISyntaxException e) {
            throw new CucumberException(e);
        }
    }

    static String jarFilePath(URL jarUrl) {
        String urlFile = jarUrl.getFile();

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy