public String urlFor(String pathAfterContext) { try { return new URL(protocol, host, port, contextPath + pathAfterContext).toExternalForm(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } }
public String getXmlSystemId() throws IOException { return file.toURI().toURL().toExternalForm(); }
private InputStream jksDatastore(String jksPath) throws FileNotFoundException { URL jksUrl = getClass().getClassLoader().getResource(jksPath); if (jksUrl != null) { logger.info("Starting with jks at {}, jks normal {}", jksUrl.toExternalForm(), jksUrl); return getClass().getClassLoader().getResourceAsStream(jksPath); } logger.warn("No keystore has been found in the bundled resources. Scanning filesystem..."); File jksFile = new File(jksPath); if (jksFile.exists()) { logger.info("Loading external keystore. Url = {}.", jksFile.getAbsolutePath()); return new FileInputStream(jksFile); } logger.warn("The keystore file does not exist. Url = {}.", jksFile.getAbsolutePath()); return null; } }
private void addJarLRByClass(Class<?> clazz, final Map<String, LocalResource> lrMap) throws IOException, LoginException { final File jar = new File(Utilities.jarFinderGetJar(clazz)); final String localJarPath = jar.toURI().toURL().toExternalForm(); final LocalResource jarLr = createJarLocalResource(localJarPath); lrMap.put(DagUtils.getBaseName(jarLr), jarLr); }
uFolder = new URL(uFolder.toExternalForm().replaceAll(" ", "%20")); } catch (Exception ex) { fFolder = new File(uFolder.toURI()); log.debug("resourceList: having folder:\n%s", fFolder); String sFolder = normalizeAbsolute(fFolder.getPath(), false); sFolder = sFolder.substring(1); files.add(sFolder); files = doResourceListFolder(new File(sFolder), files, filter); files.remove(0); return files; } catch (Exception ex) { if (!"jar".equals(uFolder.getProtocol())) { log.debug("resourceList:\n%s", folder); log.error("resourceList: URL neither folder nor jar:\n%s", ex);
private static List<JavaFileObject> browseJar(URL packageFolderURL) { List<JavaFileObject> result = new ArrayList<>(); try { String jarUri = packageFolderURL.toExternalForm().split("!")[0]; JarURLConnection jarConn = (JarURLConnection) packageFolderURL.openConnection(); String rootEntryName = jarConn.getEntryName(); int rootEnd = rootEntryName.length() + 1; Enumeration<JarEntry> entryEnum = jarConn.getJarFile().entries(); while (entryEnum.hasMoreElements()) { JarEntry jarEntry = entryEnum.nextElement(); String name = jarEntry.getName(); if (name.startsWith(rootEntryName) && name.indexOf('/', rootEnd) == -1 && name.endsWith(CLASS_FILE)) { String binaryName = name.replaceAll("/", ".").replaceAll(CLASS_FILE + "$", ""); result.add(new CustomJavaFileObject(URI.create(jarUri + "!/" + name), JavaFileObject.Kind.CLASS, binaryName)); } } } catch (Exception e) { throw new RuntimeException(packageFolderURL + " is not a JAR file", e); } return result; } }
final boolean isVfs = url.getProtocol() != null && url.getProtocol().startsWith("vfs"); if ("file".equals(url.getProtocol()) || isVfs) { final File dir = toFile(url); if (dir.isDirectory()) { if (idx > -1) { jarPath = jarPath.substring(0, idx + 4); final File jarFile = new File(jarPath); if (jarFile.isFile() && jarFile.exists()) { files.add(jarFile); print("Add jar file from VFS: '%s'", jarFile); loadJarContent((JarURLConnection) url.openConnection(), packageName, streams); } catch (ClassCastException cce) { throw new AssertionError("Not a File: " + url.toExternalForm()); try { String u = url.toExternalForm(); if (u.startsWith("zip:")) { u = u.substring(4); jarFile = toFile(new URL(u)); } catch (Exception ex) { throw new AssertionError("Not a File: " + url.toExternalForm());
rootPath = new File(classPath).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/"; File webappDir = new File(rootPath + resourceBase); if (!webappDir.exists() || !webappDir.isDirectory()) { throw new IllegalArgumentException("Could not found webapp directory or it is not directory."); resourceUrls.add(webappUrl); while (staticUrls.hasMoreElements()) { staticURL = staticUrls.nextElement(); if (staticURL != null) { resourceUrls.add(staticURL.toExternalForm());
while (urls.hasMoreElements()) { final URL url = urls.nextElement(); int index = url.toExternalForm().lastIndexOf(resourceName); if (index != -1) { result.add(new URL(url, url.toExternalForm().substring(0, index))); } else { result.add(url);
@Override public List<String> getURLsFromPage(Document doc) { List<String> result = new ArrayList<>(); List<String> urlsToGrab = new ArrayList<>(); if (url.toExternalForm().contains("/manga/")) { for (Element el : doc.select("div.chapter-list > div.row > span > a")) { urlsToGrab.add(el.attr("href")); } Collections.reverse(urlsToGrab); for (String url : urlsToGrab) { result.addAll(getURLsFromChap(url)); } } else if (url.toExternalForm().contains("/chapter/")) { result.addAll(getURLsFromChap(doc)); } return result; }
private void handleURL(String theUrl, String id, String title) { URL originalURL; try { originalURL = new URL(theUrl); } catch (MalformedURLException e) { return; String url = urls.get(0).toExternalForm(); Pattern p = Pattern.compile("https?://i.reddituploads.com/([a-zA-Z0-9]+)\\?.*"); Matcher m = p.matcher(url); addURLToDownload(urls.get(0), new File(savePath)); URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm()); if (urlToDownload != null) { LOGGER.info("url: " + urlToDownload + " file: " + savePath); addURLToDownload(urlToDownload, new File(savePath));
private InputSource(Object source, String systemId) { assertNotNull(source, "source"); if (source instanceof URL) { try { this.source = new File(((URL) source).toURI().normalize()); // convert URL to File } catch (Exception e) { this.source = source; } } else if (source instanceof File) { this.source = new File(((File) source).toURI().normalize()); // remove ../ } else { this.source = source; } if (this.source instanceof URL) { this.systemId = ((URL) this.source).toExternalForm(); } else if (this.source instanceof File) { this.systemId = ((File) this.source).toURI().toString(); } else { this.systemId = trimToNull(systemId); } }
String protocol = url.getProtocol(); return new URL(jarPath); new Object[] { mue.getMessage(), url.toExternalForm(), jarPath });
webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml"); webapp.setServer(server); webapp.setWar(location.toExternalForm()); webapp.setTempDirectory(new File("/path/to/webapp-directory"));
xml=new URI((String)xml); } catch (URISyntaxException e) { xml=new File((String)xml); xml=uri.toURL(); return new StreamSource(url.toExternalForm());
wasDir = entry.isDirectory(); LOG.finest("urlForArchiveOrDir:toURI:entry"); //NOI18N u = Utilities.toURI(entry).toURL(); isDir = entry.isDirectory(); } while (wasDir ^ isDir); return getArchiveRoot(u); } else if (isDir) { assert u.toExternalForm().endsWith("/"); //NOI18N return u; } else if (!entry.exists()) { if (!u.toString().endsWith("/")) { //NOI18N u = new URL(u + "/"); // NOI18N
private URLOutputStream(URL url, String method, Map<String, String> headers, int expectedResponseCode) throws IOException { this.url = url; this.method = method; this.expectedResponseCode = expectedResponseCode; if (url.getProtocol().equals("file")) { File file = new File(url.getFile()); ensureParentDirExists(file); out = new FileOutputStream(file); urlConnection = null; } else if (url.getProtocol().startsWith("http")) { urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod(method); urlConnection.setDoOutput(true); for (Map.Entry<String, String> header : headers.entrySet()) { urlConnection.setRequestProperty(header.getKey(), header.getValue()); } out = urlConnection.getOutputStream(); } else { throw new IllegalArgumentException("URL Scheme must be one of file,http,https. " + url.toExternalForm()); } }
private static URL toURL(File fFile, FileObject fo) throws MalformedURLException { URL retVal = Utilities.toURI(fFile).toURL(); if (retVal != null && fo.isFolder()) { // #155742,160333 - URL for folder must always end with slash final String urlDef = retVal.toExternalForm(); final String pathSeparator = "/";//NOI18N if (!urlDef.endsWith(pathSeparator)) { retVal = new URL(urlDef + pathSeparator); } } return retVal; }
if ("file".equalsIgnoreCase(url.getProtocol())) { if (url.getHost() == null || "".equals(url.getHost())) { return path.toUri().toURL(); } else if ("jar".equals(url.getProtocol())) { String file = url.getFile(); int pos = file.indexOf("!/"); URL internalUrl = new URL(filePath); URL normalizedUrl = resolveRepoURL(internalUrl); if (normalizedUrl == null) { return null; return new URL("jar", "", normalizedUrl.toExternalForm() + jarTail); } else {
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); } }