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.boundary.sdk.event.notification.AlarmNotification.java

public static AlarmNotification load(String resource) throws URISyntaxException {
    AlarmNotification instance = new AlarmNotification();

    ClassLoader classLoader = instance.getClass().getClassLoader();
    URL url = classLoader.getResource(resource);
    File file = new File(url.toURI());

    ObjectMapper mapper = new ObjectMapper();

    try {//from   w  ww  . j  a v a 2  s.c om
        instance = mapper.readValue(file, AlarmNotification.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return instance;
}

From source file:bit.changepurse.wdk.util.CheckedExceptionMethods.java

public static URI newURI(URL url) {
    try {//w  w  w.j  a va 2s . c  o  m
        return url.toURI();
    } catch (URISyntaxException | NullPointerException e) {
        throw new UncheckedException(e);
    }
}

From source file:gov.nih.nci.cacis.common.test.TestUtils.java

/**
 * Returns contents of a file as byte array
 *
 * @param fileName - URL of the source file
 * @return byte[] - content of the file as byte[]
 * @throws java.io.IOException        - IOExpetion thrown
 * @throws java.net.URISyntaxException - URISyntaxException thrown
 *//*from ww w.j a va  2 s  . co  m*/
public static byte[] getBytesFromFile(URL fileName) throws IOException, URISyntaxException {
    return FileUtils.readFileToByteArray(new File(fileName.toURI()));
}

From source file:com.eryansky.common.utils.io.IoUtils.java

public static File getFile(String filePath) {
    URL url = IoUtils.class.getClassLoader().getResource(filePath);
    try {//from   w w  w.j  a v a  2  s  .co  m
        return new File(url.toURI());
    } catch (Exception e) {
        //      throw new ServiceException("Couldn't get file " + filePath + ": " + e.getMessage());
    }
    return null;
}

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

public static String absolutize(String url, String confluenceRootUrl) {
    try {//  w ww . j  a  v a2  s.  com
        new URL(url);
        //already absolute
        return url;
    } catch (MalformedURLException e) {
    }
    try {
        URL context = new URL(confluenceRootUrl);
        String contextPath = context.getPath();
        if (!url.startsWith(contextPath)) {
            //the url does NOT start with context path: it is meant to be
            //relative to the context
            url = contextPath + url;
        }
        URL absolute = new URL(context, url);
        return absolute.toURI().normalize().toString();
    } catch (MalformedURLException e) {
        return url;
    } catch (URISyntaxException e) {
        return url;
    }
}

From source file:Main.java

/**
 * Transform to XML document from the URL.
 * /*w  ww .j  a  va2s  . com*/
 * @param url
 *            the url to transform
 * @return XML document transformed from the URL.
 * @throws SAXException
 *             indicate SAX error
 * @throws IOException
 *             indicate IO error
 * @throws URISyntaxException
 *             indicate the URL syntax error
 */
public static Document toDocument(URL url) throws SAXException, IOException, URISyntaxException {
    return builders.get().parse(url.toURI().toString());
}

From source file:com.glaf.core.util.AnnotationUtils.java

public static AnnotationDB getAnnotationDB(String packagePrefix) {
    AnnotationDB db = new AnnotationDB();
    db.addIgnoredPackages("org");
    db.setScanClassAnnotations(true);//from   w ww. java2 s.c om
    String[] scanPackages = new String[1];
    scanPackages[0] = packagePrefix;
    db.setScanPackages(scanPackages);
    URL url = ClasspathUrlFinder.findClassBase(AnnotationUtils.class);
    try {
        logger.debug("scan url:" + url.toURI().toString());
        db.scanArchives(url);
        URL[] urls = ClasspathUrlFinder.findClassPaths();
        for (URL url2 : urls) {
            logger.debug("scan url:" + url2.toURI().toString());
            db.scanArchives(url2);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }

    return db;
}

From source file:com.mycorp.SwaggerConfiguredArquillianTest.java

/**
 * Construct a deployment that will trigger the framework to initialize a default JAX-RS Application.
 *///from w w  w  .j a  v a  2s  .  c  o  m
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive archive = ShrinkWrap.create(WARArchive.class, "SampleTest.war");
    archive.addClass(Resource.class);
    URL yml = Thread.currentThread().getContextClassLoader().getResource("project-defaults.yml");
    assert yml != null;
    archive.addAsResource(new File(yml.toURI()), "/project-defaults.yml");
    archive.addAllDependencies();
    return archive;
}

From source file:io.undertow.integration.test.rootcontext.RootContextUtil.java

/**
 * Access http://localhost///from  www . ja v a2s.c  o  m
 */
public static String hitRootContext(Logger log, URL url, String serverName) throws Exception {
    HttpGet httpget = new HttpGet(url.toURI());
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpget.setHeader("Host", serverName);

    log.info("executing request" + httpget.getRequestLine());
    HttpResponse response = httpclient.execute(httpget);

    int statusCode = response.getStatusLine().getStatusCode();
    Header[] errorHeaders = response.getHeaders("X-Exception");
    assertTrue("Wrong response code: " + statusCode, statusCode == HttpURLConnection.HTTP_OK);
    assertTrue("X-Exception(" + Arrays.toString(errorHeaders) + ") is null", errorHeaders.length == 0);

    return EntityUtils.toString(response.getEntity());
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcResourceDaoTest.java

public static String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException {
    final URL sqlUrl = JdbcResourceDaoTest.class.getResource("/test-data/InsertTestData.sql");
    String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next();
    return sqlString;
}