List of usage examples for java.net URL getPath
public String getPath()
From source file:com.spotify.docker.client.messages.RegistryAuthTest.java
private static Path getWindowsPath(final String path) { final URL resource = RegistryAuthTest.class.getResource("/" + path); return Paths.get(resource.getPath().substring(1)); }
From source file:com.netflix.genie.web.controllers.ControllerUtils.java
/** * Given a HTTP {@code request} and a {@code path} this method will return the root of the request minus the path. * Generally the path will be derived from {@link #getRemainingPath(HttpServletRequest)} and this method will be * called subsequently./* ww w .j ava 2 s .c o m*/ * <p> * If the request URL is {@code https://myhost/api/v3/jobs/12345/output/genie/run?myparam=4#BLAH} and the path is * {@code genie/run} this method should return {@code https://myhost/api/v3/jobs/12345/output/}. * <p> * All query parameters and references will be stripped off. * * @param request The HTTP request to get information from * @param path The path that should be removed from the end of the request URL * @return The base of the request * @throws MalformedURLException If we're unable to create a new valid URL after removing the path * @since 4.0.0 */ static URL getRequestRoot(final URL request, @Nullable final String path) throws MalformedURLException { final String currentPath = request.getPath(); final String newPath = StringUtils.removeEnd(currentPath, path); return new URL(request.getProtocol(), request.getHost(), request.getPort(), newPath); }
From source file:eu.artist.methodology.mpt.cheatsheet.Activator.java
public static void createDirs() throws IOException, URISyntaxException { final String STATE_LOCATION = Activator.getDefault().getStateLocation().toString(); System.out.println("Creating dirs in state location ..."); URL csURL = plugin.getBundle().getEntry("cheatsheets/"); //csURL = new URL("platform:/plugin/eu.artist.methodology.mpt.cheatsheet/cheatsheets/" + csMap.get(csId)); URL resolvedcsURL = FileLocator.toFileURL(csURL); URI resolvedcsURI = new URI(resolvedcsURL.getProtocol(), resolvedcsURL.getPath(), null); File csFile = new File(resolvedcsURI); FileUtils.copyDirectory(csFile, new File(STATE_LOCATION)); }
From source file:com.atlassian.theplugin.idea.crucible.CrucibleHelper.java
public static Collection<UploadItem> getUploadItemsFromChanges(final Project project, final Collection<Change> changes) { Collection<UploadItem> uploadItems = new ArrayList<UploadItem>(); for (Change change : changes) { try {/* w w w . j a v a 2s.c om*/ ContentRevision contentRevision; if (change.getBeforeRevision() != null) { contentRevision = change.getBeforeRevision(); } else { //for added but not committed files after revision is available only contentRevision = change.getAfterRevision(); } // PL-1619 if (contentRevision == null) { continue; } String fileUrl = null; VirtualFile file = contentRevision.getFile().getVirtualFile(); if (file == null) { file = contentRevision.getFile().getVirtualFileParent(); if (file == null) { continue; } fileUrl = VcsIdeaHelper.getRepositoryUrlForFile(project, file); if (fileUrl != null) { fileUrl = fileUrl + "/" + contentRevision.getFile().getName(); } } else { fileUrl = VcsIdeaHelper.getRepositoryUrlForFile(project, file); } try { URL url = new URL(fileUrl); fileUrl = url.getPath(); } catch (MalformedURLException e) { String rootUrl = VcsIdeaHelper.getRepositoryRootUrlForFile(project, contentRevision.getFile().getVirtualFile()); fileUrl = StringUtils.difference(rootUrl, fileUrl); } ContentRevision revOld = change.getBeforeRevision(); ContentRevision revNew = change.getAfterRevision(); byte[] byteOld = revOld != null && revOld.getContent() != null ? revOld.getContent().getBytes() : new byte[0]; byte[] byteNew = revNew != null && revNew.getContent() != null ? revNew.getContent().getBytes() : new byte[0]; // @todo implement it handling of binary files uploadItems.add(new UploadItem(fileUrl, byteOld, byteNew)); } catch (VcsException e) { throw new RuntimeException(e); } } return uploadItems; }
From source file:com.github.walterfan.util.http.URLHelper.java
public static String getPathAndQuery(String strUrl) { try {/*from www . ja v a 2 s .com*/ URL url = new URL(strUrl); //System.out.println("url=" + url); String path = url.getPath(); String query = url.getQuery(); if (StringUtils.isNotBlank(query)) { path = path + "?" + query; } if (path.startsWith("/")) { return path.substring(1); } } catch (MalformedURLException e) { e.printStackTrace(); } return ""; }
From source file:com.katsu.dwm.reflection.JarUtils.java
public static File getRootApplicationContentPath() { URLClassLoader sysloader = (URLClassLoader) JarUtils.class.getClassLoader(); URL[] urls = sysloader.getURLs(); String classesPath = "WEB-INF/classes/"; if (urls != null) { for (URL url : urls) { try { if (url.getPath().endsWith(classesPath)) { return new File(url.toURI()).getParentFile().getParentFile(); }//w w w . j ava 2s . co m } catch (Exception e) { logger.error(e); } } } return null; }
From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java
public static String absolutize(String url, String confluenceRootUrl) { try {//from w ww. ja va2s. c om new URL(url); //already absolute return url; } catch (MalformedURLException e) { } try { URL context = new URL(confluenceRootUrl); String contextPath = context.getPath(); if (!url.startsWith(contextPath)) { //the url does NOT start with context path: it is meant to be //relative to the context url = contextPath + url; } URL absolute = new URL(context, url); return absolute.toURI().normalize().toString(); } catch (MalformedURLException e) { return url; } catch (URISyntaxException e) { return url; } }
From source file:com.moss.appkeep.tools.cache.SimpleAppkeepComponentCache.java
private static String dirNameForUrl(String url) { try {/*from w w w . ja v a2 s.com*/ URL u = new URL(url); return u.getProtocol() + "_" + u.getHost() + "_" + u.getPort() + "_" + u.getPath().replaceAll(Pattern.quote("/"), "_"); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static BitmapDrawable getBitmapDrawableFromUrl(Resources res, URL trueUrl, BitmapFactory.Options mOptions) throws Exception { Bitmap bitmap = null;/* ww w . java2s . c o m*/ FileInputStream mFS = null; try { mFS = new FileInputStream(trueUrl.getPath()); bitmap = BitmapFactory.decodeFileDescriptor(mFS.getFD(), null, mOptions); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (mFS != null) { mFS.close(); } } return new BitmapDrawable(res, bitmap); }
From source file:org.commonjava.maven.galley.transport.htcli.internal.HttpListing.java
static boolean isSubpath(final URL url, final String linkHref) { String linkPath;//from w ww . j a v a2 s .c om try { URL linkUrl = new URL(linkHref); linkPath = linkUrl.getPath(); } catch (MalformedURLException ex) { linkPath = linkHref; } boolean valid = linkPath.length() > 0 && (((linkPath.charAt(0) != '/') && (linkPath.charAt(0) != '.')) || linkPath.startsWith(url.getPath())); Logger logger = LoggerFactory.getLogger(HttpListing.class); logger.debug("Does URL: {} (linkPath: {}) reference a sub-path of: {}? {}", linkHref, linkPath, url.getPath(), valid); return valid; }