Example usage for java.net URI create

List of usage examples for java.net URI create

Introduction

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

Prototype

public static URI create(String str) 

Source Link

Document

Creates a URI by parsing the given string.

Usage

From source file:com.arpnetworking.tsdcore.sinks.ReMetSinkTest.java

@Before
public void before() {
    _remetSinkBuilder = new ReMetSink.Builder().setName("file_sink_test").setUri(URI.create("localhost:8888"));
}

From source file:cn.com.loopj.android.http.HttpPatch.java

/**
 * @param uri target url as String/*from w ww .  j  av  a2s .c  o m*/
 * @throws IllegalArgumentException if the uri is invalid.
 */
public HttpPatch(final String uri) {
    super();
    setURI(URI.create(uri));
}

From source file:net.majorkernelpanic.streaming.misc.UriParser.java

/**
 * Configures a Session according to the given URI.
 * Here are some examples of URIs that can be used to configure a Session:
 * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul>
 * @param uri The URI//from w  w w.  ja v a  2 s.com
 * @param session The Session that will be configured
 * @throws IllegalStateException
 * @throws IOException
 */
public static void parse(String uri, Session session) throws IllegalStateException, IOException {
    boolean flash = false;
    int camera = CameraInfo.CAMERA_FACING_BACK;

    List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8");
    if (params.size() > 0) {

        // Those parameters must be parsed first or else they won't necessarily be taken into account
        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // FLASH ON/OFF
            if (param.getName().equals("flash")) {
                if (param.getValue().equals("on"))
                    flash = true;
                else
                    flash = false;
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equals("camera")) {
                if (param.getValue().equals("back"))
                    camera = CameraInfo.CAMERA_FACING_BACK;
                else if (param.getValue().equals("front"))
                    camera = CameraInfo.CAMERA_FACING_FRONT;
            }

            // MULTICAST -> the stream will be sent to a multicast group
            // The default mutlicast address is 228.5.6.7, but the client can specify one 
            else if (param.getName().equals("multicast")) {
                session.setRoutingScheme(Session.MULTICAST);
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    session.setDestination(InetAddress.getByName("228.5.6.7"));
                }
            }

            // UNICAST -> the client can use this so specify where he wants the stream to be sent
            else if (param.getName().equals("unicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        session.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid destination address !");
                    }
                }
            }

            // TTL -> the client can modify the time to live of packets
            // By default ttl=64
            else if (param.getName().equals("ttl")) {
                if (param.getValue() != null) {
                    try {
                        int ttl = Integer.parseInt(param.getValue());
                        if (ttl < 0)
                            throw new IllegalStateException("The TTL must be a positive integer !");
                        session.setTimeToLive(ttl);
                    } catch (Exception e) {
                        throw new IllegalStateException("The TTL must be a positive integer !");
                    }
                }
            }

            // No tracks will be added to the session
            else if (param.getName().equals("stop")) {
                return;
            }

        }

        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // H264
            if (param.getName().equals("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H264, camera, quality, flash);
            }

            // H263
            else if (param.getName().equals("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                session.addVideoTrack(Session.VIDEO_H263, camera, quality, flash);
            }

            // AMRNB
            else if (param.getName().equals("amrnb") || param.getName().equals("amr")) {
                session.addAudioTrack(Session.AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equals("aac")) {
                session.addAudioTrack(Session.AUDIO_AAC);
            }

            // Generic Audio Stream -> make use of api level 12
            // TODO: Doesn't work :/
            else if (param.getName().equals("testnewapi")) {
                session.addAudioTrack(Session.AUDIO_ANDROID_AMR);
            }

        }

        // The default behavior is to only add one video track
        if (session.getTrackCount() == 0) {
            session.addVideoTrack();
            session.addAudioTrack();
        }

    }
    // Uri has no parameters: the default behavior is to only add one video track
    else {
        session.addVideoTrack();
        session.addAudioTrack();
    }
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.HttpResponseValidator.java

@Override
public void validate(IValidatable<String> validatable) {
    try {//from www. java2  s.c o  m
        if (!checkValidityOfUri(URI.create(validatable.getValue()))) {
            ValidationError error = new ValidationError();
            if (status == null) {
                error.setMessage(String.format("There was an unkown issue when trying to connect to '%s'",
                        validatable.getValue()));
            } else {
                error.setMessage(String.format("'%s' received invalid HTTP response: HTTP %d %s",
                        validatable.getValue(), status.getStatusCode(), status.getReasonPhrase()));
            }
            validatable.error(error);
        }
    } catch (UnknownHostException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("Unkown host: '%s'", validatable.getValue()));
        validatable.error(error);
    } catch (IOException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("There was an I/O issue when trying to connect to '%s': %s",
                validatable.getValue(), ex.getMessage()));
        validatable.error(error);
    } catch (IllegalArgumentException ex) {
        ValidationError error = new ValidationError();
        error.setMessage(String.format("Invalid URI: '%s'", validatable.getValue()));
        validatable.error(error);
    }
}

