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:de.codecentric.boot.admin.controller.LogfileController.java

@RequestMapping("/logfile")
@ResponseBody/*from   ww w.  ja v a  2 s  .co m*/
public String getLogfile(HttpServletResponse response) {
    String path = env.getProperty("logging.file");
    if (path == null) {
        LOGGER.error("Logfile download failed for missing property 'logging.file'");
        return "Logfile download failed for missing property 'logging.file'";
    }
    Resource file = new FileSystemResource(path);
    if (!file.exists()) {
        LOGGER.error("Logfile download failed for missing file at path=" + path);
        return "Logfile download failed for missing file at path=" + path;
    }
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\"");
    try {
        FileCopyUtils.copy(file.getInputStream(), response.getOutputStream());
    } catch (IOException e) {
        LOGGER.error("Logfile download failed for path=" + path);
        return "Logfile download failed for path=" + path;
    }
    return null;
}

From source file:fr.acxio.tools.agia.tasks.FileOperationTaskletTest.java

@Test
public void testExecuteCopy() throws Exception {
    FileOperationTasklet aTasklet = new FileOperationTasklet();
    aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/input.csv"));
    aTasklet.setDestination(new FileSystemResource("target/input-copy.csv"));
    aTasklet.setOperation(Operation.COPY);
    aTasklet.afterPropertiesSet();/* w w w  .  j a  va 2 s .  c om*/
    StepContribution aStepContribution = mock(StepContribution.class);
    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null));
    verify(aStepContribution, times(1)).incrementReadCount();
    verify(aStepContribution, times(1)).incrementWriteCount(1);
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.restserver.reports.GenerateReportsRest.java

public Representation getHandler() {
    String result = null;//from w ww  . j a v  a  2s  .  c  o m
    try {
        getParameters();

        // Generate Reports at MCC level for dates
        if (topAccountId != null && dateStart != null && dateEnd != null) {

            getContext().getParameters().add("maxThreads", "512");

            Resource resource = new ClassPathResource(file);
            if (!resource.exists()) {
                resource = new FileSystemResource(file);
            }
            DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource);
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            ReportProcessor processor = getApplicationContext().getBean(ReportProcessor.class);

            // Launching a new Service(Thread) to make the request async.
            RunnableReport runnableReport = new RunnableReport(topAccountId, processor, properties, dateStart,
                    dateEnd);

            taskService.submit(runnableReport);

            result = "OK - Task created, this usually takes 10-15mins for 1000 accounts/month";
        } else {
            taskService.getContext();
        }
    } catch (Exception exception) {
        return handleException(exception);
    }
    addReadOnlyHeaders();
    return createJsonResult(result);
}

From source file:org.rivetlogic.utils.IntegrationUtils.java

public static BeanFactory getBeanFactory() throws IOException {
    if (beanFactory == null) {
        synchronized (beanFactoryLockObj) {
            if (beanFactory == null) {
                PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
                AbstractApplicationContext context = new ClassPathXmlApplicationContext(
                        "application-context.xml");

                Resource resource = new FileSystemResource("cma-cfg.properties");
                Properties properties = new Properties();
                properties.load(resource.getInputStream());

                configurer.setProperties(properties);

                context.addBeanFactoryPostProcessor(configurer);
                context.refresh();/*from  ww w .j  ava  2 s.  co  m*/

                beanFactory = context.getBeanFactory();
            }
        }
    }

    return beanFactory;
}

From source file:io.kahu.hawaii.config.HawaiiAppContextInitializer.java

private PropertySource<Object> getPropertySource() {
    List<Resource> resources = new ArrayList<Resource>();

    String configurationFiles = System.getProperty("properties.configuration");
    String[] files = StringUtils.split(configurationFiles, ",");
    for (String configFileName : files) {
        try {//from   w w  w.  j a v  a  2  s.  c o m
            File file = new File(configFileName);
            if (file.exists()) {
                resources.add(0, new FileSystemResource(file));
            } else {
                System.err.println("Configured properties file '" + configFileName + "' does not exist.");
            }
        } catch (Throwable t) {
            System.err.print("Error loading properties from file '" + configFileName + "': " + t.getMessage());
            resources = null;
        }
    }

    try {
        CompositePropertySource propertySource = new CompositePropertySource("properties");
        for (Resource resource : resources) {
            propertySource.addPropertySource(new ResourcePropertySource(resource));
        }
        return propertySource;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.apache.uima.ruta.resource.CSVTable.java

public CSVTable(String location) throws IOException {
    this(new FileSystemResource(location));
}

From source file:it.geosolutions.geoserver.jms.impl.utils.JMSPropertyPlaceholderConfigurer.java

@Override
public void afterPropertiesSet() throws Exception {
    File properties = new File(
            config.getConfiguration(EmbeddedBrokerConfiguration.EMBEDDED_BROKER_PROPERTIES_KEY).toString());
    if (!properties.isAbsolute() && !properties.isFile()) {
        // try to resolve as absolute
        properties = new File(JMSConfiguration.getConfigPathDir(), properties.getPath());
        if (!properties.isFile()) {
            // copy the defaults
            IOUtils.copy(defaults.getFile(), properties);
        }/*from   ww  w .  j a  va  2s  .co m*/
    }
    final Resource res = new FileSystemResource(properties);
    super.setLocation(res);

    // make sure the activemq.base is set to a valuable default 
    final Properties props = new Properties();
    props.setProperty("activemq.base", (String) config.getConfiguration("CLUSTER_CONFIG_DIR"));
    props.setProperty("instanceName", (String) config.getConfiguration("instanceName"));
    setProperties(props);
}

From source file:com.wavemaker.tools.project.LauncherHelper.java

/**
 * NOTE: this method is called from the Launcher. DO NOT CHANGE TO NEW RESOURCE API.
 * /*from w  w w. j  a v  a  2s .  co m*/
 * @param waveMakerHome
 * @throws IOException
 */
public static void doUpgrade(java.io.File waveMakerHomeFile) throws IOException {
    Resource waveMakerHome = new FileSystemResource(waveMakerHomeFile);
    VersionInfo vi = LocalStudioConfiguration.getCurrentVersionInfo();
    LocalStudioConfiguration.setRegisteredVersionInfo(vi);

    Resource oldWMHome = LocalStudioConfiguration.staticGetWaveMakerHome();
    if (0 != oldWMHome.getFile().compareTo(waveMakerHome.getFile())) {
        FileUtils.copyDirectory(oldWMHome.getFile(), waveMakerHome.getFile());
        LocalStudioConfiguration.setWaveMakerHome(waveMakerHome);
    }
}

From source file:net.sourceforge.vulcan.metrics.TransformTestCase.java

public Resource getResource(String filename) {
    return new FileSystemResource(TestUtils.resolveRelativeFile("source/main/config/xsl/" + filename));
}

From source file:org.globus.security.stores.ResourceSecurityWrapperStore.java

public void loadWrappers(String[] locations) throws ResourceStoreException {
    for (String location : locations) {
        File file = new File(location);
        FileSystemResource resource = new FileSystemResource(file);
        try {//from  ww w .j a v  a2s. c  om
            loadWrappers(resource.getURL().toExternalForm());
        } catch (IOException ioe) {
            throw new ResourceStoreException(ioe);
        }
    }
}