Java Code Examples for java.net.URL#toString()

The following examples show how to use java.net.URL#toString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: wecube-platform   File: RealS3Client.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String uploadFile(String bucketName, String s3KeyName, File file) {
    if (!(s3Client.doesBucketExist(bucketName))) {
        s3Client.createBucket(new CreateBucketRequest(bucketName));
    }

    if (fileExists(bucketName, s3KeyName)) {
        throw new WecubeCoreException(String.format("File[%s] already exists", s3KeyName));
    }

    s3Client.putObject(new PutObjectRequest(bucketName, s3KeyName, file).withCannedAcl(CannedAccessControlList.Private));
    GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(bucketName, s3KeyName);
    URL url = s3Client.generatePresignedUrl(urlRequest);

    log.info("uploaded File  [{}] to S3. url = [{}]", file.getAbsolutePath(), url);
    return url.toString();
}
 
Example 2
Source Project: JFoenix   File: SVGGlyphLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * load a single svg icon from a file
 *
 * @param url of the svg icon
 * @return SVGGLyph node
 * @throws IOException
 */
public static SVGGlyph loadGlyph(URL url) throws IOException {
    String urlString = url.toString();
    String filename = urlString.substring(urlString.lastIndexOf('/') + 1);

    int startPos = 0;
    int endPos = 0;
    while (endPos < filename.length() && filename.charAt(endPos) != '-') {
        endPos++;
    }
    int id = Integer.parseInt(filename.substring(startPos, endPos));
    startPos = endPos + 1;

    while (endPos < filename.length() && filename.charAt(endPos) != '.') {
        endPos++;
    }
    String name = filename.substring(startPos, endPos);

    return new SVGGlyph(id, name, extractSvgPath(getStringFromInputStream(url.openStream())), Color.BLACK);
}
 
Example 3
Source Project: ache   File: LinkFilter.java    License: Apache License 2.0 6 votes vote down vote up
public boolean accept(URL link) {

        String url = link.toString();
        String domain = LinkRelevance.getTopLevelDomain(link.getHost());

        TextMatcher hostWhitelist = hostsWhitelists.get(domain);
        if (hostWhitelist != null && !hostWhitelist.matches(url)) {
            return false;
        }
        TextMatcher hostBlacklist = hostsBlacklists.get(domain);
        if (hostBlacklist != null && !hostBlacklist.matches(url)) {
            return false;
        }
        if (whitelist != null && !whitelist.matches(url)) {
            return false;
        }
        if (blacklist != null && !blacklist.matches(url)) {
            return false;
        }

        return true;
    }
 
