List of usage examples for org.springframework.core.io ClassPathResource getFile
@Override public File getFile() throws IOException
From source file:at.ac.tuwien.ifs.tita.test.csv.CSVReaderTest.java
/** * Test./*from w ww. j a va2s . c o m*/ * * @throws IOException * ioe */ @Test public void testImportCSV() throws IOException { CellProcessor[] processors = new CellProcessor[] { new ParseDate("dd.MM.yyyy"), null, new ParseDate("HH:mm:ss"), new ParseDate("HH:mm:ss"), new ParseDate("HH:mm:ss") }; IImportReader reader = new CSVReader(service); ClassPathResource res = new ClassPathResource("../test-classes/at/ac/tuwien/ifs/tita/test/csv"); File file = res.getFile(); String path = file.getAbsolutePath() + "/CSVReaderTest.csv"; String[] header = new String[] { "date", "description", "duration", "startTime", "endTime" }; assertEquals("Before importing", C_TWO, tit1.getTitaEfforts().size()); try { reader.importEffortData(path, header, processors, tit1, us1); } catch (PersistenceException e1) { fail(""); } assertEquals("Three Efforts were imported", C_TWO + C_THREE, tit1.getTitaEfforts().size()); }
From source file:org.joy.generator.engine.FreeMarkerImpl.java
public void initConfiguration() { try {//from w w w .j a v a2 s . c om config = new Configuration(); ClassPathResource resource = new ClassPathResource("templates/freemarker"); // config.setDirectoryForTemplateLoading(new File(classPath + "templates/freemarker")); config.setDirectoryForTemplateLoading(resource.getFile()); config.setObjectWrapper(new DefaultObjectWrapper()); config.setSetting("classic_compatible", "true"); config.setSetting("whitespace_stripping", "true"); config.setSetting("template_update_delay", "1"); config.setSetting("locale", "zh_CN"); config.setSetting("default_encoding", DEFAULT_ENCODING); config.setSetting("url_escaping_charset", DEFAULT_ENCODING); config.setSetting("datetime_format", "yyyy-MM-dd hh:mm:ss"); config.setSetting("date_format", "yyyy-MM-dd"); config.setSetting("time_format", "HH:mm:ss"); config.setSetting("number_format", "0.######;"); } catch (Exception e) { LOGGER.info(e.getMessage(), e); } }
From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.caching.fileCollectors.FileCollectorAbstract.java
/** * Returns a {@link ClassLoaderOffer} containing the requested file in the classpath, if possible.<br/> * If the resource cannot be located, {@code null} is returned instead. * //from w ww . j a v a 2 s. c o m * @param fileName the name of the resource * @return the offer (can be {@code null}) */ protected ClassLoaderOffer collectFile(String fileName) { try { ClassPathResource resource = new ClassPathResource(fileName); if (resource.exists()) { File file = resource.getFile(); ClassLoaderFile classLoaderFile = new ClassLoaderFile(fileName, file.lastModified(), ContentType.ROFILE, Files.toByteArray(file)); return new ClassLoaderOffer(null, 0, new ClassLoaderFile[] { classLoaderFile }); } } catch (IOException e) { // ignore } return null; }
From source file:org.ngrinder.script.handler.ScriptHandler.java
/** * Get the initial script with the given value map. * * @param values map of initial script referencing values. * @return generated string//from www. ja v a 2 s.c om */ public String getScriptTemplate(Map<String, Object> values) { try { Configuration freemarkerConfig = new Configuration(); ClassPathResource cpr = new ClassPathResource("script_template"); freemarkerConfig.setDirectoryForTemplateLoading(cpr.getFile()); freemarkerConfig.setObjectWrapper(new DefaultObjectWrapper()); Template template = freemarkerConfig.getTemplate("basic_template_" + getExtension() + ".ftl"); StringWriter writer = new StringWriter(); template.process(values, writer); return writer.toString(); } catch (Exception e) { throw processException("Error while fetching the script template.", e); } }
From source file:org.springsource.restbucks.payment.web.PaymentProcessIntegrationTest.java
/** * Creates a new {@link Order} by looking up the orders link from the source and posting the content of * {@code orders.json} to it. Verifies we get receive a {@code 201 Created} and a {@code Location} header. Follows the * location header to retrieve the {@link Order} just created. * /*ww w .j a v a 2 s . c o m*/ * @param source * @return * @throws Exception */ private MockHttpServletResponse createNewOrder(MockHttpServletResponse source) throws Exception { String content = source.getContentAsString(); Link ordersLink = getDiscovererFor(source).findLinkWithRel(ORDERS_REL, content); ClassPathResource resource = new ClassPathResource("order.json"); byte[] data = Files.readAllBytes(resource.getFile().toPath()); MockHttpServletResponse result = mvc .perform(post(ordersLink.expand().getHref()).contentType(MediaType.APPLICATION_JSON).content(data)). // andExpect(status().isCreated()). // andExpect(header().string("Location", is(notNullValue()))). // andReturn().getResponse(); return mvc.perform(get(result.getHeader("Location"))).andReturn().getResponse(); }
From source file:com.iyonger.apm.web.handler.ScriptHandler.java
/** * Get the initial script with the given value map. * * @param values map of initial script referencing values. * @return generated string/*from w w w. j a v a2s . c o m*/ */ /*public String getScriptTemplate(Map<String, Object> values) { try { Configuration freemarkerConfig = new Configuration(); ClassPathResource cpr = new ClassPathResource("script_template"); freemarkerConfig.setDirectoryForTemplateLoading(cpr.getFile()); freemarkerConfig.setObjectWrapper(new DefaultObjectWrapper()); Template template = freemarkerConfig.getTemplate("basic_template_" + getExtension() + ".ftl"); StringWriter writer = new StringWriter(); template.process(values, writer); return writer.toString(); } catch (Exception e) { throw processException("Error while fetching the script template.", e); } }*/ public String getScriptTemplate(Map<String, Object> values) { try { Configuration freemarkerConfig = new Configuration(); ClassPathResource cpr = new ClassPathResource("script_template"); freemarkerConfig.setDirectoryForTemplateLoading(cpr.getFile()); freemarkerConfig.setObjectWrapper(new DefaultObjectWrapper()); Template template = freemarkerConfig.getTemplate("basic_template_" + getExtension() + ".ftl"); StringWriter writer = new StringWriter(); template.process(values, writer); return writer.toString(); } catch (Exception e) { throw processException("Error while fetching the script template.", e); } }
From source file:oz.hadoop.yarn.api.core.ApplicationMasterLauncherImpl.java
/** * /* www. ja va2 s . co m*/ */ private void initializeJarExclusionPatterns() { BufferedReader reader = null; try { this.jarsExclusionPatterns = new ArrayList<>(); ClassPathResource r = new ClassPathResource("classpath.filters"); reader = new BufferedReader(new FileReader(r.getFile())); String line; while ((line = reader.readLine()) != null) { Pattern pattern = Pattern.compile(line); this.jarsExclusionPatterns.add(pattern); } } catch (FileNotFoundException e) { logger.warn("Failed to process classpath exclusion paterns. " + "Not a fatal condition and simply means that all JARs in the classpath will be propagated " + "to the cluster as part of the application launch"); } catch (Exception e) { throw new IllegalStateException("Failed to process classpath exclusion paterns", e); } finally { if (reader != null) { try { reader.close(); } catch (Exception e2) { // ignore } } } }
From source file:oz.hadoop.yarn.api.core.LocalApplicationLaunchTests.java
@Test(timeout = 20000) public void validateContainerLaunchWithVariableLengthCommandsUntillDone() throws Exception { ClassPathResource resource = new ClassPathResource("variable", this.getClass()); YarnApplication<Void> yarnApplication = YarnAssembly .forApplicationContainer(resource.getFile().getAbsolutePath()).containerCount(6) .withApplicationMaster().build("sample-yarn-application"); assertEquals(0, yarnApplication.liveContainers()); assertFalse(yarnApplication.isRunning()); yarnApplication.launch();/*from w w w .j a v a 2 s. com*/ while (yarnApplication.isRunning()) { LockSupport.parkNanos(1000000); } assertFalse(yarnApplication.isRunning()); }