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:cat.calidos.morfeu.model.injection.URIToParsedModule.java

@Produces
@Named("FetchedRawContent")
public static InputStream fetchedRawContent(@Named("FetchableContentURI") URI uri) throws FetchingException {

    // if uri is absolute we retrieve it, otherwise we assume it's a local relative file

    try {//from ww  w  .  j  a v  a 2 s .  c  om
        if (uri.isAbsolute()) {
            log.info("Fetching absolute content uri '{}' to parse", uri);
            return IOUtils.toInputStream(IOUtils.toString(uri, Config.DEFAULT_CHARSET), Config.DEFAULT_CHARSET);
        } else {
            log.info("Fetching relative content uri '{}' to parse, assuming file", uri);
            return FileUtils.openInputStream(new File(uri.toString()));
        }
    } catch (IOException e) {
        log.error("Could not fetch '{}' ({}", uri, e);
        throw new FetchingException("Problem when fetching '" + uri + "'", e);
    }
}

From source file:edu.stanford.junction.android.AndroidJunctionMaker.java

/**
 * Returns an Intent than can be used to join a Junction activity.
 * If you want a specific class to handle this intent,
 * you can specify the package/class on the returned
 * Intent before using it to start an activity.
 * /*from w w  w . jav a 2  s  .com*/
 * @param junctionInvitation
 * @return
 */
public static Intent getIntentForActivityJoin(URI junctionInvitation) {
    Intent launchIntent = new Intent(Intents.ACTION_JOIN);
    launchIntent.putExtra("junctionVersion", 1);
    //launchIntent.putExtra("activityDescriptor", invitation.toString());
    // TODO: keep URI?
    launchIntent.putExtra(Intents.EXTRA_ACTIVITY_SESSION_URI, junctionInvitation.toString());

    return launchIntent;
}

From source file:com.simiacryptus.util.Util.java

/**
 * Cache file file.//  www . j a  v a 2 s  .  c om
 *
 * @param url the url
 * @return the file
 * @throws IOException              the io exception
 * @throws NoSuchAlgorithmException the no such algorithm exception
 * @throws KeyStoreException        the key store exception
 * @throws KeyManagementException   the key management exception
 */
public static File cacheFile(@javax.annotation.Nonnull final URI url)
        throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    return com.simiacryptus.util.Util.cacheFile(url.toString(), new File(url.getPath()).getName());
}

From source file:com.simiacryptus.util.Util.java

/**
 * Cache input stream.// w w w  .  j  a  va  2s .  c om
 *
 * @param url the url
 * @return the input stream
 * @throws IOException              the io exception
 * @throws NoSuchAlgorithmException the no such algorithm exception
 * @throws KeyStoreException        the key store exception
 * @throws KeyManagementException   the key management exception
 */
public static InputStream cacheStream(@javax.annotation.Nonnull final URI url)
        throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    return com.simiacryptus.util.Util.cacheStream(url.toString(), new File(url.getPath()).getName());
}

From source file:org.fcrepo.camel.FedoraClient.java

/**
 * Build a HttpOperationFailedException object from an http response
 *///from  ww w.  j a v a  2s .c o  m
protected static HttpOperationFailedException buildHttpOperationFailedException(final URI url,
        final HttpResponse response) throws IOException {

    final int status = response.getStatusLine().getStatusCode();
    final Header locationHeader = response.getFirstHeader("location");
    final HttpEntity entity = response.getEntity();
    String locationValue = null;

    if (locationHeader != null && (status >= 300 && status < 400)) {
        locationValue = locationHeader.getValue();
    }

    return new HttpOperationFailedException(url.toString(), status, response.getStatusLine().getReasonPhrase(),
            locationValue, extractResponseHeaders(response.getAllHeaders()),
            entity != null ? EntityUtils.toString(entity) : null);
}

From source file:com.microsoft.tfs.client.common.credentials.CredentialsHelper.java

