List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:com.searchbox.framework.service.DirectoryService.java
public String getApplicationRelativePath(String fname) { Resource tempDir = context.getResource("WEB-INF/temp/"); File file;// www . j a v a 2 s . c om try { file = new File(tempDir.getFile().getAbsolutePath() + "/" + fname); LOGGER.debug("Application absolutePath: " + context.getResource("").getFile().getAbsolutePath()); String relative = context.getResource("").getFile().toURI().relativize(file.toURI()).getPath(); return relative; } catch (IOException e) { LOGGER.error("Could not create temp file in directoryService", e); } return null; }
From source file:org.adsync4j.testutils.ldap.EmbeddedLdapServerFactoryBean.java
@Override public EmbeddedUnboundIDLdapServer getObject() throws Exception { EmbeddedUnboundIDLdapServer server = createEmbeddedUnboundIDLdapServer(); for (Resource[] resources : _schemas) { for (Resource resource : resources) { try { server.addSchema(resource.getFile()); } catch (IOException e) { server.addSchema(resourceToInputStream(resource)); }//from w ww .ja v a 2s . co m } } server.setIncludeStandardSchema(_includeStandardSchema).setRootDNs(_rootDNs) .setLdifs(resourceArrayListToInputStreamList(_ldifs)); if (_port != null) { server.setPort(_port); } if (_bindCredentials != null) { server.setBindCredentials(_bindCredentials); } return server.init(); }
From source file:org.jasig.ssp.util.importer.job.tasklet.BatchInitializer.java
private void copyDeleteFiles(File processDirectory) throws IOException { for (Resource resource : resources) { File file = resource.getFile(); logger.info("Move file from " + file.getPath() + " to " + processDirectory.getPath()); file.renameTo(new File(processDirectory, file.getName())); }//www . j a v a 2 s .c o m }
From source file:fr.acxio.tools.agia.file.pdf.MergingPDDocumentFactoryTest.java
@Test public void testTwoDocuments() throws Exception { MergingPDDocumentFactory aFactory = new MergingPDDocumentFactory(); ResourcesFactory aResourcesFactory = mock(ResourcesFactory.class); Resource aFileResource1 = mock(Resource.class); when(aFileResource1.getFile()).thenReturn(new File("src/test/resources/testFiles/content1.pdf")); Resource aFileResource2 = mock(Resource.class); when(aFileResource2.getFile()).thenReturn(new File("src/test/resources/testFiles/content2.pdf")); when(aResourcesFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource1, aFileResource2 }); PDDocumentContainer aContainer = aFactory.fromParts(aResourcesFactory); assertNotNull(aContainer);//w ww . ja v a2s . co m assertNotNull(aContainer.getParts()); assertEquals(2, aContainer.getParts().size()); assertNotNull(aContainer.getParts().get(0)); assertNotNull(aContainer.getParts().get(1)); aContainer.close(); }
From source file:hm.binkley.spring.axon.AxonDistributedCommandBusAutoConfiguration.java
@Bean @ConditionalOnMissingBean// w w w. j a v a 2 s . c o m public JChannel jChannel() throws Exception { final Resource configuration = properties.getConfiguration(); return null == configuration ? new JChannel() : new JChannel(configuration.getFile()); }
From source file:com.searchbox.framework.service.DirectoryService.java
public Boolean fileExists(String fname) { Resource tempDir = context.getResource("WEB-INF/temp/"); File newFile;//from w w w. j ava 2 s. c om try { newFile = new File(tempDir.getFile().getAbsolutePath() + "/" + fname); return newFile.exists(); } catch (IOException e) { LOGGER.error("Could not create temp file in directoryService", e); } return false; }
From source file:org.jasig.ssp.util.importer.job.tasklet.BatchInitializer.java
private File createDirectory(Resource directory) throws Exception { File dir = directory.getFile(); if (!dir.exists()) { if (!dir.mkdirs()) { logger.error("Process directory was not created at " + dir.getPath()); throw new Exception("Process directory was not created at " + dir.getPath()); }//from www .java2 s .com } else cleanDirectoryQuietly(dir); return dir; }
From source file:coral.reef.web.ReefController.java
@RequestMapping(value = "/assets/**") public void icon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException { String path = ((String) httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); Resource res = appContext.getResource("classpath:" + path); File f = res.getFile(); FileSystemResource fr = new FileSystemResource(f); String type = servletContext.getMimeType(f.getAbsolutePath()); httpResponse.setContentType(type);//from ww w . j a v a 2 s. c o m IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream()); }
From source file:com.lnu.agile.controller.TrackController.java
@RequestMapping(value = RestURIConstants.GET_TRACK, method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody TrackInfo getTrack(@PathVariable("id") int trackId) { try {/*from w w w. j ava2s .c om*/ logger.info("Start getTracks. ID = " + trackId); Resource resource = new DefaultResourceLoader().getResource(PATH); FileParser parser = new XmlToJsonParser(); TrackInfoArray allTracks = parser.parseFile(resource.getFile().getAbsolutePath()); return allTracks.getTracks().get(0).getTrackInfo().get(trackId); } catch (IOException ex) { java.util.logging.Logger.getLogger(TrackController.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:org.archone.ad.schema.DisplayAttributeHelper.java
public void init() throws FileNotFoundException, IOException { Resource r = applicationContext.getResource(this.configPath); FileReader attrDefs = new FileReader(r.getFile()); JSONDeserializer jd = new JSONDeserializer().use(null, LinkedList.class).use("values", DisplayAttribute.class); this.displayAttributeList = (List<DisplayAttribute>) jd.deserialize(attrDefs); for (DisplayAttribute displayAttribute : displayAttributeList) { if (displayAttribute.getAccess() != null && displayAttribute.getAccess().contains("user")) { if (displayAttribute.getApiName() == null) { displayAttribute.setApiName(displayAttribute.getLdapName()); }// ww w .jav a 2s.c om this.apiNameIndex.put(displayAttribute.getApiName(), displayAttribute); this.ldapNameIndex.put(displayAttribute.getLdapName(), displayAttribute); } } }