List of usage examples for java.net URL getFile
public String getFile()
From source file:business.LargerExcerptListTests.java
@Test(groups = "request", dependsOnMethods = "approveRequest") public void uploadExcerptList() throws IOException { UserAuthenticationToken palga = getPalga(); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(palga); RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId); log.info("Status: " + representation.getStatus()); log.info("Activity: " + representation.getActivityId()); if (representation.getActivityId() == null) { for (Task task : taskService.createTaskQuery().list()) { log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: " + task.getName() + ", key: " + task.getTaskDefinitionKey()); }/* www .j a v a 2 s .co m*/ } log.info("uploadExcerptList: processInstanceId = " + processInstanceId); representation = requestController.claim(palga, processInstanceId, representation); ClassLoader classLoader = getClass().getClassLoader(); URL resource = classLoader.getResource("test/Example excerptlist 20150521 v2.csv"); InputStream input = resource.openStream(); MultipartFile file = new MockMultipartFile(resource.getFile(), input); Integer flowTotalChunks = 1; Integer flowChunkNumber = 1; String flowIdentifier = "flow"; int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(), flowTotalChunks, flowChunkNumber, flowIdentifier, file); assertEquals(6, entryCount); SecurityContextHolder.clearContext(); }
From source file:cfa.vo.iris.sdk.PluginManager.java
public void loadJar(URL url) { try {/*from ww w . jav a2 s . c o m*/ PluginJar jar = new PluginJar(url); jar.load(); if (!jar.getPlugins().isEmpty()) { String[] paths = url.getFile().split("/"); String name = paths[paths.length - 1]; File dest = new File(app.getConfigurationDir() + "/components/" + name); if (!dest.exists()) FileUtils.copyURLToFile(url, dest); jars.add(jar); jar.setFile(dest); for (IrisPlugin p : jar.getPlugins()) { for (IrisComponent c : p.getComponents()) { for (IMenuItem item : c.getMenus()) { item.consolidate(dest); } } } PluginJarEvent.getInstance().fire(jar, SedCommand.ADDED); } } catch (Exception ex) { Logger.getLogger(PluginManager.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.ks.text.AsciiDocParser.java
private void appendCssFile(StringBuilder builder, String cssFile) { URL asciiDoctorCss = getClass().getResource("/org/asciidoctor/" + cssFile); File file = new File(asciiDoctorCss.getFile()); try {/*from w w w . j a va2s . c o m*/ List<String> lines = Files.readLines(file, Charsets.US_ASCII); lines.forEach(line -> builder.append(line).append("\n")); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.linkedin.pinot.core.indexsegment.mutable.MutableSegmentImplTest.java
@BeforeClass public void setUp() throws Exception { FileUtils.deleteQuietly(TEMP_DIR);/*ww w .j av a2 s.co m*/ URL resourceUrl = MutableSegmentImplTest.class.getClassLoader().getResource(AVRO_FILE); Assert.assertNotNull(resourceUrl); File avroFile = new File(resourceUrl.getFile()); SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGeneratorConfigWithoutTimeColumn(avroFile, TEMP_DIR, "testTable"); SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl(); driver.init(config); driver.build(); _immutableSegment = ImmutableSegmentLoader.load(new File(TEMP_DIR, driver.getSegmentName()), ReadMode.mmap); _schema = config.getSchema(); _mutableSegmentImpl = MutableSegmentImplTestUtils.createMutableSegmentImpl(_schema, Collections.emptySet(), Collections.emptySet(), false); try (RecordReader recordReader = new AvroRecordReader(avroFile, _schema)) { GenericRow reuse = new GenericRow(); while (recordReader.hasNext()) { _mutableSegmentImpl.index(recordReader.next(reuse)); } } }
From source file:hrpod.tools.nlp.NLPTools.java
public void setChunkerModel() { try {/* ww w . j a va2 s . c o m*/ URL chUrl = this.getClass().getResource(modelBasePath + "en-chunker.bin"); this.chunkerModel = new ChunkerModel(new FileInputStream(new File(chUrl.getFile()))); } catch (Exception e) { logger.error("Error is setChunkerModel", e); } }
From source file:edu.rosehulman.sws.extension.AbstractPlugin.java
private void parseRouteLine(String line) { // split line on any amount of white space in between parts String[] routeParts = line.split("\\s+"); String path = routeParts[0].replaceAll(".*[/\\\\].*", File.separator); String routeKey = getServeltRouteKey(path, routeParts[1]); String routeServletClass = routeParts[2]; // create new servlet instance frome routeServlet name Class<?> servletClass;/*from ww w . j a va 2s . c o m*/ try { URL location = getClass().getProtectionDomain().getCodeSource().getLocation(); ClassLoader classLoader = new URLClassLoader( new URL[] { new File(location.getFile()).toURI().toURL() }); servletClass = classLoader.loadClass(routeServletClass); Constructor<?> servletConstructor = servletClass.getConstructor(); Object servletObj = servletConstructor.newInstance(); IServlet servlet = (IServlet) servletObj; servlet.setPlugin(this); this.servletMap.put(routeKey, servlet); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:co.cask.hydrator.plugin.batch.spark.test.GDTreeTest.java
@Before public void copyFiles() throws Exception { URL testFileUrl = this.getClass().getResource("/trainData.csv"); FileUtils.copyFile(new File(testFileUrl.getFile()), new File(sourceFolder, "/trainData.csv")); }
From source file:com.adaptris.core.BaseCase.java
/** * <p>/*from www . j a v a 2s . co m*/ * Check if the file component of the passed file URL exists. * </p> */ protected boolean checkFileExists(String fileUrl) { try { URL url = new URL(fileUrl); File file = new File(url.getFile()); return file.exists(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.adaptris.core.BaseCase.java
/** * <p>//from w ww. j a v a 2s .co m * Delete the file component of the passed file URL. * </p> */ protected void removeFile(String fileUrl) { try { URL url = new URL(fileUrl); File file = new File(url.getFile()); file.delete(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:dkpro.similarity.uima.io.PlainTextCombinationReader.java
@Override public List<CombinationPair> getAlignedPairs() throws ResourceInitializationException { List<CombinationPair> pairs = new ArrayList<CombinationPair>(); URL inputUrl = null; try {/*from w ww . jav a 2 s . c o m*/ inputUrl = ResourceUtils.resolveLocation(inputDirName, this, getUimaContext()); } catch (IOException e) { throw new ResourceInitializationException(e); } File inputDir = new File(inputUrl.getFile()); for (File file : FileUtils.listFiles(inputDir, new String[] { "txt" }, false)) { try { String s = FileUtils.readFileToString(file); String id = file.getName().substring(file.getName().length() - 5, file.getName().length() - 4); CombinationPair pair = new CombinationPair(inputDir.getAbsolutePath()); pair.setID1(file.getName().substring(0, file.getName().length() - 4)); pair.setID2(file.getName().substring(0, file.getName().length() - 4)); pair.setText1(s.split("\n")[0]); pair.setText2(s.split("\n")[1]); pairs.add(pair); } catch (IOException e) { throw new ResourceInitializationException(e); } } return pairs; }