Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:com.thoughtworks.go.util.command.UrlUserInfo.java

public static boolean hasUserInfo(String url) {
    try {/*from w  ww.  j  a  v a2 s.  c o m*/
        return isNotBlank(new URI(url).getUserInfo());
    } catch (URISyntaxException e) {
        return false;
    }
}

From source file:ch.ethz.inf.vs.hypermedia.client.Utils.java

public static String resolve(String base, String... relativePaths) throws URISyntaxException {
    URI uri = new URI(base);
    for (String relativePath : relativePaths) {
        if (relativePath != null) {
            uri = URIUtils.resolve(uri, relativePath);
        }//from   ww w .ja  va 2 s. c om
    }
    return uri.toString();
}

From source file:fr.digitbooks.android.examples.chapitre08.DigibooksRatingApi.java

public static String requestRatings(int count, String format) {
    String response = null;/*from   ww w  .  ja va2s  .c  o  m*/
    StringBuffer stringBuffer = new StringBuffer();
    BufferedReader bufferedReader = null;
    try {
        // Cration d'une requ?te de type GET
        HttpGet httpGet = new HttpGet();
        URI uri = new URI(Config.URL_SERVER + "data?count=" + count + "&format=" + format);
        httpGet.setURI(uri);
        // Cration d'une connexion
        AndroidHttpClient httpClient = AndroidHttpClient.newInstance("");
        HttpResponse httpResponse = httpClient.execute(httpGet);
        // Traitement de la rponse
        InputStream inputStream = httpResponse.getEntity().getContent();
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 1024);
        String readLine = bufferedReader.readLine();
        while (readLine != null) {
            stringBuffer.append(readLine);
            readLine = bufferedReader.readLine();
        }
        httpClient.close();
    } catch (Exception e) {
        Log.e(LOG_TAG, "IOException trying to execute request for " + e);
        return null;
    } finally {
        if (bufferedReader != null) {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                return null;
            }
        }
        response = stringBuffer.toString();
        if (Config.INFO_LOGS_ENABLED) {
            Log.i(LOG_TAG, "Reponse = " + response);
        }
    }

    return response;
}

From source file:f1db.configuration.ProductionProfile.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));
    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);/*from w  w  w.j  av a2 s .c  om*/
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    return basicDataSource;
}

From source file:bibibi.configs.ProductionProfile.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));

    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);//from  www.j  a v a  2  s .  com
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    return basicDataSource;
}

From source file:Main.java

public InputSource resolveEntity(String publicId, String systemId) {
    try {/*from  ww w.  j a  v a 2s  .  c  o  m*/
        URI uri = new URI(systemId);
        if ("file".equals(uri.getScheme())) {
            String filename = uri.getSchemeSpecificPart();
            return new InputSource(new FileReader(filename));
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:org.thoughtcrime.securesms.mms.MmsSendHelper.java

private static byte[] makePost(MmsConnectionParameters parameters, byte[] mms)
        throws ClientProtocolException, IOException {
    Log.w("MmsSender", "Sending MMS1 of length: " + mms.length);
    try {//www  .  ja  v a2  s .  c o  m
        HttpClient client = constructHttpClient(parameters);
        URI hostUrl = new URI(parameters.getMmsc());
        HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
        HttpPost request = new HttpPost(parameters.getMmsc());
        ByteArrayEntity entity = new ByteArrayEntity(mms);

        entity.setContentType("application/vnd.wap.mms-message");

        request.setEntity(entity);
        request.setParams(client.getParams());
        request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");

        HttpResponse response = client.execute(target, request);
        StatusLine status = response.getStatusLine();

        if (status.getStatusCode() != 200)
            throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());

        return parseResponse(response.getEntity());
    } catch (URISyntaxException use) {
        Log.w("MmsDownlader", use);
        throw new IOException("Bad URI syntax");
    }
}

From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.MachineRestController.java

public static MachineDTO machineDetails(Long id) throws URISyntaxException {
    String url = MACHINE_URL + id;
    HttpEntity re = rt.exchange(new URI(url), HttpMethod.GET, new HttpEntity<>(httpHeaders), MachineDTO.class);
    return (MachineDTO) re.getBody();
}

From source file:eu.trentorise.smartcampus.portfolio.utils.NetUtility.java

public static Bitmap loadBitmapfromUrl(String imageUrl) {
    Bitmap resultImage = null;//from  www.ja v  a 2  s . c o  m
    HttpGet getRequest = new HttpGet();
    try {
        URI imageURI = new URI(imageUrl);
        getRequest.setURI(imageURI);
        HttpClient httpClient = HttpClientFactory.INSTANCE.getThreadSafeHttpClient();
        HttpResponse response = httpClient.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w(NetUtility.class.getName(), "Error: " + statusCode + " image url: " + imageUrl);
        } else {
            final HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream inputStream = null;
                try {
                    inputStream = new FlushedInputStream(entity.getContent());
                    resultImage = BitmapFactory.decodeStream(inputStream);
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    entity.consumeContent();
                }
            }
        }
    } catch (Exception e) {
        getRequest.abort();
        e.printStackTrace();
        Log.w(NetUtility.class.getName(), "Error image url: " + imageUrl);
    }
    return resultImage;
}

From source file:org.apache.bigtop.bigpetstore.qstream.Utils.java

public static HttpResponse get(String hostnam) throws Exception {
    URI uri = new URI(hostnam);
    return get(uri);
}