From source file:com.msopentech.odatajclient.engine.utils.URIUtils.java

/**
 * Build URI starting from the given base and href.
 * <br/>/*from  w  w w.  j  ava 2  s.  c  o m*/
 * If href is absolute or base is null then base will be ignored.
 *
 * @param base URI prefix.
 * @param href URI suffix.
 * @return built URI.
 */
public static URI getURI(final String base, final String href) {
    if (href == null) {
        throw new IllegalArgumentException("Null link provided");
    }

    URI uri = URI.create(href);

    if (!uri.isAbsolute() && base != null) {
        uri = URI.create(base + "/" + href);
    }

    return uri.normalize();
}

From source file:eu.openanalytics.rpooli.RPooliNode.java

public RPooliNode(final ObjectPoolItem item) {
    this.item = Validate.notNull(item, "item can't be null");
    this.object = (PoolObject) item.getObject();
    this.address = URI.create(this.object.getAddress().toString());
    this.id = strip(address.getPath(), "/");
}

From source file:org.commonjava.cartographer.result.ProjectPathTest.java

@Test
public void jsonRoundTrip() throws Exception {
    ProjectVersionRef ref = new SimpleProjectVersionRef("org.foo", "bar", "1");
    ProjectPath in = new ProjectPath(Collections.singletonList(new SimpleParentRelationship(
            URI.create("http://nowhere.com"), ref, new SimpleProjectVersionRef("org.dep", "project", "1.1"))));

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModules(new ProjectVersionRefSerializerModule(), new ProjectRelationshipSerializerModule());
    mapper.enable(SerializationFeature.INDENT_OUTPUT);

    String json = mapper.writeValueAsString(in);

    System.out.println(json);//from w w  w .  ja v a 2  s.c  o m

    ProjectPath out = mapper.readValue(json, ProjectPath.class);
}

From source file:azkaban.storage.HdfsStorageTest.java

@Before
public void setUp() throws Exception {
    this.hdfs = mock(FileSystem.class);
    this.hdfsAuth = mock(HdfsAuth.class);
    final AzkabanCommonModuleConfig config = mock(AzkabanCommonModuleConfig.class);
    when(config.getHdfsRootUri()).thenReturn(URI.create("hdfs://localhost:9000/path/to/foo"));

    this.hdfsStorage = new HdfsStorage(this.hdfsAuth, this.hdfs, config);
}

From source file:de.codecentric.boot.admin.notify.PagerdutyNotifierTest.java

@Before
public void setUp() {
    restTemplate = mock(RestTemplate.class);
    notifier = new PagerdutyNotifier();
    notifier.setServiceKey("--service--");
    notifier.setClient("TestClient");
    notifier.setClientUrl(URI.create("http://localhost"));
    notifier.setRestTemplate(restTemplate);
}

From source file:org.digidoc4j.impl.bdoc.SKOcspDataLoader.java

@Override
public byte[] post(final String url, final byte[] content) throws DSSException {
    logger.info("Getting OCSP response from " + url);

    HttpPost httpRequest = null;//from   w  w  w  . j  a  va  2  s.com
    HttpResponse httpResponse = null;

    try {
        final URI uri = URI.create(url.trim());
        httpRequest = new HttpPost(uri);
        httpRequest.setHeader("User-Agent", userAgent);

        // The length for the InputStreamEntity is needed, because some receivers (on the other side) need this information.
        // To determine the length, we cannot read the content-stream up to the end and re-use it afterwards.
        // This is because, it may not be possible to reset the stream (= go to position 0).
        // So, the solution is to cache temporarily the complete content data (as we do not expect much here) in a byte-array.
        final ByteArrayInputStream bis = new ByteArrayInputStream(content);

        final HttpEntity httpEntity = new InputStreamEntity(bis, content.length);
        final HttpEntity requestEntity = new BufferedHttpEntity(httpEntity);
        httpRequest.setEntity(requestEntity);
        if (contentType != null) {
            httpRequest.setHeader(CONTENT_TYPE, contentType);
        }

        httpResponse = getHttpResponse(httpRequest, url);

        final byte[] returnedBytes = readHttpResponse(url, httpResponse);
        return returnedBytes;
    } catch (IOException e) {
        throw new DSSException(e);
    } finally {
        if (httpRequest != null) {
            httpRequest.releaseConnection();
        }
        if (httpResponse != null) {
            EntityUtils.consumeQuietly(httpResponse.getEntity());
        }
    }
}