List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:io.cloudslang.lang.compiler.CompileResultsTest.java
private Executable preCompileExecutable(String source) throws Exception { URL sourceURI = getClass().getResource(source); return compiler.preCompile(SlangSource.fromFile(sourceURI.toURI())); }
From source file:org.jboss.test.capedwarf.blobstore.support.FileUploader.java
public String getUploadUrl(URL url) throws URISyntaxException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet get = new HttpGet(url.toURI()); HttpResponse response = httpClient.execute(get); return EntityUtils.toString(response.getEntity()).trim(); }
From source file:com.netflix.nicobar.core.archive.SingleFileScriptArchiveTest.java
@Test public void testWithModuleSpec() 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(); ModuleId moduleId = ModuleId.create("testModuleId"); for (String script : singleFileScripts) { Path scriptPath = rootPath.resolve(script); SingleFileScriptArchive scriptArchive = new SingleFileScriptArchive.Builder(scriptPath) .setModuleSpec(new ScriptModuleSpec.Builder(moduleId).build()).build(); assertEquals(scriptArchive.getModuleSpec().getModuleId(), moduleId); // We just need to test one script in the set break;/*from w w w .ja va 2 s. c o m*/ } }
From source file:au.org.ala.delta.confor.ToKeyTest.java
private File urlToFile(String urlString) throws Exception { URL url = ToKeyTest.class.getResource(urlString); File file = new File(url.toURI()); return file;/* ww w . j a va 2 s. c o m*/ }
From source file:au.org.ala.delta.key.AllowImproperSubgroupsTest.java
public void testAllowImproperSubgroups() throws Exception { URL directivesFileURL = getClass().getResource("/sample/mykey"); File directivesFile = new File(directivesFileURL.toURI()); URL charFileURL = getClass().getResource("/sample/kchars"); File charFile = new File(charFileURL.toURI()); URL itemsFileURL = getClass().getResource("/sample/kitems"); File itemsFile = new File(itemsFileURL.toURI()); // Use dummy temp file for data directory seeing as we don't have a use // for it here KeyContext context = new KeyContext(directivesFile); context.setABase(1.0);/*from w w w. jav a 2 s . c o m*/ context.setVaryWt(1.0); context.setRBase(1.0); context.setReuse(1.0); context.setCharactersFile(charFile); context.setItemsFile(itemsFile); context.setAllowImproperSubgroups(false); KeyUtils.loadDataset(context); List<Integer> availableCharacterNumbers = Arrays .asList(ArrayUtils.toObject(new IntRange(1, context.getNumberOfCharacters()).toArray())); List<Integer> availableTaxaNumbers = Arrays .asList(ArrayUtils.toObject(new IntRange(1, context.getMaximumNumberOfItems()).toArray())); Map<Character, Double> bestMap = KeyBest.orderBest(context.getDataSet(), context.getCharacterCostsAsArray(), context.getCalculatedItemAbundanceValuesAsArray(), availableCharacterNumbers, availableTaxaNumbers, context.getRBase(), context.getABase(), context.getReuse(), context.getVaryWt(), context.getAllowImproperSubgroups()); assertFalse(bestMap.containsKey(context.getCharacter(10))); context.setAllowImproperSubgroups(true); Map<Character, Double> bestMap2 = KeyBest.orderBest(context.getDataSet(), context.getCharacterCostsAsArray(), context.getCalculatedItemAbundanceValuesAsArray(), availableCharacterNumbers, availableTaxaNumbers, context.getRBase(), context.getABase(), context.getReuse(), context.getVaryWt(), context.getAllowImproperSubgroups()); assertTrue(bestMap2.containsKey(context.getCharacter(10))); }
From source file:com.boundary.sdk.event.esper.EsperRouteBuilder.java
/** * TODO: Proper handling of exception/* w ww.ja v a2 s. com*/ * @throws URISyntaxException {@link URISyntaxException} */ protected void loadConfiguration() throws URISyntaxException { ClassLoader classLoader = this.getClass().getClassLoader(); URL url = classLoader.getResource(this.configuration); this.queryList = load(url.toURI()); }
From source file:org.yroffin.neo4b.components.WebServerService.java
/** * post construct// w w w . ja v a 2s .c o m * * @throws IOException * @throws URISyntaxException */ @PostConstruct void init() throws IOException, URISyntaxException { logger.info("Component {} is loading", this.getClass().getName()); URL url = this.getClass().getResource("/" + SERVER_PROPERTIES); if (url != null) { File file = new File(url.toURI()); if (file.exists()) { properties = getProperties(file); String iface = properties.getProperty("listen"); int port = Integer.parseInt(properties.getProperty("port")); spark.Spark.ipAddress(iface); spark.Spark.port(port); // register hook registerShutdownHook(this); // Map resources resourceMapper.map(); } else { logger.error("Unable to find any {}", SERVER_PROPERTIES); } } else { logger.error("Unable to find any {} in classpath", SERVER_PROPERTIES); } logger.info("Component {} is loaded", this.getClass().getName()); }
From source file:ca.marcmeszaros.papyrus.remote.DownloadThumbnails.java
@Override protected LinkedList<Bitmap> doInBackground(URL... urls) { // some class variables HttpGet httpRequest;/*from www . j a v a2 s . c o m*/ Bitmap bm; LinkedList<Bitmap> bitmaps = new LinkedList<Bitmap>(); try { // loop through all urls for (URL url : urls) { // create the HTTP request httpRequest = new HttpGet(url.toURI()); // create an HTTP client and get the response HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); // get a handle on the http entity HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); // read the entity from the stream into a bitmap object bm = BitmapFactory.decodeStream(instream); // add the bitmap to the list bitmaps.add(bm); } } catch (URISyntaxException e) { Log.e(TAG, "URISyntaxException", e); } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException", e); } catch (IOException e) { Log.e(TAG, "IOException", e); } return bitmaps; }
From source file:com.boundary.sdk.event.esper.QueryListTest.java
private void load() throws Exception { ClassLoader classLoader = this.getClass().getClassLoader(); URL url = classLoader.getResource(QUERY_LIST_FILE); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {//from w ww . j a v a 2 s. com this.queryList = mapper.readValue(file, QueryList.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.troja.eve.crest.CrestDataProcessorTest.java
private String getExampleData() throws URISyntaxException, IOException { final URL resource = getClass().getResource(EXAMPLE_FILE); final Path file = Paths.get(resource.toURI()); final String answer = new String(Files.readAllBytes(file)); return answer; }