List of usage examples for java.net URL getFile
public String getFile()
From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java
@Test public void testAddSeaCloudsApplicationData() throws Exception { Yaml yamlParser = new Yaml(); URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH); Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile()))); int oldSize = dataStore.listSeaCloudsApplicationData().size(); SeaCloudsApplicationData seaCloudsApplicationData = new SeaCloudsApplicationData(toscaDamMap); dataStore.addSeaCloudsApplicationData(seaCloudsApplicationData); int newSize = dataStore.listSeaCloudsApplicationData().size(); assertEquals(oldSize, newSize - 1);/*from www. j a v a2 s.co m*/ SeaCloudsApplicationData seaCloudsApplicationDataById = dataStore .getSeaCloudsApplicationDataById(seaCloudsApplicationData.getSeaCloudsApplicationId()); assertEquals(seaCloudsApplicationData, seaCloudsApplicationDataById); }
From source file:eu.seaclouds.platform.dashboard.model.SeaCloudsApplicationDataStorageTest.java
@Test public void testRemoveSeaCloudsApplicationData() throws Exception { Yaml yamlParser = new Yaml(); URL resource = Resources.getResource(TOSCA_DAM_FILE_PATH); Map toscaDamMap = (Map) yamlParser.load(FileUtils.openInputStream(new File(resource.getFile()))); int oldSize = dataStore.listSeaCloudsApplicationData().size(); SeaCloudsApplicationData seaCloudsApplicationData = new SeaCloudsApplicationData(toscaDamMap); dataStore.addSeaCloudsApplicationData(seaCloudsApplicationData); SeaCloudsApplicationData seaCloudsApplicationDataById = dataStore .removeSeaCloudsApplicationDataById(seaCloudsApplicationData.getSeaCloudsApplicationId()); assertEquals(seaCloudsApplicationData, seaCloudsApplicationDataById); int newSize = dataStore.listSeaCloudsApplicationData().size(); assertEquals(oldSize, newSize);// w ww .ja va2 s.c o m }
From source file:net.idea.opentox.cli.test.DatasetClientTest.java
@Override public void testCreate() throws Exception { //in case the TEST_SERVER uses HTTP BASIC otclient.setHTTPBasicCredentials("localhost", 8080, "admin", "changeit"); DatasetClient<POLICY_RULE> cli = getOTClient(); URL url = getClass().getClassLoader().getResource("net/idea/opentox/cli/test/sdf/1000-90-4.sdf"); File fileToImport = new File(url.getFile()); Assert.assertTrue(fileToImport.exists()); Dataset dataset = new Dataset(); dataset.getMetadata().setTitle("Test dataset"); dataset.getMetadata().setSeeAlso("Test see also uri"); dataset.getMetadata()/*from w ww . j ava 2 s. co m*/ .setRights(new Rights("CC-BY-SA", "http://creativecommons.org/licenses/by-sa/2.0/", _type.license)); dataset.setInputData(new InputData(fileToImport, DatasetClient._MATCH.InChI)); RemoteTask task = cli.postAsync(dataset, new Identifier(String.format("%s%s", TEST_SERVER, Resources.dataset))); task.waitUntilCompleted(1000); //verify if ok Assert.assertEquals(HttpStatus.SC_OK, task.getStatus()); Assert.assertNull(task.getError()); List<Dataset> theDataset = cli.getMetadata(task.getResult()); Assert.assertEquals(1, theDataset.size()); Assert.assertEquals(dataset.getMetadata().getTitle(), theDataset.get(0).getMetadata().getTitle()); Assert.assertEquals(dataset.getMetadata().getSeeAlso(), theDataset.get(0).getMetadata().getSeeAlso()); Assert.assertEquals(task.getResult(), theDataset.get(0).getResourceIdentifier()); CompoundClient<POLICY_RULE> ccli = otclient.getCompoundClient(); List<Compound> compounds = cli.getCompounds(theDataset.get(0), ccli); Assert.assertNotNull(compounds); for (Compound compound : compounds) { System.out.println(compound); } //finally delete the dataset cli.delete(theDataset.get(0)); }
From source file:idgs.metadata.LocalStoreLoader.java
@Override public DataStoreConfig loadDataStoreConf() throws IdgsException { log.info("load store config: " + cfgFilePath); if (storeConfigMap.containsKey(cfgFilePath)) { return storeConfigMap.get(cfgFilePath); }//from w w w . java2s . c o m File file = new File(cfgFilePath); do { if (file.exists()) { break; } String temppath; // IDGS_HOME env if ((temppath = System.getenv("IDGS_HOME")) != null) { temppath = temppath + "/" + cfgFilePath; file = new File(temppath); if (file.exists()) { break; } } URL url = LocalStoreLoader.class.getClassLoader().getResource(cfgFilePath); if (url != null) { file = new File(url.getFile()); break; } log.error("Data store config file " + cfgFilePath + " is not found."); throw new IdgsException("Data store config file " + cfgFilePath + " is not found."); } while (false); DataStoreConfig.Builder builder = DataStoreConfig.newBuilder(); try { JsonUtil.jsonFileToPb(builder, file.getAbsolutePath()); } catch (IOException e) { log.error(e.getMessage()); throw new IdgsException(e); } DataStoreConfig conf = builder.build(); storeConfigMap.put(cfgFilePath, conf); return conf; }
From source file:eu.cloud4soa.soa.jaxrs.test.SemanticAppInitializer.java
public void initialize() { try {// w ww .j ava 2s. c o m String developerUserDir = "applicationProfiles"; URL resource = scanPackage(developerUserDir); String protocol = resource.getProtocol(); if (protocol.equals("file")) { File file = new File(resource.getFile()); if (file.isDirectory()) { String[] list = file.list(); for (String fileName : list) { String applicationTurtleProfile = loadTurtleFileIntoString(developerUserDir, fileName); logger.info("Loaded application profile: " + fileName); storeTurtleApplicationProfile(applicationTurtleProfile, developerUriId); } } } } catch (IOException ex) { logger.error("Error during the creation of the Application profiles", ex); } }
From source file:com.sastix.cms.server.services.cache.CacheFileUtilsServiceTest.java
@Test public void downloadLocalResourceTest() throws IOException, URISyntaxException { //from local storage URL localFile = getClass().getClassLoader().getResource("./logo.png"); byte[] bytesFound = cacheFileUtilsService.downloadResource(localFile); byte[] expected = Files.readAllBytes(Paths.get(localFile.getFile())); Assert.assertArrayEquals(expected, bytesFound); }
From source file:com.liferay.frontend.theme.contributor.extender.internal.ThemeContributorExtender.java
private BundleWebResourcesImpl _scanForResources(Bundle bundle) { final List<String> cssResourcePaths = new ArrayList<>(); final List<String> jsResourcePaths = new ArrayList<>(); Enumeration<URL> cssEntries = bundle.findEntries("/META-INF/resources", "*.css", true); Enumeration<URL> jsEntries = bundle.findEntries("/META-INF/resources", "*.js", true); if (cssEntries != null) { while (cssEntries.hasMoreElements()) { URL url = cssEntries.nextElement(); String path = url.getFile(); path = path.replace("/META-INF/resources", ""); int index = path.lastIndexOf('/'); if (!StringPool.UNDERLINE.equals(path.charAt(index + 1)) && !path.endsWith("_rtl.css")) { cssResourcePaths.add(path); }/* w w w. j ava 2 s . c o m*/ } } if (jsEntries != null) { while (jsEntries.hasMoreElements()) { URL url = jsEntries.nextElement(); String path = url.getFile(); jsResourcePaths.add(path.replace("/META-INF/resources", "")); } } if (cssResourcePaths.isEmpty() && jsResourcePaths.isEmpty()) { return null; } else { return new BundleWebResourcesImpl(cssResourcePaths, jsResourcePaths); } }
From source file:com.revo.deployr.rbroker.example.data.io.anon.discrete.task.ExternalDataInDataFileOut.java
public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult) { log.info("[ TASK RESULT ] Discrete task " + "completed in " + rTaskResult.getTimeOnCall() + "ms [ RTaskResult ]."); if (rTaskResult != null) { /*//from ww w . j a v a2 s .com * Retrieve the working directory file (artifact) called * hip.csv that was generated by the execution. * * Outputs generated by an execution can be used in any * number of ways by client applications, including: * * 1. Use output data to perform further calculations. * 2. Display output data to an end-user. * 3. Write output data to a database. * 4. Pass output data along to another Web service. * 5. etc. */ List<URL> wdFiles = rTaskResult.getGeneratedFiles(); for (URL wdFile : wdFiles) { String fileName = wdFile.getFile(); if (fileName.endsWith("hip.csv")) { log.info("[ DATA OUTPUT ] Retrieved working " + "directory file output " + fileName.substring(fileName.lastIndexOf("/") + 1) + " [ URL ]"); InputStream fis = null; try { fis = wdFile.openStream(); IOUtils.toByteArray(fis); } catch (Exception ex) { log.warn("Working directory data file " + ex); } finally { IOUtils.closeQuietly(fis); } } } } /* * Unblock main thread so example application can release * resources before exit. */ latch.countDown(); }
From source file:ZipURLStreamHandler.java
/** * Returns a ZipURLConnection for the specified URL. *///from w ww. j a va 2s .c om public URLConnection openConnection(URL url) throws IOException { String urlFile = url.getFile(); int barIndex = urlFile.indexOf("|"); if (barIndex == -1) throw new MalformedURLException("Missing '|'"); String fileName = urlFile.substring(0, barIndex); String entryName = urlFile.substring(barIndex + 1); return new ZipURLConnection(url, new File(fileName), entryName); }
From source file:io.fabric8.kubernetes.pipeline.KubernetesPipelineTest.java
private void configureCloud(JenkinsRuleNonLocalhost r) throws Exception { // Slaves running in Kubernetes (minikube) need to connect to this server, so localhost does not work URL url = r.getURL(); URL nonLocalhostUrl = new URL(url.getProtocol(), InetAddress.getLocalHost().getHostAddress(), url.getPort(), url.getFile()); JenkinsLocationConfiguration.get().setUrl(nonLocalhostUrl.toString()); r.jenkins.clouds.add(cloud);//from w ww . j a v a2 s. c o m }