List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:com.collective.celos.JettyServer.java
private void startServer() throws Exception { URL url = Thread.currentThread().getContextClassLoader().getResource("WEB-INF"); URIBuilder uriBuilder = new URIBuilder(url.toURI()); uriBuilder.setPath(Paths.get(url.getPath()).getParent().toString()); context = new WebAppContext(uriBuilder.toString() + "/", "/"); context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); context.setExtractWAR(false);// w ww.jav a 2 s . c o m server.setHandler(context); server.start(); }
From source file:CookieAccessor.java
/** * Set cookie in cookie store/*from www.j av a 2 s .com*/ */ public void setCookieUsingCookieHandler() { try { // instantiate CookieManager CookieManager manager = new CookieManager(); CookieHandler.setDefault(manager); CookieStore cookieJar = manager.getCookieStore(); // create cookie HttpCookie cookie = new HttpCookie("UserName", "John Doe"); // add cookie to CookieStore for a particular URL URL url = new URL("http://host.example.com"); cookieJar.add(url.toURI(), cookie); System.out.println("Added cookie using cookie handler"); } catch (Exception e) { System.out.println("Unable to set cookie using CookieHandler"); e.printStackTrace(); } }
From source file:com.quangphuong.crawler.util.XMLUtil.java
public XMLUtil() throws URISyntaxException { URL u = getClass().getProtectionDomain().getCodeSource().getLocation(); File f = new File(u.toURI().getPath()); rootPath = f.getParent();//from ww w. ja v a 2 s. co m f.delete(); }
From source file:com.goodformobile.build.mobile.AbstractRIMMojoTest.java
protected File getRelativeFile(String path) throws URISyntaxException { URL url = getClassLoader().getResource(path); File pluginConfig = new File(url.toURI()); return pluginConfig; }
From source file:com.netflix.nicobar.core.archive.SingleFileScriptArchiveTest.java
@Test public void testDefaultModuleSpec() throws Exception { URL rootPathUrl = getClass().getClassLoader().getResource(TEST_SCRIPTS_PATH.getResourcePath()); Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath(); Set<String> singleFileScripts = TEST_SCRIPTS_PATH.getContentPaths(); for (String script : singleFileScripts) { Path scriptPath = rootPath.resolve(script); SingleFileScriptArchive scriptArchive = new SingleFileScriptArchive.Builder(scriptPath).build(); String moduleId = script.replaceAll("\\.", "_"); assertEquals(scriptArchive.getModuleSpec().getModuleId().toString(), moduleId); Set<String> archiveEntryNames = scriptArchive.getArchiveEntryNames(); assertEquals(archiveEntryNames.size(), 1); for (String entryName : archiveEntryNames) { URL entryUrl = scriptArchive.getEntry(entryName); assertNotNull(entryUrl);//from ww w.ja va 2 s . c o m InputStream inputStream = entryUrl.openStream(); String content = IOUtils.toString(inputStream, Charsets.UTF_8); // We have stored the file name as the content of the file assertEquals(content, script + lineSeparator()); } } }
From source file:org.n52.car.io.schema.Validation.java
private List<String> findSchemas() throws URISyntaxException { URL url = getClass().getResource("/schema"); File baseDir = new File(url.toURI()); File[] files = baseDir.listFiles(new FileFilter() { @Override//from ww w . j a va2 s . c om public boolean accept(File pathname) { return pathname.getName().endsWith(".json"); } }); List<String> result = new ArrayList<String>(files.length); String path; for (File f : files) { path = f.getAbsolutePath(); result.add(path.substring(path.lastIndexOf("/schema"), path.length())); } return result; }
From source file:com.esri.geoportal.harvester.ckan.data.gov.DataGovBroker.java
@Override protected Content createContent(Dataset dataSet) throws DataInputException { if (dataSet.extras != null) { String oid = findOid(dataSet); if (oid != null) { try { URL xmlUrl = makeXmlUrl(oid); HttpGet req = new HttpGet(xmlUrl.toURI()); try (CloseableHttpResponse httpResponse = httpClient.execute(req); InputStream contentStream = httpResponse.getEntity().getContent();) { String reasonMessage = httpResponse.getStatusLine().getReasonPhrase(); String responseContent = IOUtils.toString(contentStream, "UTF-8"); LOG.trace(String.format("RESPONSE: %s, %s", responseContent, reasonMessage)); return new Content(responseContent, readContentType(httpResponse)); }/*w ww . j a v a2 s . com*/ } catch (URISyntaxException | IOException ex) { throw new DataInputException(this, String.format("Error reading metadata for object: %s", oid), ex); } } else { LOG.warn(formatForLog("Unable to find '%s' for dataset: %s", definition.getOidKey(), dataSet.id)); } } return super.createContent(dataSet); }
From source file:com.netflix.nicobar.core.archive.PathScriptArchiveTest.java
@Test public void testDefaultModuleId() throws Exception { URL rootPathUrl = getClass().getClassLoader().getResource(TEST_TEXT_PATH.getResourcePath()); Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath(); PathScriptArchive scriptArchive = new PathScriptArchive.Builder(rootPath).build(); assertEquals(scriptArchive.getModuleSpec().getModuleId(), TEST_TEXT_PATH.getModuleId()); }
From source file:com.runwaysdk.system.metadata.MetadataPatcher.java
@Override public void run() { String location = this.getScriptLocation(); String driver = this.getDriver(); try {//from w ww . j av a2 s .c o m URL resource = this.getClass().getResource(location); File scripts = new File(resource.toURI()); DbDeploy deploy = new DbDeploy(); deploy.setDbms(this.dbms); deploy.setDriver(driver); deploy.setUserid(this.userid); deploy.setPassword(this.password); deploy.setUrl(this.url); deploy.setScriptdirectory(scripts); deploy.go(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.silverpeas.converter.ToPDFConverterTest.java
private File getDocumentNamed(final String name) throws Exception { final URL documentLocation = getClass().getResource(name); return new File(documentLocation.toURI()); }