Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

In this page you can find the example usage for java.net URI toString.

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:com.semagia.cassa.client.GraphClient.java

private static MediaType guessMediaType(final URI uri) {
    MediaType result = null;// ww w.  jav  a  2 s .co  m
    final String uri_ = uri.toString();
    final int dotIdx = uri_.lastIndexOf('.');
    final String ext = dotIdx > -1 ? uri_.substring(dotIdx + 1) : null;
    if (ext != null) {
        final Syntax syntax = Syntax.forFileExtension(ext);
        result = syntax != null ? MediaType.valueOf(syntax.getDefaultMIMEType()) : null;
    }
    return result;
}

From source file:com.aptana.core.epl.downloader.RepositoryStatusHelper.java

/**
 * Translates exceptions representing "FileNotFound" into FileNotFoundException.
 * //from w  ww.  j  a  v a 2  s.  c  o  m
 * @param t
 *            the throwable to check
 * @param toDownload
 *            the URI the exception was thrown for
 * @throws FileNotFoundException
 *             if 't' represents a file not found
 */
public static void checkFileNotFound(Throwable t, URI toDownload) throws FileNotFoundException {
    if (t instanceof IncomingFileTransferException) {
        IncomingFileTransferException e = (IncomingFileTransferException) t;
        if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300)
            throw new FileNotFoundException(toDownload.toString());
    }
    if (t instanceof BrowseFileTransferException) {
        BrowseFileTransferException e = (BrowseFileTransferException) t;
        if (e.getErrorCode() == 404 || e.getErrorCode() == 403 || e.getErrorCode() == 300)
            throw new FileNotFoundException(toDownload.toString());
    }

    if (t instanceof FileNotFoundException)
        throw (FileNotFoundException) t;
    if (t instanceof CoreException) {
        IStatus status = ((CoreException) t).getStatus();
        Throwable e = status == null ? null : status.getException();
        if (e instanceof FileNotFoundException)
            throw (FileNotFoundException) e;
    }
}

From source file:com.aliyun.oss.integrationtests.TestUtils.java

public static String composeLocation(String endpoint, String bucketName, String key) {
    try {/*from w ww .  j  av  a 2s . c o m*/
        URI baseUri = URI.create(endpoint);
        URI resultUri = new URI(baseUri.getScheme(), null, bucketName + "." + baseUri.getHost(),
                baseUri.getPort(), String.format("/%s", HttpUtil.urlEncode(key, DEFAULT_CHARSET_NAME)), null,
                null);
        return URLDecoder.decode(resultUri.toString(), DEFAULT_CHARSET_NAME);
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:org.mule.tools.rhinodo.impl.NodeModuleImplBuilder.java

private static URI getRoot(Class<?> klass, String rootDirectory) {
    ClassLoader classLoader = klass.getClassLoader();
    URI root;
    try {//from   w  w w  . j  a  va2  s  .co m
        URL resource = classLoader.getResource(rootDirectory);
        if (resource == null) {
            throw new IllegalArgumentException("Invalid resource at: " + rootDirectory);
        }
        root = resource.toURI();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    if (root == null) {
        throw new IllegalStateException("Error: path not found.");
    }

    try {
        root = new URI(root.toString() + "/");
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    return root;
}

From source file:org.keycloak.testsuite.util.SamlClient.java

/**
 * Creates a SAML login request document with the given parameters. See SAML &lt;AuthnRequest&gt; description for more details.
 *
 * @param issuer/*w w  w . ja v a  2s. c o  m*/
 * @param assertionConsumerURL
 * @param destination
 * @return
 */
public static AuthnRequestType createLoginRequestDocument(String issuer, String assertionConsumerURL,
        URI destination) {
    try {
        SAML2Request samlReq = new SAML2Request();
        AuthnRequestType loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(),
                assertionConsumerURL, destination == null ? null : destination.toString(), issuer);

        return loginReq;
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.vmware.photon.controller.common.auth.AuthClientHandler.java

/**
 * Replace the id_token part in logout URL with placeholder.
 *
 * @param logoutUri//from w  w  w .  j  av a  2s . c om
 * @throws AuthException
 */
public static URI replaceIdTokenWithPlaceholder(URI logoutUri)
        throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException {
    String placeholderValue = "";
    String keyToMatch = URLDecoder.decode(LOGOUT_URL_ID_TOKEN_START, "UTF-8");
    final String urlQuery = logoutUri.getQuery();

    if (urlQuery == null) {
        throw new IllegalArgumentException(
                String.format("Logout URL %s has invalid format", logoutUri.toString()));
    }

    final String[] queryParams = urlQuery.split("&");

    for (String param : queryParams) {
        final String[] pairs = param.split("=");
        if (pairs[0].equals(keyToMatch)) {
            placeholderValue = pairs[1];
            break;
        }
    }

    if (placeholderValue == "") {
        throw new IllegalArgumentException(
                String.format("Logout URL %s has invalid format", logoutUri.toString()));
    }

    String logoutStr = logoutUri.toString();
    return new URI(logoutStr.replace(placeholderValue, LOGOUT_URL_ID_TOKEN_PLACEHOLDER));
}

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

public static void readUtterances(RuntimeBean runtime, URI source) throws IOException {
    InputStream is = source.toURL().openStream();
    InputStreamReader rdr = new InputStreamReader(is);
    UtteranceLogic.read(runtime.getApp(), rdr);
    rdr.close();//w w w  . j  av a  2s .  c om
    runtime.firePropertyChange("app", null, runtime.getApp());
    setProp("app.utterances", source.toString());
}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

/**
 * Copy the entries specified from the bundle provided to the metadata area for the bundle provided, and return the URL for the metadata area for this bundle.
 * //w  ww.j  av  a 2 s.co  m
 * @param bundle
 * @param path
 * @param filePattern
 * @param recurse
 * @return URL
 * @throws IOException
 */
public static URL copyToMetadata(Bundle bundle, String path, String filePattern, boolean recurse)
        throws IOException {
    Location instanceLocation = Platform.getInstanceLocation();
    URL dataArea = getDataArea(instanceLocation, bundle.getSymbolicName());
    Enumeration entries = bundle.findEntries(path, filePattern, recurse);
    while (entries.hasMoreElements()) {
        URL entry = (URL) entries.nextElement();
        String entryPath = entry.getPath();
        try {
            InputStream inputStream = FileLocator.openStream(bundle, new Path(entryPath), false);
            URI dataURI = dataArea.toURI();
            URI fullPath = URI.create(dataURI.toString() + entryPath);
            File file = new File(fullPath);
            if (!file.exists()) {
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            FileOutputStream outputStream = new FileOutputStream(file);
            IOUtils.copy(inputStream, outputStream);
            outputStream.close();
        } catch (Exception e) {
            // skip this one
        }
    }
    return dataArea;
}

From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java

private static void sendRedirect(HttpServletResponse response, URI target) {
    sendRedirect(response, target.toString());
}

From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java

public static void readIntents(RuntimeBean runtime, URI source) throws IOException {
    InputStream is = source.toURL().openStream();
    InputStreamReader rdr = new InputStreamReader(is);
    ApplicationLogic.readIntents(runtime.getApp(), rdr);
    rdr.close();/* w  w  w  .j av a  2s  . c o m*/
    runtime.firePropertyChange("app", null, runtime.getApp());
    setProp("app.intents", source.toString());
}