List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:com.boundary.sdk.util.UnixTimeSerializerTest.java
public static MyDate read(String resource) throws URISyntaxException { MyDate instance = new MyDate(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {/* w ww . j a v a 2s.c om*/ instance = mapper.readValue(file, MyDate.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:jenkins.plugins.livingdoc.ReportCollectorTest.java
@BeforeClass public static void initBaseDir() throws IOException, URISyntaxException { URL dirUrl = ReportCollectorTest.class.getResource("ReportCollector"); baseDir = new File(dirUrl.toURI()); File localBuildDir = File.createTempFile("junit", "builddir"); FileUtils.deleteQuietly(localBuildDir); FileUtils.forceMkdir(localBuildDir); buildDir = new FilePath(localBuildDir); }
From source file:com.shadwelldacunha.byteswipe.core.Utilities.java
public static File getResource(String resource) throws URISyntaxException { ClassLoader classLoader = Utilities.class.getClassLoader(); URL fileURL = classLoader.getResource(resource); return new File(fileURL.toURI()); }
From source file:com.betfair.cougar.codegen.Files.java
/** * Retrieve a File from the given resource name. *//* w ww. j av a 2s . c om*/ public static File fromResource(String resourceName) { URL url = Files.class.getClassLoader().getResource(resourceName); try { return new File(url.toURI()); } catch (URISyntaxException e) { throw new RuntimeException("Error converting resource to URI: " + e, e); } }
From source file:org.n52.oss.util.Util.java
public static String readResourceFile(String s) { URL resource = Util.class.getResource(s); Path path;/* w ww .j a v a2s. c om*/ try { path = Paths.get(resource.toURI()); } catch (URISyntaxException e) { log.error("Could not read from resource path " + s, e); return ""; } return readResourceFile(path); }
From source file:com.jeklsoft.cassandraclient.hector.HectorTest.java
public static me.prettyprint.hector.api.Keyspace configureHectorAccessToCassandra(String cassandraHostname, Integer cassandraPort, String cassandraClusterName, String cassandraKeySpaceName, String configurationPath, List<String> cassandraCommands) throws Exception { try {/* www . j av a 2 s .com*/ if (StringUtils.isNotEmpty(configurationPath) && (cassandraCommands != null) && (!cassandraCommands.isEmpty())) { URL stream = HectorTest.class.getClassLoader().getResource("cassandra.yaml"); File cassandraYaml = new File(stream.toURI()); EmbeddedCassandra.builder().withCleanDataStore().withStartupCommands(cassandraCommands) .withHostname(cassandraHostname).withHostport(cassandraPort) .withCassandaConfigurationDirectoryPath(configurationPath) .withCassandaYamlFile(cassandraYaml).build(); } CassandraHostConfigurator configurator = new CassandraHostConfigurator( cassandraHostname + ":" + cassandraPort); Cluster cluster = HFactory.getOrCreateCluster(cassandraClusterName, configurator); me.prettyprint.hector.api.Keyspace keyspace = HFactory.createKeyspace(cassandraKeySpaceName, cluster); return keyspace; } catch (Exception e) { throw new RuntimeException("Error configuring access", e); } }
From source file:com.twosigma.beaker.mimetype.MIMEContainer.java
protected static boolean isValidURL(String urlString) { try {/*from w ww .j av a 2s . c o m*/ URL url = new URL(urlString); url.toURI(); return true; } catch (Exception exception) { return false; } }
From source file:ch.ifocusit.livingdoc.plugin.utils.Template.java
public static Template create(final URL url) { try {//from ww w . ja v a2 s. c o m Template parameter = new Template(); parameter.template = new File(url.toURI()); return parameter; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:com.github.woozoo73.ht.XmlUtils.java
public static String getContent(String path) { try {//from ww w . ja va 2 s .co m URL url = XmlUtils.class.getClassLoader().getResource(path); File schemaLocation = new File(url.toURI()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(schemaLocation); StringWriter writer = new StringWriter(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(document), new StreamResult(writer)); String content = writer.getBuffer().toString(); return content; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:cop.raml.processor.AbstractProcessorTest.java
protected static File getResourceAsFile(String path) { URL url = AbstractProcessorTest.class.getClassLoader().getResource(path); try {// w ww . j a va2 s. co m return url != null ? new File(url.toURI()) : null; } catch (URISyntaxException ignored) { return new File(url.getPath()); } }