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:Main.java

public static <T> void saveObject(T object, Class<T> typeClass, URL path) {
    try {//  w ww.  j  a  va 2s  .  c o m
        File file = new File(path.toURI());
        JAXBContext jaxbContext = JAXBContext.newInstance(typeClass);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        jaxbMarshaller.marshal(object, file);

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static <T> T loadObject(Class<T> typeClass, URL path) {
    T object = null;// w  ww . j  a  v  a2  s. co m

    try {
        File file = new File(path.toURI());
        JAXBContext jaxbContext = JAXBContext.newInstance(typeClass);

        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        object = (T) jaxbUnmarshaller.unmarshal(file);
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    return object;
}

From source file:io.wcm.maven.plugins.i18n.FileUtil.java

public static File getFileFromClasspath(String resourcePath) throws URISyntaxException {
    URL url = FileUtil.class.getClassLoader().getResource(resourcePath);
    return new File(url.toURI());
}

From source file:Main.java

public static File findPom(Class clazz) {
    try {//from  www  .  j  a va 2 s. c  o m
        URL location = clazz.getProtectionDomain().getCodeSource().getLocation();
        File classFile = new File(location.toURI());
        File root = findPomRoot(classFile);
        return root != null ? new File(root, "pom.xml") : null;
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.free.movierenamer.utils.JSONUtilsTest.java

@BeforeClass
public static void init() throws FileNotFoundException, UnsupportedEncodingException, URISyntaxException {
    URL url = JSONUtilsTest.class.getResource("json.txt");
    File file = new File(url.toURI());
    Reader reader = new FileReader(file);
    json = (JSONObject) JSONValue.parse(reader);
}

From source file:com.boundary.sdk.snmp.metric.Pollers.java

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

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

    ObjectMapper mapper = new ObjectMapper();

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

From source file:com.vaadin.sass.testcases.scss.AbstractDirectoryScanningSassTests.java

private static File[] getScssFiles(URL directoryUrl) throws URISyntaxException {
    URL sasslangUrl = directoryUrl;
    File sasslangDir = new File(sasslangUrl.toURI());
    File scssDir = new File(sasslangDir, "scss");
    Assert.assertTrue(scssDir.exists());

    return scssDir.listFiles(new FilenameFilter() {

        @Override/*  www  .  j  a v  a2s  .co  m*/
        public boolean accept(File dir, String name) {
            return name.endsWith(".scss");
        }
    });
}

From source file:com.boundary.sdk.snmp.metric.OidMapList.java

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

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

    ObjectMapper mapper = new ObjectMapper();

    try {// w  w w.  j a va2  s. com
        instance = mapper.readValue(file, OidMapList.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return instance;
}

From source file:com.quartercode.jtimber.rh.agent.util.ResourceLister.java

private static URI toURI(URL url) {

    try {/*from  www. j  a v  a 2 s  . c  om*/
        return url.toURI();
    } catch (URISyntaxException e) {
        throw new RuntimeException("Strange error: Cannot convert url '" + url + "' into uri", e);
    }
}

From source file:com.boundary.sdk.snmp.metric.HostLists.java

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

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

    ObjectMapper mapper = new ObjectMapper();

    try {/*www  .ja v  a2s. c o m*/
        instance = mapper.readValue(file, HostLists.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return instance;
}