public static Credentials getOAuthCredentials(final URI serverURI, final JwtCredentials accessToken,
        final Action<DeviceFlowResponse> callback) {
    removeStaleOAuth2Token();/*from  ww w. ja  v  a 2s  .c  o  m*/

    final Authenticator authenticator;
    final OAuth2Authenticator oauth2Authenticator = OAuth2Authenticator.getAuthenticator(CLIENT_ID,
            REDIRECT_URL, accessTokenStore, callback);
    final Token token;

    if (serverURI != null) {
        log.debug("Interactively retrieving credential based on oauth2 flow for " + serverURI.toString()); //$NON-NLS-1$
        log.debug("Trying to persist credential, generating a PAT"); //$NON-NLS-1$

        authenticator = new VstsPatAuthenticator(oauth2Authenticator, tokenStore);

        final String tokenKey = authenticator.getUriToKeyConversion().convert(serverURI,
                authenticator.getAuthType());
        removeStalePersonalAccessToken(tokenKey, serverURI);

        final TokenPair oauth2Token = (accessToken == null) ? null
                : new TokenPair(accessToken.getAccessToken(), "null"); //$NON-NLS-1$

        token = authenticator.getPersonalAccessToken(serverURI, VsoTokenScope.AllScopes,
                getAccessTokenDescription(serverURI.toString()), PromptBehavior.AUTO, oauth2Token);
    } else {
        log.debug("Interactively retrieving credential based on oauth2 flow for VSTS"); //$NON-NLS-1$
        log.debug("Do not try to persist, generating oauth2 token."); //$NON-NLS-1$

        authenticator = oauth2Authenticator;

        final TokenPair tokenPair = authenticator.getOAuth2TokenPair();
        token = tokenPair != null ? tokenPair.AccessToken : null;
    }

    if (token != null && token.Type != null && !StringUtil.isNullOrEmpty(token.Value)) {
        switch (token.Type) {
        case Personal:
            return new PatCredentials(token.Value);
        case Access:
            return new JwtCredentials(token.Value);
        }
    }

    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog1")); //$NON-NLS-1$
    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog2")); //$NON-NLS-1$
    log.warn(Messages.getString("CredentialsHelper.InteractiveAuthenticationFailedDetailedLog3")); //$NON-NLS-1$

    removeOAuth2Token(true);

    // Failed to get credential, return null
    return null;
}

From source file:ca.osmcanada.osvuploadr.Utils.Helper.java

public static Boolean OpenBrowser(URI uri) {
    try {/*from w  ww. j a v  a 2s  .  co m*/
        boolean supportsBrowse = true;
        if (!Desktop.isDesktopSupported()) {
            supportsBrowse = false;
            if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                supportsBrowse = false;
            }
        }

        if (supportsBrowse) {
            Desktop.getDesktop().browse(uri);
        } else {
            EnumOS os = getOs();
            if (os.isLinux()) {
                if (runCommand("kde-open", "%s", uri.toString()))
                    return true;
                if (runCommand("gnome-open", "%s", uri.toString()))
                    return true;
                if (runCommand("xdg-open", "%s", uri.toString()))
                    return true;
            }

            if (os.isMac()) {
                if (runCommand("open", "%s", uri.toString()))
                    return true;
            }

            if (os.isWindows()) {
                if (runCommand("explorer.exe", "%s", uri.toString()))
                    return true;
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    return false;
}

From source file:com.pusher.Pusher.java

/**
 * Delivers a message to the Pusher API/* ww  w . ja va  2s .co m*/
 * @param channel
 * @param event
 * @param jsonData
 * @param socketId
 * @return
 */
public static HttpResponse triggerPush(String channel, String event, String jsonData, String socketId) {
    //Build URI path
    String uriPath = buildURIPath(channel);

    //Build Request Body
    String body = getParameters(channel, event, jsonData, socketId);

    //Build query
    String query = buildQuery(event, body, socketId);
    //Generate signature
    String signature = buildAuthenticationSignature(uriPath, query);
    //Build URI
    URI uri = buildURI(uriPath, query, signature);

    //Create Google APP Engine Fetch URL service and request
    HttpPost request = new HttpPost(uri);
    request.addHeader("Content-Type", "application/json");

    try {
        StringEntity strEntity = new StringEntity(body);
        request.setEntity(strEntity);
        return HttpClientBuilder.create().build().execute(request);
    } catch (UnsupportedEncodingException e1) {
        logger.warning("Pusher request could not be send to the following URI " + uri.toString());
        return null;
    } catch (ClientProtocolException e) {
        logger.warning("Pusher request could not be send to the following URI " + uri.toString());
        return null;
    } catch (IOException e) {
        logger.warning("Pusher request could not be send to the following URI " + uri.toString());
        return null;
    }
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 * Chops uri to the max length supplied if it is longer.
 *
 * @param uri          URI object to chop
 * @param maxUriLength max number of characters acceptable
 * @return corrected or initial URI object
 *///w ww  .  java  2s.c om
public static URI chopUri(URI uri, int maxUriLength) {
    String initialURIStr = uri.toString();
    String cutURIStr = left(initialURIStr, maxUriLength);
    if (!cutURIStr.equals(initialURIStr)) {
        uri = createUri(cutURIStr);
    }
    return uri;
}

From source file:org.springsource.ide.eclipse.commons.core.SpringCoreUtils.java

public static Document parseDocument(URI deploymentDescriptor) {
    try {//from w w  w .  ja v  a  2  s  .c o m
        return getDocumentBuilder().parse(deploymentDescriptor.toString());
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}