List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:net.peakplatform.sonar.plugins.spring.SpringSensor.java
private void checkXmlFile(final Project project, final SensorContext sensorContext, final org.sonar.api.resources.File beanFile) { String sourceDirectory = (String) project.getProperty(SpringPlugin.SOURCE_DIRECTORY); LOGGER.info("SpringSensor analyse sourceDirectory: " + sourceDirectory); File springBeanDefinition = this.projectFileSystem .resolvePath(sourceDirectory + "/" + beanFile.getLongName()); org.springframework.core.io.Resource beanDefinitionsXML = new FileSystemResource( springBeanDefinition.getAbsolutePath()); int beanCount = beanDefinitionReader.loadBeanDefinitions(beanDefinitionsXML); LOGGER.info("BeanClassCheck validate " + beanCount + " beans loaded."); BeanDefinitionRegistry beanDefinitionRegistry = beanDefinitionReader.getRegistry(); String[] beanDefinitionNames = beanDefinitionRegistry.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { LOGGER.info("BeanClassCheck validate beanDefinitionName: " + beanDefinitionName); BeanDefinition beanDefinition = beanDefinitionRegistry.getBeanDefinition(beanDefinitionName); BeanSourceCode beanSourceCode = new BeanSourceCode(beanFile, beanDefinition); for (BeanCheck beanCheck : springChecks) { LOGGER.info("SpringSensor analyse BeanCheck: " + beanCheck.getClass().getName()); beanCheck.validate(beanSourceCode, project); }//w w w. j a va2 s . com LOGGER.info("SpringSensor analyse beanSourceCode.getViolations().size(): " + beanSourceCode.getViolations().size()); for (Violation violation : beanSourceCode.getViolations()) { LOGGER.info("SpringSensor analyse violation.getMessage(): " + violation.getMessage()); sensorContext.saveViolation(violation); } } }
From source file:com.anuz.dummyapi.controller.ClientController.java
@RequestMapping(value = "/download_content_data/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public FileSystemResource getFiles(@PathVariable("id") int id, HttpServletResponse response) throws FileNotFoundException { String fileName = "content" + id + ".zip"; // //from w w w . j a v a 2s .c o m // byte[] buffer = new byte[1024]; // FileOutputStream fos = new FileOutputStream(CONSTANTS.CONTENTS+fileName); // ZipOutputStream zos=new ZipOutputStream(fos); // // ZipEntry ze= new ZipEntry("spy.log"); return new FileSystemResource(CONSTANTS.CONTENTS + fileName); }
From source file:com.autentia.wuija.mail.MailService.java
/** * send an e-mail/* w w w. j a v a 2 s. c om*/ * * @param to recipient e-mail * @param subject the subject of the e-mail * @param text the body of the e-mail * @param attachments an array of it * @throws EmailException if the e-mail cannot be prepare or send. */ public void send(String to, String subject, String text, File... attachments) { Assert.hasLength(to, "email 'to' needed"); Assert.hasLength(subject, "email 'subject' needed"); Assert.hasLength(text, "email 'text' needed"); if (log.isDebugEnabled()) { final boolean usingPassword = StringUtils.isNotBlank(mailSender.getPassword()); log.debug("Sending email to: '" + to + "' [through host: '" + mailSender.getHost() + ":" + mailSender.getPort() + "', username: '" + mailSender.getUsername() + "' usingPassword:" + usingPassword + "]."); log.debug("isActive: " + active); } if (!active) { return; } final MimeMessage message = mailSender.createMimeMessage(); try { // use the true flag to indicate you need a multipart message final MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(to); helper.setSubject(subject); helper.setFrom(getFrom()); helper.setText(text); if (attachments != null) { for (int i = 0; i < attachments.length; i++) { // let's attach each file final FileSystemResource file = new FileSystemResource(attachments[i]); helper.addAttachment(attachments[i].getName(), file); if (log.isDebugEnabled()) { log.debug("File '" + file + "' attached."); } } } } catch (MessagingException e) { final String msg = "Cannot prepare email message : " + subject + ", to: " + to; log.error(msg, e); throw new MailPreparationException(msg, e); } this.mailSender.send(message); }
From source file:me.springframework.di.maven.AbstractGeneratorMojo.java
final public void execute() throws MojoExecutionException, MojoFailureException { for (BeanFactory factory : getBeanFactories()) { Configuration configuration = load(new FileSystemResource(factory.getContextFile())); process(configuration, factory); }/*from ww w.j a va 2 s.co m*/ }
From source file:com.siberhus.tdfl.DflSimpleTest.java
@Test public void testDfpLifeCycle() throws DataFileLoaderException { LifecycleDfp dfp = new LifecycleDfp(); employeeDfl.setDataFileProcessor(dfp); employeeDfl.setResource(new FileSystemResource(XLS_FILE_IN_NAME)); employeeDfl.load();//from w w w . j a v a2 s. c o m System.out.println("++++++++ Summary ++++++++"); System.out.println("Start count = " + dfp.startCount); System.out.println("Finish count = " + dfp.finishCount); System.out.println("Update count = " + dfp.updateCount); System.out.println("Process item count = " + dfp.processItemCount); System.out.println("Item success count = " + dfp.itemSuccessCount); System.out.println("Item error count = " + dfp.itemErrorCount); System.out.println(dfp.itemStatusMap); }
From source file:org.openxdata.server.OpenXDataPropertyPlaceholderConfigurer.java
private void setLocation(File fileLocation) { if (fileLocation != null) { FileSystemResource resource = new FileSystemResource(fileLocation); setLocation(resource);/* w w w. j a v a2 s .c om*/ } }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java
/** * Test with multiple zip files, together they contain 6 text files with 20 * lines each.//from ww w . j a v a 2 s . com * * @throws Exception */ @Test public void testMultipleZipFiles() throws Exception { LOG.debug("testMultipleTarFiles"); ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_MULTIPLE_FILES), new FileSystemResource(ZIP_INPUT_SINGLE_FILE), new FileSystemResource(ZIP_INPUT_NESTED_DIRS) }); // call general setup last generalMultiResourceReaderSetup(mReader); // open with mock context mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { String item = null; int count = 0; do { item = mReader.read(); if (item != null) { count++; } } while (item != null); assertEquals(140, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:fr.acxio.tools.agia.tasks.FileCopyTaskletTest.java
@Test public void testExecuteDeleteOrigin() throws Exception { FileCopyTasklet aTasklet = new FileCopyTasklet(); aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/input.csv")); aTasklet.setDestination(new FileSystemResource("target/input-copy2.csv")); aTasklet.execute(null, null);/*from w w w . j ava 2 s.c o m*/ assertTrue(aTasklet.getDestination().getFile().exists()); aTasklet.setDeleteOrigin(true); aTasklet.setOrigin(new FileSystemResource("target/input-copy2.csv")); aTasklet.setDestination(new FileSystemResource("target/input-copy3.csv")); aTasklet.execute(null, null); assertTrue(aTasklet.getDestination().getFile().exists()); assertFalse(aTasklet.getOrigin().getFile().exists()); }
From source file:org.sakaiproject.login.springframework.SakaiHomeContextLoader.java
/** * Initialize the local ApplicationContext, link it to the shared context, and load shared definitions into the shared context. * * @param servletContext current servlet context * @return the new WebApplicationContext * @throws org.springframework.beans.BeansException * if the context couldn't be initialized */// ww w . ja v a2s.c o m public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException { WebApplicationContext rv = super.initWebApplicationContext(servletContext); ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) rv; if (configurableApplicationContext != null) { String sakaiHomeLocation = servletContext.getInitParameter(SAKAI_HOME_LOCATION_PARAM); String servletContextName = rv.getServletContext().getServletContextName(); if (sakaiHomeLocation == null || sakaiHomeLocation.length() == 0) { sakaiHomeLocation = servletContextName + SAKAI_HOME_CONTEXT_SUFFIX; } if (sakaiHomeLocation != null) { final String sakaiHomePath = ServerConfigurationService.getSakaiHomePath(); String[] locations = StringUtils.tokenizeToStringArray(sakaiHomeLocation, ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS); if (locations != null) { XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader( (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory()); for (int i = 0; i < locations.length; i++) { String resourcePath = sakaiHomePath + locations[i]; M_log.debug( servletContextName + " is attempting to load Spring beans from: " + resourcePath); if (new File(resourcePath).exists()) { reader.loadBeanDefinitions(new FileSystemResource(resourcePath)); } else { M_log.info(servletContext + " startup is skipping introspection of the resource: " + resourcePath + " because it does not exist."); } } } } } return rv; }