Example 4
@NonNull
@Override
public String process(@NonNull String destination) {

    String out = destination;

    if (base != null) {
        try {
            final URL u = new URL(base, destination);
            out = u.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return out;
}
 
Example 5
Source Project: groovy   File: JsonSlurper.java    License: Apache License 2.0 6 votes vote down vote up
private Object parseURL(URL url, Map params, String charset) {
    Reader reader = null;
    try {
        if (params == null || params.isEmpty()) {
            reader = ResourceGroovyMethods.newReader(url, charset);
        } else {
            reader = ResourceGroovyMethods.newReader(url, params, charset);
        }
        return parse(reader);
    } catch (IOException ioe) {
        throw new JsonException("Unable to process url: " + url.toString(), ioe);
    } finally {
        if (reader != null) {
            DefaultGroovyMethodsSupport.closeWithWarning(reader);
        }
    }
}
 
Example 6
Source Project: netbeans   File: SelectRootsPanel.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
private static String getDisplayName(@NonNull final URL root) {
    final File f = FileUtil.archiveOrDirForURL(root);
    return f == null ?
        root.toString() :
        f.isFile() ?
            f.getName() :
            f.getAbsolutePath();
}
 
Example 7
Request(Session session, URL overriddenURL) {
    this.session = session;
    this.overriddenURL = overriddenURL.toString();

    setHttpMethod(HttpMethod.GET);

    this.parameters = new Bundle();
}
 
Example 8
Source Project: incubator-tajo   File: HttpServer.java    License: Apache License 2.0 5 votes vote down vote up
protected String getWebAppsPath(String name) throws FileNotFoundException {
  URL url = getClass().getClassLoader().getResource("webapps/" + name);
  if (url == null) {
    throw new FileNotFoundException("webapps/" + name + " not found in CLASSPATH");
  }
  String urlString = url.toString();
  return urlString.substring(0, urlString.lastIndexOf('/'));
}
 
Example 9
@Override
protected URLConnection openConnection(URL url) throws IOException {
    String s = url.toString();
    int index = s.indexOf("!/");
    if (index == -1)
        throw new MalformedURLException("no !/ found in url spec:" + s);

    throw new IOException("Can't connect to jmod URL");
}
 
Example 10
private Test(URL base, String spec) {
    testCount++;
    try {
        url = new URL(base, spec);
    } catch (Exception x) {
        exc = x;
    }
    if (url != null)
        input = url.toString();
    originalURL = url;
}
 
Example 11
Source Project: sis   File: MetadataCommandTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests with the same file than {@link #testNetCDF()}, but producing a XML output.
 *
 * @throws Exception if an error occurred while creating the command.
 */
@Test
@Ignore("Requires GeoAPI 3.1")
@DependsOnMethod("testNetCDF")
public void testFormatXML() throws Exception {
    final URL url = new URL("Cube2D_geographic_packed.nc") ; // TestData.NETCDF_2D_GEOGRAPHIC.location();
    final MetadataCommand test = new MetadataCommand(0, CommandRunner.TEST, url.toString(), "--format", "XML");
    test.run();
    verifyNetCDF("<?xml", test.outputBuffer.toString());
}
 
Example 12
public static Permission getConnectPermission(URL url) throws IOException {
    String urlStringLowerCase = url.toString().toLowerCase();
    if (urlStringLowerCase.startsWith("http:") || urlStringLowerCase.startsWith("https:")) {
        return getURLConnectPermission(url);
    } else if (urlStringLowerCase.startsWith("jar:http:") || urlStringLowerCase.startsWith("jar:https:")) {
        String urlString = url.toString();
        int bangPos = urlString.indexOf("!/");
        urlString = urlString.substring(4, bangPos > -1 ? bangPos : urlString.length());
        URL u = new URL(urlString);
        return getURLConnectPermission(u);
        // If protocol is HTTP or HTTPS than use URLPermission object
    } else {
        return url.openConnection().getPermission();
    }
}
 
Example 13
@Test
public void testGenerateGetAgreement() throws Exception {
    server.enqueue(new MockResponse().
            setBody(readFile("/eu/seaclouds/planner/core/application/agreements/sla-create-agreement-response.xml")));
    server.start();
    URL url = server.url("/").url();

    AgreementGenerator generator = new AgreementGenerator(url.toString());
    String result = generator.getAgreement("templateId");

    assertNotNull(result);
}
 
Example 14
Source Project: netbeans   File: DDProvider.java    License: Apache License 2.0 5 votes vote down vote up
public InputSource resolveEntity(String publicId, String systemId) {
    // return a proper input source
    String resource;
    if ("http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd".equals(systemId)) {
        resource = "/org/netbeans/modules/j2ee/dd/impl/resources/ejb-jar_2_1.xsd"; //NOI18N
    } else if ("http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd".equals(systemId)) {
        resource = "/org/netbeans/modules/j2ee/dd/impl/resources/ejb-jar_3_0.xsd"; //NOI18N
    } else {
        return null;
    }
    URL url = this.getClass().getResource(resource);
    return new InputSource(url.toString());
}
 
Example 15
Source Project: govpay   File: UrlUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static URL addParameter(URL url, String paramName, String paramValue) throws MalformedURLException {
	String urlString = url.toString();
	if(urlString.contains("?")) {
		if(urlString.endsWith("&")) 
			urlString = urlString + paramName + "=" + paramValue;
		else
			urlString = urlString + "&" + paramName + "=" + paramValue;
	} else {
		urlString = urlString + "?" + paramName + "=" + paramValue;
	}
	return new URL(urlString);
}
 
Example 16
Source Project: flowable-engine   File: ContentEngines.java    License: Apache License 2.0 5 votes vote down vote up
protected static void initContentEngineFromSpringResource(URL resource) {
    try {
        Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.flowable.content.spring.SpringContentConfigurationHelper");
        Method method = springConfigurationHelperClass.getDeclaredMethod("buildContentEngine", new Class<?>[] { URL.class });
        ContentEngine contentEngine = (ContentEngine) method.invoke(null, new Object[] { resource });

        String contentEngineName = contentEngine.getName();
        EngineInfo contentEngineInfo = new EngineInfo(contentEngineName, resource.toString(), null);
        contentEngineInfosByName.put(contentEngineName, contentEngineInfo);
        contentEngineInfosByResourceUrl.put(resource.toString(), contentEngineInfo);

    } catch (Exception e) {
        throw new FlowableException("couldn't initialize content engine from spring configuration resource " + resource + ": " + e.getMessage(), e);
    }
}
 
Example 17
Source Project: olca-app   File: HtmlFolder.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public static String getUrl(Bundle bundle, String page) {
	File file = getFile(bundle, page);
	if (file == null)
		return null;
	try {
		URL url = file.toURI().toURL();
		return url.toString();
	} catch (Exception e) {
		log.error("failed to get URL for page " + bundle + "/" + page, e);
		return null;
	}
}
 
Example 18
Source Project: disconf   File: RestfulGet.java    License: Apache License 2.0 5 votes vote down vote up
public RestfulGet(Class<T> clazz, URL url) {

        HttpGet request = new HttpGet(url.toString());
        request.addHeader("content-type", "application/json");
        this.request = request;
        this.httpResponseCallbackHandler = new
                HttpResponseCallbackHandlerJsonHandler<T>(clazz);
    }
 
Example 19
static Image getImageFromHash(Toolkit tk, URL url) {
    checkPermissions(url);
    synchronized (urlImgCache) {
        String key = url.toString();
        Image img = (Image)urlImgCache.get(key);
        if (img == null) {
            try {
                img = tk.createImage(new URLImageSource(url));
                urlImgCache.put(key, img);
            } catch (Exception e) {
            }
        }
        return img;
    }
}
 
Example 20
Source Project: Strata   File: ResourceLocator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a resource from a {@code URL}.
 * 
 * @param url  the URL to wrap
 * @return the resource locator
 */
public static ResourceLocator ofClasspathUrl(URL url) {
  ArgChecker.notNull(url, "url");
  String locator = CLASSPATH_URL_PREFIX + url.toString();
  return new ResourceLocator(locator, UriByteSource.of(url));
}