List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.jasig.ssp.util.importer.job.tasklet.PartialUploadGuard.java
public void setDirectory(Resource directory) throws PartialUploadGuardException, IOException { this.directory = directory; if (!directory.getFile().exists()) throw new PartialUploadGuardException( "Input directory does not exist. Locoation:" + directory.getFile().getPath()); }
From source file:org.sift.batch.tuple.TupleLineMapper.java
/** * Interface method implementation. Maps the input line into a {@link Tuple} with line number as key and the line contents as a single String value * @see org.springframework.batch.item.file.LineMapper#mapLine(java.lang.String, int) *///from w w w . j av a2s.c o m public Tuple mapLine(String line, int lineNumber) throws Exception { Resource currentResource = this.itemReader == null ? this.resource : this.itemReader.getCurrentResource(); URI reviewURI = new URI(currentResource.getFile().getAbsolutePath() + "#" + String.valueOf(lineNumber)); Tuple tuple = new Tuple(Fields.KEY, Fields.SOURCES, Fields.VALUES); //Add key tuple.setValue(Fields.KEY, String.valueOf(lineNumber)); //Add sources List<URI> sourceURI = new ArrayList<URI>(); sourceURI.add(reviewURI); tuple.setValue(Fields.SOURCES, sourceURI); //Add values List<String> initialValues = new ArrayList<String>(); initialValues.add(line); tuple.setValue(Fields.VALUES, initialValues); return tuple; }
From source file:org.web4thejob.orm.CreateSchemaTest.java
@Test public void schemaExportTest() throws IOException, SQLException { Log4jConfigurer.initLogging("classpath:org/web4thejob/conf/log4j.xml"); Properties datasource = new Properties(); datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream()); final Configuration configuration = new Configuration(); configuration.setProperty(AvailableSettings.DIALECT, datasource.getProperty(DatasourceProperties.DIALECT)); configuration.setProperty(AvailableSettings.DRIVER, datasource.getProperty(DatasourceProperties.DRIVER)); configuration.setProperty(AvailableSettings.URL, "jdbc:hsqldb:mem:mydb"); configuration.setProperty(AvailableSettings.USER, datasource.getProperty(DatasourceProperties.USER)); configuration.setProperty(AvailableSettings.PASS, datasource.getProperty(DatasourceProperties.PASSWORD)); final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); Connection connection = serviceRegistry.getService(ConnectionProvider.class).getConnection(); Statement statement = connection.createStatement(); statement.executeUpdate("CREATE SCHEMA w4tj;"); statement.close();//from w w w.j a va2 s. co m PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { for (Resource resource : resolver.getResources("classpath*:org/web4thejob/orm/**/*.hbm.xml")) { if (resource.getFile().getName().equals("AuxiliaryDatabaseObjects.hbm.xml")) continue; configuration.addFile(resource.getFile()); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } SchemaExport schemaExport = new SchemaExport(serviceRegistry, configuration); schemaExport.execute(Target.EXPORT, SchemaExport.Type.CREATE); if (!schemaExport.getExceptions().isEmpty()) { throw new RuntimeException((Throwable) schemaExport.getExceptions().get(0)); } }
From source file:com.xyxy.platform.modules.nosql.redis.JedisScriptExecutor.java
/** * Lua Script, ?Spring Resource?.//from w w w. j a v a2s .c o m */ public void loadFromFile(final String scriptPath) throws JedisDataException { String scriptContent; try { Resource resource = new DefaultResourceLoader().getResource(scriptPath); scriptContent = FileUtils.readFileToString(resource.getFile()); } catch (IOException e) { throw new IllegalArgumentException(scriptPath + " is not exist.", e); } load(scriptContent); }
From source file:fr.acxio.tools.agia.file.pdf.MergingPDDocumentFactoryTest.java
@Test public void testSingleDocument() throws Exception { MergingPDDocumentFactory aFactory = new MergingPDDocumentFactory(); ResourcesFactory aResourcesFactory = mock(ResourcesFactory.class); Resource aFileResource = mock(Resource.class); when(aFileResource.getFile()).thenReturn(new File("src/test/resources/testFiles/content1.pdf")); when(aResourcesFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource }); PDDocumentContainer aContainer = aFactory.fromParts(aResourcesFactory); assertNotNull(aContainer);/*from w ww . j a v a2 s .com*/ assertNotNull(aContainer.getParts()); assertEquals(1, aContainer.getParts().size()); assertNotNull(aContainer.getParts().get(0)); aContainer.close(); }
From source file:fr.acxio.tools.agia.file.pdf.MergingPDDocumentFactoryTest.java
@Test public void testDoubleDocument() throws Exception { MergingPDDocumentFactory aFactory = new MergingPDDocumentFactory(); ResourcesFactory aResourcesFactory = mock(ResourcesFactory.class); Resource aFileResource = mock(Resource.class); when(aFileResource.getFile()).thenReturn(new File("src/test/resources/testFiles/content1.pdf")); when(aResourcesFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource, aFileResource }); PDDocumentContainer aContainer = aFactory.fromParts(aResourcesFactory); assertNotNull(aContainer);//from w w w . ja v a2s . c om assertNotNull(aContainer.getParts()); assertEquals(2, aContainer.getParts().size()); assertNotNull(aContainer.getParts().get(0)); assertNotNull(aContainer.getParts().get(1)); aContainer.close(); }
From source file:fr.acxio.tools.agia.file.pdf.MergingPDDocumentFactoryTest.java
@Test public void testDocumentDoesNotExist() throws Exception { exception.expect(PDDocumentFactoryException.class); MergingPDDocumentFactory aFactory = new MergingPDDocumentFactory(); ResourcesFactory aResourcesFactory = mock(ResourcesFactory.class); Resource aFileResource = mock(Resource.class); when(aFileResource.getFile()).thenReturn(new File("src/test/resources/testFiles/contentX.pdf")); when(aResourcesFactory.getResources(anyMapOf(Object.class, Object.class))) .thenReturn(new Resource[] { aFileResource }); PDDocumentContainer aContainer = aFactory.fromParts(aResourcesFactory); assertNotNull(aContainer);/* ww w. j ava2 s. c o m*/ assertNotNull(aContainer.getParts()); assertEquals(1, aContainer.getParts().size()); assertNotNull(aContainer.getParts().get(0)); aContainer.close(); }
From source file:gallery.service.sitemap.SitemapServiceImpl.java
public void setPath(Resource res) { try {//from w ww . j av a 2 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 Sitemap"); } catch (IOException e) { path = null; throw new NullPointerException("xml path not found for Sitemap"); } //System.out.println("----------------------------path = "+this.path); }
From source file:gallery.service.sitemap.SitemapServiceImpl.java
public void setPath_tmp(Resource res) { try {/*from ww w .ja v a2s . c o m*/ File f = res.getFile(); if (f.exists() && f.isDirectory()) path_tmp = f.getCanonicalPath() + "/"; else throw new NullPointerException("xml path not found for Sitemap"); } catch (IOException e) { path_tmp = null; throw new NullPointerException("xml path not found for Sitemap"); } //System.out.println("----------------------------path = "+this.path); }
From source file:org.brekka.stillingar.spring.snapshot.WatchedResourceMonitor.java
@Override public void initialise(Resource resource) { try {/*from w w w . j a v a 2 s . co m*/ this.resourceFile = resource.getFile().toPath(); Path parent = resourceFile.getParent(); this.watchService = parent.getFileSystem().newWatchService(); this.watchKey = parent.register(this.watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE); } catch (IOException e) { throw new ConfigurationException( String.format("Failed to initialize watcher for resource '%s'", resource.toString()), e); } }