Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

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

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:com.othermedia.exampleasyncimage.AsyncImageDemo.java

public static String stringFromURL(String address) throws Exception {

    StringBuilder result = new StringBuilder();
    URL url = new URL(address);
    HttpGet httpRequest = new HttpGet(url.toURI());
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(response.getEntity());
    InputStream input = bufHttpEntity.getContent();

    BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));

    String line;//from  w  w  w . j a  v a  2  s  .c  om
    while ((line = reader.readLine()) != null) {
        result.append(line);
    }
    reader.close();

    return result.toString();
}

From source file:com.centeractive.ws.builder.MessageComplianceTest.java

public static String getContent(String folderPath, String fileName) {
    URL fileUrl = ResourceUtils.getResourceWithAbsolutePackagePath(folderPath, fileName);
    File file = null;// w  ww  .j  a v a 2  s .co  m
    try {
        file = new File(fileUrl.toURI());
    } catch (URISyntaxException e) {
        file = new File(fileUrl.getPath());
    }
    try {
        return FileUtils.readFileToString(file);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:azkaban.database.AzkabanDatabaseSetupTest.java

@BeforeClass
public static void setupDB() throws IOException, URISyntaxException {
    URL resourceUrl = Resources.getResource("sql");
    assertNotNull(resourceUrl);/*from w  w  w.  jav  a  2 s  . co m*/
    sqlScriptsDir = new File(resourceUrl.toURI()).getCanonicalPath();
}

From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java

/**
 * Extracts the URL part relative to Confluence's root URL, given a variety of input formats, e.g.:
 * <ol>//from   ww  w . j a  va 2  s .  c  om
 * <li><code>/confluence/download/attachments/983042/image.png?version=1&amp;modificationDate=1327402370523</code> (image)</li>
 * <li><code>/confluence/download/thumbnails/983042/image.png</code> (thumbnail)</li>
 * <li><code>http://localhost:1990/confluence/download/attachments/983042/image.png</code> (image)</li>
 * <li><code>/confluence/download/attachments/983042/pom.xml?version=1&amp;modificationDate=1327402370710</code> (attachment)</li>
 * <li><code>/confluence/download/attachments/983042/armonia.png?version=1&amp;modificationDate=1327402370523</code> (image as attachment)</li>
 * </ol>
 */
public static String extractConfluenceRelativePath(String url, String confluenceRootUrl) {
    try {
        URL context = new URL(confluenceRootUrl);
        URL absolute = new URL(context, url);
        URI relative = context.toURI().relativize(absolute.toURI());
        URI confluencePath = ROOT.resolve(relative);
        return confluencePath.getPath();
    } catch (MalformedURLException e) {
        return url;
    } catch (URISyntaxException e) {
        return url;
    }
}

From source file:com.vilt.minium.prefs.AppPreferences.java

private static File getDefaultPrefsFile() {
    try {//from  ww  w  .j a  va2 s. c  om
        if (System.getProperty(MINIUM_HOME_KEY) == null) {
            URL resource = AppPreferences.class.getClassLoader().getResource("minium-prefs.json");
            return new File(resource.toURI());
        } else {
            return new File(System.getProperty(MINIUM_HOME_KEY), "minium-prefs.json");
        }
    } catch (URISyntaxException e) {
        throw propagate(e);
    }
}

From source file:eu.eubrazilcc.lvl.oauth2.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllJUnitTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;//from w  w w .j a v  a2 s.  c  om
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:Main.java

public static void transform(InputStream doc, URL xsltUrl, OutputStream out)
        throws URISyntaxException, TransformerException {
    StreamSource source = new StreamSource(doc);
    StreamSource xslt = new StreamSource(new File(xsltUrl.toURI()));
    TransformerFactory fac = TransformerFactory.newInstance();
    Transformer t = fac.newTransformer(xslt);
    Result result = new StreamResult(out);
    t.transform(source, result);/*from w  w  w .  j a v  a2 s.com*/
}

From source file:eu.eubrazilcc.lvl.core.AllTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllTests.setup()");
    final URL anchorURL = AllTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;/*  w ww. j  a va 2s  . c om*/
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.storage.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;/*w  w  w.j  av a 2  s.c o m*/
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.storage.AllIntegrationTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllIntegrationTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;//w  w  w.  j  av  a  2 s .  c  om
    try {
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}