Example usage for org.springframework.core.io FileSystemResource FileSystemResource

List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource

Introduction

In this page you can find the example usage for org.springframework.core.io FileSystemResource FileSystemResource.

Prototype

public FileSystemResource(Path filePath) 

Source Link

Document

Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File .

Usage

From source file:com.wavemaker.tools.project.upgrade.swamis.WebInfActiveGridUpgradeTest.java

public void testWebInfUpgrade() throws Exception {

    StudioFileSystem fileSystem = new LocalStudioFileSystem();

    File sourceProjectRoot = new ClassPathResource(
            "com/wavemaker/tools/project/upgrade/swamis/webinfactivegridupgrade/").getFile();
    assertTrue(sourceProjectRoot.exists());

    File projectRoot = IOUtils.createTempDirectory("testWebInfUpgrade", "_dir");
    fileSystem.copyRecursive(new FileSystemResource(sourceProjectRoot.getAbsolutePath()),
            new FileSystemResource(projectRoot.getAbsolutePath() + "/"), new ArrayList<String>());
    // FileUtils.copyDirectory(sourceProjectRoot, projectRoot);

    Project p = new Project(new FileSystemResource(projectRoot.getAbsolutePath() + "/"),
            new LocalStudioFileSystem());
    File webinf = p.getWebInf().getFile();
    assertTrue(webinf.exists());// w  w  w . j ava2s  .co m

    File servicesConfig = new File(webinf, ConfigurationCompiler.RUNTIME_SERVICES);
    File managersConfig = new File(webinf, ConfigurationCompiler.RUNTIME_MANAGERS);
    File webxml = new File(webinf, ProjectConstants.WEB_XML);
    assertTrue(servicesConfig.exists());
    assertTrue(managersConfig.exists());
    assertTrue(webxml.exists());

    String webxmlContents = FileUtils.readFileToString(webxml);
    assertTrue(webxmlContents.contains("com.activegrid.runtime.server.CleanupListener"));
    assertFalse(webxmlContents.contains("com.wavemaker.runtime.server.CleanupListener"));

    WebInfActiveGridUpgrade upgrade = new WebInfActiveGridUpgrade();
    UpgradeInfo upgradeInfo = new UpgradeInfo();
    upgrade.doUpgrade(p, upgradeInfo);
    assertEquals("verbose was: " + upgradeInfo.getVerbose() + ", messages: " + upgradeInfo.getMessages(),
            "Removed com.activegrid references from web.xml\nRe-generated files: project-services.xml, project-managers.xml",
            upgradeInfo.getVerbose().get("-1.0").get(0));

    webxmlContents = FileUtils.readFileToString(webxml);
    assertFalse(webxmlContents.contains("com.activegrid.runtime.server.CleanupListener"));
    assertTrue(webxmlContents.contains("com.wavemaker.runtime.server.CleanupListener"));

    assertTrue(servicesConfig.exists());
    assertTrue(managersConfig.exists());

    String servicesConfigContents = FileUtils.readFileToString(servicesConfig);
    String managersConfigContents = FileUtils.readFileToString(managersConfig);

    assertFalse(servicesConfigContents.contains("activegrid"));
    assertFalse(managersConfigContents.contains("activegrid"));
}

From source file:de.thm.arsnova.config.ExtraConfig.java

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    configurer.setLocations(new Resource[] { new ClassPathResource("arsnova.properties.example"),
            new FileSystemResource("/etc/arsnova/arsnova.properties"), });
    configurer.setIgnoreResourceNotFound(true);
    configurer.setIgnoreUnresolvablePlaceholders(false);
    return configurer;
}

From source file:org.nekorp.workflow.desktop.data.access.rest.ImagenDAOImp.java

@Override
public ImagenMetadata saveImage(BufferedImage image) {
    try {/* w  w  w .  j a va 2s .c  o  m*/
        ImagenMetadata r = factory.getTemplate().getForObject(factory.getRootUlr() + "/upload/url",
                ImagenMetadata.class);
        File file = new File("data/upload.jpg");
        ImageIO.write(image, "jpg", file);
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        form.add("myFile", new FileSystemResource(file));
        r = factory.getTemplate().postForObject(r.getUploadUrl(), form, ImagenMetadata.class);
        File cache = new File("data/" + r.getRawBlobKey());
        file.renameTo(cache);
        return r;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:edu.usf.cutr.fdot7.gui.SessionForm.java

/** Creates new form OSMSessionForm */
public SessionForm() {
    factory = new XmlBeanFactory(new FileSystemResource(
            System.getProperty("user.dir") + System.getProperty("file.separator") + "data-source.xml"));
    initComponents();/*w w w  . j  a v a2 s  . co m*/
    this.setLocationRelativeTo(null);
    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            Test.mutex.release();
        }
    });
}

