protected static File asFile(String path) { try { URI uri = new URI(path); if (uri.getScheme().equals("file")) { return new File(uri.getPath()); } else { throw new IllegalArgumentException("This path does not denote a local file."); } } catch (URISyntaxException | NullPointerException e) { throw new IllegalArgumentException("This path does not describe a valid local file URI.", e); } }
final URI uri; if (fsUri.getScheme() != null) { uri = fsUri; rewrittenUri = new URI(defaultUri.getScheme(), null, defaultUri.getHost(), defaultUri.getPort(), fsUri.getPath(), null, null); if (defaultUri.getScheme().equals("file")) { try { rewrittenUri = new URI( "file", null, new Path(new File(fsUri.getPath()).getAbsolutePath()).toUri().getPath(), null); } catch (URISyntaxException ignored) { + uri.toString() + "'. Hint: Did you forget a slash? (correct path would be '" + supposedUri + "')");
throw new FileNotFoundException(); String dummySourceFilePath = dummySourceFile.toUri().toString(); cleanURI = new URI(dummySourceFilePath); } catch (URISyntaxException e) { throw new FileNotFoundException(); File dummyFile = new File(cleanURI); File sourcesGenerationFolder = dummyFile.getParentFile(); File projectRoot = sourcesGenerationFolder.getParentFile();
static URI propertyUrlToUri(String wildFlyConfig) { if (File.separator.equals("\\") && wildFlyConfig.contains("\\")) { // we are on the windows and path is for windows File f = new File(wildFlyConfig); return f.toPath().toUri(); } else { try { URI uri = new URI(wildFlyConfig); if (!uri.isAbsolute()) { // URI does not include schema if (uri.getPath().charAt(0) != File.separatorChar && uri.getPath().charAt(0) != '/') { // relative path String userDir = System.getProperty("user.dir").replace(File.separatorChar, '/'); return Paths.get(userDir, uri.getPath()).toUri(); } else { // absolute path return Paths.get(uri.getPath()).toUri(); } } return uri; } catch (URISyntaxException e) { // no config file there return null; } } }
/** * Get the URI of the path. Assume to be local file system if no scheme. */ public static URI getURI(String path) throws URISyntaxException { if (path == null) { return null; } URI uri = new URI(path); if (uri.getScheme() == null) { // if no scheme in the path, we assume it's file on local fs. uri = new File(path).toURI(); } return uri; }
public static File getClasspathFile(String file) throws FileNotFoundException { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (Throwable ex) { // } if (cl == null) { cl = TestUtils.class.getClassLoader(); } URL resourceUrl = cl.getResource(file); try { return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart()); } catch (URISyntaxException e) { throw new FileNotFoundException(file); } }
/** * Insert a base URL (if configured) unless the given URL has a host already. */ private URI insertBaseUrl(URI url) { try { String baseUrl = getBaseUrl(); if (baseUrl != null && url.getHost() == null) { url = new URI(baseUrl + url.toString()); } return url; } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URL after inserting base URL: " + url, ex); } }
static String absoluteURI(String serverOrigin, HttpServerRequest req) throws URISyntaxException { String absoluteURI; URI uri = new URI(req.uri()); String scheme = uri.getScheme(); if (scheme != null && (scheme.equals("http") || scheme.equals("https"))) { absoluteURI = uri.toString(); } else { String host = req.host(); if (host != null) { absoluteURI = req.scheme() + "://" + host + uri; } else { // Fall back to the server origin absoluteURI = serverOrigin + uri; } } return absoluteURI; }
@Override public void initialize(URI name, Configuration conf) throws IOException { try { URI realUri = new URI (realScheme, realAuthority, name.getPath(), name.getQuery(), name.getFragment()); super.initialize(realUri, conf); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * Base URI for a config store should be root of the zip file, so change path part of URI to be null */ private URI getBaseURI(URI configKey) throws URISyntaxException { return new URI(configKey.getScheme(), configKey.getAuthority(), null, configKey.getQuery(), configKey.getFragment()); } }
public String siteUrlFor(String url, boolean forceSsl) throws URISyntaxException { String scheme = new URI(url).getScheme(); ServerSiteUrlConfig siteUrl = forceSsl || (scheme != null && scheme.equals("https")) ? getSecureSiteUrl() : serverConfig().getSiteUrl(); return siteUrl.siteUrlFor(url, false); }
protected String hostInfoForCommandline() { try { URI uri = new URI(url); if (uri.getUserInfo() != null) { //(String scheme, String userInfo, String host, int port, String path, String query, String fragment) uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); } return uri.toString(); } catch (URISyntaxException e) { // In subversion we may have a file path that is not actually a URL return url; } }