List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.wte4j.examples.showcase.server.hsql.ShowCaseDbInitializer.java
void createDateBaseFiles(Path dataBaseLocation, boolean overide) { Path hsqlScript = dataBaseLocation.resolve("wte4j-showcase.script"); if (overide || !Files.exists(hsqlScript)) { try {//from ww w.j a va 2 s.com if (!Files.exists(dataBaseLocation)) { Files.createDirectories(dataBaseLocation); } Resource[] resources = resourceLoader.getResources("classpath:/db/*"); for (Resource resource : resources) { Path filePath = dataBaseLocation.resolve(resource.getFilename()); File source = resource.getFile(); Files.copy(source.toPath(), filePath, StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { throw new IllegalArgumentException("can not copy database files", e); } } }
From source file:com.camp.web.converter.XMLConverter.java
public Object convertFromXMLToObject(Resource resource) throws IOException { FileInputStream fileStream = null; try {/*w w w .j a v a 2 s .c om*/ File file = resource.getFile(); fileStream = new FileInputStream(file); return getUnmarshaller().unmarshal(new StreamSource(fileStream)); } finally { if (null != fileStream) { fileStream.close(); } } }
From source file:com.siberhus.tdfl.DefaultResourceCreator.java
@Override public Resource create(Resource example) throws IOException { String parent = example.getFile().getParent(); String targetDirPath = parent + File.separator + subdirectory; File targetDir = new File(targetDirPath); if (!targetDir.exists()) { if (createDirectory) { targetDir.mkdir();/*from www .j av a 2 s . com*/ } } String filename = example.getFilename(); if (extension == null) extension = FilenameUtils.getExtension(filename); filename = FilenameUtils.getBaseName(filename); if (prefix != null) { filename = prefix + filename; } if (suffix != null) { filename = filename + suffix; } filename = filename + "." + extension; return new FileSystemResource(targetDirPath + File.separator + filename); }
From source file:com.miko.demo.birt.core.BirtEngineFactory.java
public void setLogDirectory(Resource resource) { File f;/*from w w w .j a v a 2s . co m*/ try { f = resource.getFile(); validateLogDirectory(f); _resolvedDirectory = f; } catch (IOException e) { logger.error("setLogDirectory e= " + e); throw new RuntimeException("Couldnt set the log Directory"); } }
From source file:org.openregistry.core.repository.xml.XmlBasedDisclosureRecalculationStrategyRepositoryImpl.java
public XmlBasedDisclosureRecalculationStrategyRepositoryImpl(final Resource resource) throws JAXBException, IOException { File disclosureCalculationStrategyFile = resource.getFile(); JAXBContext jaxbContext = JAXBContext.newInstance(XmlBasedDisclosureRecalculationStrategyImpl.class); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); logger.info("Attempting to load Xml Disclosure recalculation strategy spec from [" + disclosureCalculationStrategyFile.getAbsolutePath() + "]"); Assert.isTrue(disclosureCalculationStrategyFile.isFile() && disclosureCalculationStrategyFile.canRead() && disclosureCalculationStrategyFile.getName().endsWith(".xml")); final FileReader fileReader = new FileReader(disclosureCalculationStrategyFile); disclosureRecalcualationStrategy = (DisclosureRecalculationStrategy) unMarshaller.unmarshal(fileReader); logger.info("Loaded Xml Disclosure recalculation strategy spec with name [" + disclosureRecalcualationStrategy.getName() + "] description [" + disclosureRecalcualationStrategy.getDescription() + "]"); }
From source file:org.bitsofinfo.util.address.usps.ais.loader.USPSParserTest.java
private List<String> loadLinesFromFile(String filename) throws Exception { Resource file = applicationContext.getResource("classpath:" + filename); List<String> lines = FileUtils.readLines(file.getFile()); return lines; }
From source file:com.oakhole.core.email.MimeMailService.java
/** * ?classpath.//www . java 2 s . c o m */ private File generateAttachment() throws MessagingException { try { Resource resource = new ClassPathResource(attachment); return resource.getFile(); } catch (IOException e) { logger.error(",?", e); throw new MessagingException("?", e); } }
From source file:infowall.infrastructure.service.GroovyExecutorTest.java
@Test public void testExec() throws Exception { Resource resource = new ClassPathResource("/groovy/simple_groovy.groovy"); GroovyExecutor executor = new GroovyExecutor(); assertThat(executor.exec(resource.getFile()), is("hello world\n")); }
From source file:com.it.j2ee.modules.email.MimeMailService.java
/** * ?classpath./*from w w w. ja v a 2s . c o m*/ */ private File generateAttachment() throws MessagingException { try { Resource resource = new ClassPathResource("/email/mailAttachment.txt"); return resource.getFile(); } catch (IOException e) { logger.error(",?", e); throw new MessagingException("?", e); } }
From source file:com.scf.web.context.WebContext.java
/** * * @return//from w w w . ja v a 2 s .co m */ public String getWebRootPath() { if (WEB_ROOT_PATH == null) { try { Resource resource = new ServletContextResource(getServletContext(), "/"); WEB_ROOT_PATH = resource.getFile().getAbsolutePath(); if (WEB_ROOT_PATH == null) { WEB_ROOT_PATH = resource.getFile().getAbsoluteFile().getAbsolutePath(); } WEB_ROOT_PATH = FileUtilies.fixPath(WEB_ROOT_PATH); WEB_ROOT_PATH += "/"; } catch (NullPointerException e1) { throw new IllegalAccessError("Can not init system root path. please check."); } catch (IOException e2) { throw new IllegalAccessError("Can not init system root path. please check."); } } return WEB_ROOT_PATH; }