From source file:com.netflix.genie.test.web.configs.IntegrationTestingConfiguration.java

/**
 * Returns a temporary directory as the jobs resource.
 *
 * @return The job dir as a resource.//  ww  w .jav  a  2s.c om
 */
@Bean
public Resource jobsDir() {
    this.jobsDir = Files.createTempDir();
    if (!this.jobsDir.exists() && !this.jobsDir.mkdirs()) {
        throw new IllegalArgumentException("Unable to create directories: " + this.jobsDir);
    }

    String jobsDirPath = this.jobsDir.getAbsolutePath();
    final String slash = "/";
    if (!jobsDirPath.endsWith(slash)) {
        jobsDirPath = jobsDirPath + slash;
    }

    return new FileSystemResource(jobsDirPath);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.environment.WindowsFileReadingEnvironmentFactory.java

public Environment create(ConfigResponse config) throws PluginException {
    try {/*from ww w.  ja  va 2  s.  c  om*/
        Environment environment = new Environment();
        Resource wrapperConf = new FileSystemResource(
                Metric.decode(config.getValue("installpath")) + "/conf/wrapper.conf");
        if (wrapperConf.exists()) {
            environment.setJvmOptions(createJvmOptions(wrapperConf));
            environment.setJavaHome(createJavaHome(wrapperConf));
            return environment;
        }
        return environment;
    } catch (Exception e) {
        throw new PluginException(
                "Unable to read existing tc Runtime configuration.  Cause: " + e.getMessage());
    }
}

From source file:org.createnet.raptor.auth.service.YamlFileApplicationContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {

    File configFile = new File(configPath);
    if (!configFile.exists()) {
        logger.warn("Configurations file does not exists: {}", configPath);
        return;// w  ww .j a  v a2 s .  c o  m
    }

    try {

        String context = System.getenv("SPRING_PROFILES_ACTIVE");
        if (context == null || context.isEmpty()) {
            context = "default";
        }

        Resource resource = new FileSystemResource(configFile);
        YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader();
        PropertySource<?> yamlTestProperties = sourceLoader.load("etcProperties", resource, context);
        applicationContext.getEnvironment().getPropertySources().addFirst(yamlTestProperties);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:com.ar.dev.tierra.api.controller.FiscalController.java

@RequestMapping(value = "/factura_a", method = RequestMethod.POST)
@ResponseBody//  w ww .j a  va  2  s  .  co  m
public FileSystemResource getFactura_a(@PathParam("factura") int factura, @PathParam("cliente") int cliente)
        throws IOException, InterruptedException {
    List<DetalleFactura> detalles = facadeService.getDetalleFacturaDAO().facturaDetalle(factura);
    Cliente c = facadeService.getClienteDAO().searchById(cliente);
    facadeService.getFiscalDAO().factura_a(detalles, c);
    return new FileSystemResource("command/factura_a.200");
}

From source file:com.netflix.genie.client.configs.JobConfigClientIntegrationTest.java

/**
 * Returns a temporary directory as the jobs resource.
 *
 * @return The job dir as a resource.//from www  . ja  va  2  s. c  om
 * @throws IOException If there is a problem.
 */
@Bean
public Resource jobsDir() throws IOException {
    this.jobsDir = Files.createTempDir();
    if (!this.jobsDir.exists() && !this.jobsDir.mkdirs()) {
        throw new IllegalArgumentException("Unable to create directories: " + this.jobsDir);
    }

    String jobsDirPath = this.jobsDir.getAbsolutePath();
    final String slash = "/";
    if (!jobsDirPath.endsWith(slash)) {
        jobsDirPath = jobsDirPath + slash;
    }

    return new FileSystemResource(jobsDirPath);
}

From source file:org.jasig.cas.WiringTests.java

@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations("file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
            "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override// ww w  . j  av a2 s .c  om
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}