List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:de.extra.client.starter.ExtraClientParametersTest.java
@Test public void testExtraClientParameters() throws Exception { final List<String> errors = Collections.<String>emptyList(); final Resource globalConfigDir = new ClassPathResource("/testglobalconfig"); final File globalConfigPath = globalConfigDir.getFile(); final Resource configDir = new ClassPathResource("/testconfig"); final File configPath = configDir.getFile(); final Resource logDir = new ClassPathResource("/testlog"); final File logPath = logDir.getFile(); final Resource backupDir = new ClassPathResource("/testBackup"); final File backupPath = backupDir.getFile(); final ExtraClientParameters parameters = new ExtraClientParameters("mandant", globalConfigPath, configPath, logPath, "outputConfirm", "outputFailure", backupPath, false, false, errors); assertFalse(parameters.getShowHelp()); assertEquals(globalConfigPath, parameters.getGlobalConfigurationDirectory()); assertEquals(configPath, parameters.getConfigurationDirectory()); assertEquals(logPath, parameters.getLogDirectory()); assertEquals(errors, parameters.getErrors()); assertEquals(backupPath, parameters.getBackupDirectory()); assertEquals(true, parameters.shouldCreateBackup()); assertEquals("mandant", parameters.getMandant()); assertEquals("outputConfirm", parameters.getOutputConfirm()); assertEquals("outputFailure", parameters.getOutputFailure()); }
From source file:common.services.generic.GenericCacheService.java
public void setPath(Resource res) { try {/*from w w w . ja v a 2 s. c om*/ File f = res.getFile(); if (f.exists()) { if (f.isFile()) { f.delete(); f.mkdir(); } } else { f.mkdirs(); //f.mkdir(); } if (f.exists() && f.isDirectory()) path = f.getCanonicalPath() + "/"; else throw new NullPointerException("cache folder not found for " + getClass().getName()); } catch (IOException e) { path = null; throw new NullPointerException("cache folder not found for " + getClass().getName()); } //System.out.println("----------------------------path = "+this.path); }
From source file:de.extra.client.starter.ClientArgumentsTest.java
@Test public void testClientArguments() throws Exception { final Resource globalConfigDir = new ClassPathResource("testglobalconfig"); final String globalConfigPath = globalConfigDir.getFile().getAbsolutePath(); final Resource configDir = new ClassPathResource("testconfig"); final String configPath = configDir.getFile().getAbsolutePath(); final Resource logDir = new ClassPathResource("testlog"); final String logPath = logDir.getFile().getAbsolutePath(); final String[] args = { "-m", MANDANT_NAME, "-g", globalConfigPath, "-c", configPath, "-l", logPath, "-oc", "xxx", "-of", "yyy" }; final ClientArgumentParser arguments = new ClientArgumentParser(args, EXITER); final ExtraClientParameters parameters = arguments.parseArgs(); assertEquals(MANDANT_NAME, parameters.getMandant()); assertEquals(globalConfigDir.getFile(), parameters.getGlobalConfigurationDirectory()); assertEquals(configDir.getFile(), parameters.getConfigurationDirectory()); assertEquals(logDir.getFile(), parameters.getLogDirectory()); assertEquals("xxx", parameters.getOutputConfirm()); assertEquals("yyy", parameters.getOutputFailure()); }
From source file:gov.va.vinci.leo.cr.ExternalCollectionReader.java
/** * Load a resource object from the path to the CollectionReader descriptor then use the framework to initialize the reader. * * @param collectionReaderDescriptor Path to the CollectionReader descriptor. * @throws ResourceInitializationException if there is an error reading the descriptor. * @throws IOException if there is an error in the XML of the descriptor. * @throws InvalidXMLException if the CollectionReader cannot be initialized by the framework. *//*w w w .j a va2s.co m*/ private void setCollectionReader(String collectionReaderDescriptor) throws IOException, InvalidXMLException, ResourceInitializationException { ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); Resource resource = loader.getResource(collectionReaderDescriptor); setCollectionReader(resource.getFile()); }
From source file:com.gst.infrastructure.core.boot.EmbeddedTomcatWithSSLConfiguration.java
public File getFile(Resource resource) throws IOException { try {/*from ww w .jav a2 s .c o m*/ return resource.getFile(); } catch (IOException e) { // Uops.. OK, try again (below) } try { URL url = resource.getURL(); /** * // If this creates filenames that are too long on Win, // then * could just use resource.getFilename(), // even though not unique, * real risk prob. min.bon String tempDir = * System.getProperty("java.io.tmpdir"); tempDir = tempDir + "/" + * getClass().getSimpleName() + "/"; String path = url.getPath(); * String uniqName = path.replace("file:/", "").replace('!', '_'); * String tempFullPath = tempDir + uniqName; **/ // instead of File.createTempFile(prefix?, suffix?); File targetFile = new File(resource.getFilename()); long len = resource.contentLength(); if (!targetFile.exists() || targetFile.length() != len) { // Only // copy // new // files FileUtils.copyURLToFile(url, targetFile); } return targetFile; } catch (IOException e) { // Uops.. erm, give up: throw new IOException("Cannot obtain a File for Resource: " + resource.toString(), e); } }
From source file:com.github.javarch.support.data.LocalFileStorage.java
/** * Constructs a local file storage./*ww w . j a v a2 s .c o m*/ * @param storageUrl the logical URL pointing to the root of this file storage * @param storageDirectory the path to the base directory on the filesystem where files physically reside; created if necessary. */ public LocalFileStorage(String storageUrl, Resource storageDirectory) { this.storageUrl = storageUrl; try { this.storageDirectory = storageDirectory.getFile(); this.storageDirectory.createNewFile(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.slc.sli.ingestion.tool.OfflineToolTest.java
@Test public void negativeTestMain1() throws Throwable { // Testing more than 1 input arguments reset();/*www. j a v a 2s .c o m*/ String[] args = new String[2]; PrivateAccessor.invoke(offlineTool, "start", new Class[] { args.getClass() }, new Object[] { args }); Mockito.verify(logger, Mockito.times(1)).error("validationTool:Illegal options"); // Testing nonexistent file reset(); String[] args4 = new String[1]; args4[0] = "/invalid/nonExist.ctl"; PrivateAccessor.invoke(offlineTool, "start", new Class[] { args4.getClass() }, new Object[] { args4 }); Mockito.verify(logger, Mockito.times(1)).error(args4[0] + " does not exist"); // Passing a directory reset(); Resource fileResource = new ClassPathResource("invalid/"); args4[0] = fileResource.getFile().toString(); PrivateAccessor.invoke(offlineTool, "start", new Class[] { args4.getClass() }, new Object[] { args4 }); Mockito.verify(logger, Mockito.times(1)) .error("Illegal option - directory path. Expecting a Zip or a Ctl file"); }
From source file:gallery.service.rss.RssServiceImpl.java
public void setPath(Resource res) { try {/*from w w w . j a v a2 s .c o m*/ File f = res.getFile(); if (f.exists() && f.isDirectory()) path = f.getCanonicalPath() + "/"; else throw new NullPointerException("xml path not found for RSS"); } catch (IOException e) { path = null; throw new NullPointerException("xml path not found for RSS"); } //System.out.println("----------------------------path = "+this.path); }
From source file:br.eb.ime.labprog3.tam.DefaultController.java
@RequestMapping(value = "index") public String index(ModelMap map) { String fileName = "../../resources/xml/aeroportos.xml"; Resource resource = null; resource = new ClassPathResource(fileName); AeroportoDAO dao = null;/*from ww w . j a v a2 s .com*/ try { dao = new AeroportoDAO(resource.getFile()); } catch (IOException ex) { Logger.getLogger(DefaultController.class.getName()).log(Level.SEVERE, null, ex); } List<Aeroporto> listaDeAeroportos = null; if (dao != null) { listaDeAeroportos = dao.listarAeroportos(); map.addAttribute("listaDeAeroportos", listaDeAeroportos); } return "index"; }
From source file:com.searchbox.collection.pubmed.PubmedCollection.java
public ItemProcessor<Resource, File> itemProcessor() { return new ItemProcessor<Resource, File>() { @Override//from w w w . ja va 2 s . com public File process(Resource item) throws IOException { LOGGER.info("Processing stuff here..."); return item.getFile(); } }; }