Package java.net

Examples of java.net.URI.normalize()


    }

  private static String normalize(String path) {
    try {
      URI uri =  new URI(path);
      String normalized = uri.normalize().toString();
      return normalized;
    } catch (URISyntaxException e) {
      e.printStackTrace();
      return null;
    }
View Full Code Here


     * place to store the output from a number of map-reduce tasks.
     */
    public static String makeStoreTmpPath(String orig) {
        Path path = new Path(orig);
        URI uri = path.toUri();
        uri.normalize();

        String pathStr = uri.getPath();
        if (path.isAbsolute()) {
            return new Path("abs"+pathStr).toString();
        } else {
View Full Code Here

            URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                    url.getRef());

            // it is possible that the original url was already (partial) escaped,
            // so we must unescape all '%' followed by 2 hexadecimals...
            String uriString = uri.normalize().toASCIIString();

            // manually escape the '+' character
            uriString = uriString.replaceAll("\\+", "%2B");

            return ESCAPE_PATTERN.matcher(uriString).replaceAll("%$1");
View Full Code Here

     * place to store the output from a number of map-reduce tasks.
     */
    public static String makeStoreTmpPath(String orig) {
        Path path = new Path(orig);
        URI uri = path.toUri();
        uri.normalize();

        String pathStr = uri.getPath();
        if (path.isAbsolute()) {
            return new Path("abs"+pathStr).toString();
        } else {
View Full Code Here

                "/a/..b/c", "/a/b..c/d", "", "a", "a/b", "a/b/c", "../", "",
                "..", "../g", "b/c/g", "../c/e", "../c/", };

        for (int i = 0; i < normalizeData.length; i++) {
            URI test = new URI(normalizeData[i]);
            String result = test.normalize().toString();
            assertEquals("Normalized incorrectly, ", normalizeResults[i],
                    result.toString());
        }
    }
View Full Code Here

     * @tests java.net.URI#normalize()
     */
    public void test_normalize2() throws URISyntaxException {
        URI uri1 = null, uri2 = null;
        uri1 = new URI("file:/D:/one/two/../../three");
        uri2 = uri1.normalize();

        assertEquals("Normalized to incorrect URI", "file:/D:/three", uri2
                .toString());
        assertTrue("Resolved URI is not absolute", uri2.isAbsolute());
        assertFalse("Resolved URI is opaque", uri2.isOpaque());
View Full Code Here

     */
    public void test_normalize3() throws URISyntaxException {
        // return same URI if it has a normalized path already
        URI uri1 = null, uri2 = null;
        uri1 = new URI("http://host/D:/one/two/three");
        uri2 = uri1.normalize();
        assertSame("Failed to return same URI after normalization", uri1, uri2);

        // try with empty path
        uri1 = new URI("http", "host", null, "fragment");
        uri2 = uri1.normalize();
View Full Code Here

        uri2 = uri1.normalize();
        assertSame("Failed to return same URI after normalization", uri1, uri2);

        // try with empty path
        uri1 = new URI("http", "host", null, "fragment");
        uri2 = uri1.normalize();
        assertSame("Failed to return same URI after normalization", uri1, uri2);
    }

    /**
     * @tests java.net.URI#parseServerAuthority()
View Full Code Here

      throw new UnsupportedIdException(blobId,
          "Id must specify a relative path");
    try {
      // insert a '/' so java.net.URI normalization works
      URI tmp = new URI(scheme + ":/" + path);
      String nPath = tmp.normalize().getRawSchemeSpecificPart()
          .substring(1);
      if (nPath.equals("..") || nPath.startsWith("../"))
        throw new UnsupportedIdException(blobId,
            "Id cannot be outside top-level directory");
      return new URI(scheme + ":" + nPath);
View Full Code Here

    if (path.startsWith("/"))
      throw new UnsupportedIdException(blobId, "Id must specify a relative path");
    try {
      // insert a '/' so java.net.URI normalization works
      URI tmp = new URI(scheme + ":/" + path);
      String nPath = tmp.normalize().getRawSchemeSpecificPart().substring(1);
      if (nPath.equals("..") || nPath.startsWith("../"))
        throw new UnsupportedIdException(blobId, "Id cannot be outside top-level directory");
      if (nPath.endsWith("/"))
        throw new UnsupportedIdException(blobId, "Id cannot specify a directory");
      return new URI(scheme + ":" + nPath);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.