List of usage examples for org.springframework.core.io Resource getFilename
@Nullable String getFilename();
From source file:org.mongeez.reader.ChangeSetReader.java
public List<ChangeSet> getChangeSets(List<Resource> files) { List<ChangeSet> changeSets = new ArrayList<ChangeSet>(); try {/*from w w w . jav a 2 s . c om*/ Digester digester = new Digester(); digester.setValidating(false); digester.addObjectCreate("mongoChangeLog", ChangeSetList.class); digester.addObjectCreate("mongoChangeLog/changeSet", ChangeSet.class); digester.addSetProperties("mongoChangeLog/changeSet"); digester.addSetNext("mongoChangeLog/changeSet", "add"); digester.addObjectCreate("mongoChangeLog/changeSet/script", Script.class); digester.addBeanPropertySetter("mongoChangeLog/changeSet/script", "body"); digester.addSetNext("mongoChangeLog/changeSet/script", "add"); for (Resource file : files) { ChangeSetList changeFileSet = (ChangeSetList) digester.parse(file.getInputStream()); for (ChangeSet changeSet : changeFileSet.getList()) { changeSet.setFile(file.getFilename()); } changeSets.addAll(changeFileSet.getList()); } } catch (IOException e) { e.printStackTrace(); } catch (org.xml.sax.SAXException e) { e.printStackTrace(); } return changeSets; }
From source file:com.searchbox.collection.pubmed.PubmedCollection.java
public ItemReader<Resource> reader() { return new ItemReader<Resource>() { boolean hasmore = true; @Override/*from ww w . j av a2 s .co m*/ public Resource read() { if (hasmore) { hasmore = false; Resource resource = context.getResource("classpath:data/pubmedIndex.xml"); if (resource.exists()) { LOGGER.info("Read has created this resource: " + resource.getFilename()); return resource; } } return null; } }; }
From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpoint.java
@RequestMapping(method = RequestMethod.GET) public void invoke(HttpServletResponse response) throws IOException { if (!isAvailable()) { response.setStatus(HttpStatus.NOT_FOUND.value()); return;//w w w.j ava 2 s.co m } Resource file = new FileSystemResource(logfile); response.setContentType(MediaType.TEXT_PLAIN_VALUE); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); FileCopyUtils.copy(file.getInputStream(), response.getOutputStream()); }
From source file:org.jasig.ssp.util.importer.job.tasklet.PartialUploadGuard.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Date lastAllowedModificationTime = getLastAllowedModifiedDate(); if (resources == null || resources.length == 0) { logger.error("Job not started. No resources found"); stopJob();//from w ww . j av a 2 s . c o m return RepeatStatus.FINISHED; } for (Resource resource : resources) { Date modified = new Date(resource.lastModified()); if (modified.after(lastAllowedModificationTime)) { logger.info(FILE_SOAK_TIME + resource.getFilename()); stopJob(); return RepeatStatus.FINISHED; } } return RepeatStatus.FINISHED; }
From source file:net.sourceforge.vulcan.spring.jdbc.JdbcSchemaMigrator.java
private void executeSql(final Resource resource) throws IOException { final String text = loadResource(resource); log.info("Running migration script " + resource.getFilename()); final String[] commands = text.split(";"); for (String command : commands) { final String trimmed = command.trim(); if (StringUtils.isBlank(trimmed)) { continue; }/* w w w .j a va 2s. co m*/ jdbcTemplate.execute(new StatementCallback() { public Object doInStatement(Statement stmt) throws SQLException, DataAccessException { stmt.execute(trimmed); final Connection conn = stmt.getConnection(); if (!conn.getAutoCommit()) { conn.commit(); } return null; } }); } }
From source file:org.mitre.jose.TestJWKSetKeyStore.java
@Test(expected = IllegalArgumentException.class) public void ksBadJWKinput() throws IOException { byte jwtbyte[] = RSAjwk.toString().getBytes(); FileOutputStream out = new FileOutputStream(ks_file_badJWK); out.write(jwtbyte);//from ww w . j a va 2s . com out.close(); JWKSetKeyStore ks_badJWK = new JWKSetKeyStore(); Resource loc = new FileSystemResource(ks_file_badJWK); assertTrue(loc.exists()); ks_badJWK.setLocation(loc); assertEquals(loc.getFilename(), ks_file_badJWK); ks_badJWK = new JWKSetKeyStore(null); }
From source file:se.inera.intyg.intygstjanst.web.service.bean.IntygBootstrapBean.java
@PostConstruct public void initData() throws IOException { List<Resource> metadataFiles = getResourceListing("bootstrap-intyg/*-metadata.json"); List<Resource> contentFiles = getResourceListing("bootstrap-intyg/*-content.json"); Collections.sort(metadataFiles, new ResourceFilenameComparator()); Collections.sort(contentFiles, new ResourceFilenameComparator()); int count = metadataFiles.size(); for (int i = 0; i < count; i++) { Resource metadata = metadataFiles.get(i); Resource content = contentFiles.get(i); LOG.debug("Loading metadata " + metadata.getFilename() + " and content " + content.getFilename()); addIntyg(metadata, content);//from ww w .j a v a 2 s . c o m addSjukfall(metadata, content); } }
From source file:org.zalando.stups.spring.boot.actuator.ExtInfoEndpointConfiguration.java
@Bean public InfoEndpoint infoEndpoint() throws Exception { LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>(); for (String filename : getAllPropertiesFiles()) { Resource resource = new ClassPathResource("/" + filename); Properties properties = new Properties(); if (resource.exists()) { properties = PropertiesLoaderUtils.loadProperties(resource); String name = resource.getFilename(); info.put(name.replace(PROPERTIES_SUFFIX, PROPERTIES_SUFFIX_REPLACEMENT), Maps.fromProperties(properties)); } else {/* w w w . j a v a 2 s . c o m*/ if (failWhenResourceNotExists()) { throw new RuntimeException("Resource : " + filename + " does not exist"); } else { log.info("Resource {} does not exist", filename); } } } return new InfoEndpoint(info); }
From source file:mvctest.web.TestController.java
private String getFlowIdFromFileName(Resource flowResource) { return StringUtils.stripFilenameExtension(flowResource.getFilename()); }
From source file:net.longfalcon.newsj.Config.java
@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED) public void init() { properties = new Properties(); for (Resource resource : propertyLocations) { try {/*from w ww.j a v a2s.c om*/ properties.load(resource.getInputStream()); } catch (IOException e) { _log.error("Unable to read from resource " + resource.getFilename()); } } defaultSite = siteDAO.getDefaultSite(); }