List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:org.psikeds.knowledgebase.xml.StaxParserTest.java
/** * Test method for {@link org.psikeds.knowledgebase.xml.impl.XMLParser} *///www . j a v a 2 s. c o m @Test public void testXmlParserWithSpringResourceAndDefaultSettings() { final TestCallbackHandler tcbh = new TestCallbackHandler(); long numElems = 0; try { LOGGER.info("Parsing XML " + XML + " using Spring-Resource ..."); final Resource xml = new FileSystemResource(XML); final KBParser parser = new XMLParser(xml, ENCODING, tcbh); numElems = parser.parseXmlElements(); LOGGER.info("... done."); } catch (final Exception ex) { final String message = "XML Parsing failed: " + ex.getMessage(); LOGGER.info(message); fail(message); } assertEquals("We expected just 1 XML-Element (RootElement) but got " + numElems, 1, numElems); assertEquals("Number of Elements counted by Parser (" + numElems + ") and CallBackHandler (" + tcbh.counter + ") are not equal.", numElems, tcbh.counter); }
From source file:org.apache.uima.ruta.resource.MultiTreeWordList.java
/** * Constructs a TreeWordList from a file with path = filename * /* ww w . j a va 2 s .c om*/ * @param pathnames * path of the file to create a TextWordList from */ public MultiTreeWordList(String[] pathnames) throws IOException { this.root = new MultiTextNode(); this.costMap = new EditDistanceCostMap(); for (String pathname : pathnames) { load(new FileSystemResource(pathname)); } }
From source file:com.lm.lic.manager.controller.HandangoWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyHgoRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {//from ww w. ja va 2s . c om String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } return valid; }
From source file:com.lm.lic.manager.controller.YouparkWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyYouparkRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {//ww w.ja v a 2 s . c om String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } valid = true; return valid; }
From source file:net.solarnetwork.node.setup.impl.DefaultKeystoreService.java
@Override public Iterable<BackupResource> getBackupResources() { File ksFile = new File(getKeyStorePath()); if (!(ksFile.isFile() && ksFile.canRead())) { return Collections.emptyList(); }//from ww w. j av a 2 s . c o m List<BackupResource> result = new ArrayList<BackupResource>(1); result.add(new ResourceBackupResource(new FileSystemResource(ksFile), BACKUP_RESOURCE_NAME_KEYSTORE, getKey())); return result; }
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 w ww . ja v a 2s . c o m*/ 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:com.pamarin.income.controller.SuggestionCtrl.java
private void sendEmail2Admin(final File attachFile) { mailSender.send(new MailCallback() { @Override/*w w w.j a va2s . c o m*/ public void execute(MimeMessageHelper helper) throws Exception { if (attachFile != null) { FileSystemResource file = new FileSystemResource(attachFile); helper.addAttachment(attachFile.getName(), file); } helper.setSubject("?" + app.getName()); helper.setText(getSuggestion().getType() + " : " + getSuggestion().getMessage()); helper.setTo(destinationReceiveEmail); } }); }
From source file:com.rxx.common.util.MailUtil.java
/** * html// w w w . j a v a2 s . com * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param imgs * @param toUser * @throws javax.mail.MessagingException */ public static void sendNews(String host, int port, String userName, String password, String title, String content, List<String> imgs, String[] toUser) throws MessagingException, javax.mail.MessagingException { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); // boolean,MimeMessageHelpertrue // multipart MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true); // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); int i = 0; for (String imagePath : imgs) { FileSystemResource img = new FileSystemResource(new File(imagePath)); messageHelper.addInline(i + "", img); i++; } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); // senderImpl.send(mailMessage); }
From source file:org.apache.uima.ruta.resource.MultiTreeWordList.java
public MultiTreeWordList(List<File> files) throws IOException { this.root = new MultiTextNode(); this.costMap = new EditDistanceCostMap(); for (File file : files) { load(new FileSystemResource(file)); }//from w w w.j a v a 2 s . co m }
From source file:com.sitewhere.configuration.TomcatConfigurationResolver.java
@Override public ApplicationContext resolveTenantContext(ITenant tenant, IVersion version, ApplicationContext global) throws SiteWhereException { LOGGER.info("Loading Spring configuration ..."); File sitewhereConf = getSiteWhereConfigFolder(); File tenantConfigFile = getTenantConfigurationFile(sitewhereConf, tenant, version); GenericApplicationContext context = new GenericApplicationContext(global); // Plug in custom property source. Map<String, Object> properties = new HashMap<String, Object>(); properties.put("sitewhere.edition", version.getEditionIdentifier().toLowerCase()); properties.put("tenant.id", tenant.getId()); MapPropertySource source = new MapPropertySource("sitewhere", properties); context.getEnvironment().getPropertySources().addLast(source); // Read context from XML configuration file. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new FileSystemResource(tenantConfigFile)); context.refresh();/* www .j a v a 2 s . com*/ return context; }