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:org.jtheque.core.impl.CoreImpl.java

@Override
public void launchApplication(Application application) {
    if (this.application != null) {
        throw new IllegalStateException("The application is already launched");
    }/*from  ww  w.  ja  v  a2 s.  c o  m*/

    this.application = application;

    Collection<String> languagesLong = CollectionUtils.newList(3);

    for (String supportedLanguage : application.getSupportedLanguages()) {
        if ("fr".equals(supportedLanguage)) {
            languagesLong.add("Franais");
        } else if ("en".equals(supportedLanguage)) {
            languagesLong.add("English");
        } else if ("de".equals(supportedLanguage)) {
            languagesLong.add("Deutsch");
        }
    }

    languages = CollectionUtils.protect(languagesLong);

    fireApplicationLaunched(application);

    imageService.registerResource(WINDOW_ICON, new FileSystemResource(new File(application.getWindowIcon())));
}

From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpoint.java

private boolean isAvailable() {
    if (!enabled) {
        return false;
    }/*from w w w.  j a va  2s. c  om*/

    if (logfile == null) {
        LOGGER.error("Logfile download failed for missing property 'logging.file'");
        return false;
    }

    Resource file = new FileSystemResource(logfile);
    if (!file.exists()) {
        LOGGER.error("Logfile download failed for missing file at path={}", logfile);
        return false;
    }

    return true;
}

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

@Test
public void testExecuteCannotReplace() throws Exception {
    exception.expect(FileCopyException.class);
    FileCopyTasklet aTasklet = new FileCopyTasklet();
    aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/input.csv"));
    aTasklet.setDestination(new FileSystemResource("target/input-copy.csv"));
    aTasklet.execute(null, null);/*from   ww  w  .  j a v  a 2  s.  com*/
    aTasklet.setForceReplace(false);
    aTasklet.execute(null, null);
}

From source file:com.glaf.activiti.util.ProcessUtils.java

public static void saveProcessImageToFileSystem(ProcessDefinition processDefinition) {
    logger.debug("@deploymentId:" + processDefinition.getDeploymentId());
    String resourceName = processDefinition.getDiagramResourceName();
    if (resourceName != null) {
        ActivitiDeployQueryService activitiDeployQueryService = ContextFactory
                .getBean("activitiDeployQueryService");
        InputStream inputStream = activitiDeployQueryService
                .getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
        logger.debug("@resourceName:" + resourceName);
        String filename = ApplicationContext.getAppPath() + "/deploy/bpmn/" + getImagePath(processDefinition);
        FileSystemResource fs = new FileSystemResource(filename);
        if (!fs.exists()) {
            try {
                logger.debug("save:" + filename);
                FileUtils.save(filename, inputStream);
            } catch (Exception ex) {
                ex.printStackTrace();/*from  w w w . j  a va 2  s.com*/
            }
        }
    }
}

From source file:de.ingrid.iplug.dsc.index.ScriptedWmsDocumentProducerTest.java

public void testMapper() throws Exception {

    PlugDescription pd = new PlugDescription();
    pd.put("WebmapXmlConfigFile", "src/test/resources/ingrid_webmap_client_config.xml");

    PlugDescriptionConfiguredWmsRecordSetProducer p = new PlugDescriptionConfiguredWmsRecordSetProducer();
    p.setStatusProvider(statusProvider);
    p.setIdTag("//capabilitiesUrl");
    p.configure(pd);//from  w w w.  j  av  a 2s. c  om

    ScriptedWmsDocumentMapper mapperLucene = new ScriptedWmsDocumentMapper();
    mapperLucene.setMappingScript(new FileSystemResource("src/main/resources/mapping/wms_to_lucene.js"));
    mapperLucene.setCompile(false);
    ScriptedIdfDocumentMapper mapperIdf = new ScriptedIdfDocumentMapper();
    mapperIdf.setMappingScript(new FileSystemResource("src/main/resources/mapping/wms_to_idf.js"));
    mapperIdf.setCompile(false);

    while (p.hasNext()) {
        ElasticDocument doc = new ElasticDocument();
        SourceRecord record = p.next();
        mapperLucene.map(record, doc);
        mapperIdf.map(record, doc);
    }

}

From source file:com.ethercamp.harmony.web.controller.WebSocketController.java

/**
 * @return logs file to be able to download from browser
 *//*from  w  w w.  ja va  2 s  .  co  m*/
@RequestMapping(value = "/logs/{logName:.+}", method = RequestMethod.GET)
@ResponseBody
public FileSystemResource logFile(@PathVariable("logName") String logName, HttpServletResponse response) {
    final String fileName = logName;

    if (!fileName.endsWith(".log") && !fileName.endsWith(".zip")) {
        throw new RuntimeException("Forbidden file requested: " + fileName);
    }

    // force file downloading, otherwise line breaks will gone in web view
    response.setContentType("text/plain");
    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

    return new FileSystemResource(new File(getLogsDir() + "/" + fileName));
}

From source file:net.sourceforge.vulcan.spring.jdbc.JdbcSchemaMigratorTest.java

@SuppressWarnings("unchecked")
static Resource[] getMigrationScripts() {
    File dir = TestUtils.resolveRelativeFile("source/main/sql/hsql");
    List<Resource> scripts = new ArrayList<Resource>();
    for (File file : (Collection<File>) FileUtils.listFiles(dir, new WildcardFilter("S*.sql"),
            FalseFileFilter.INSTANCE)) {
        scripts.add(new FileSystemResource(file));
    }/*from   www. j  a  va  2 s .  c o  m*/
    return scripts.toArray(new Resource[scripts.size()]);
}

From source file:io.gravitee.management.service.impl.EmailServiceImpl.java

private String addResourcesInMessage(final MimeMessageHelper mailMessage, final String htmlText)
        throws Exception {
    final Document document = Jsoup.parse(htmlText);

    final List<String> resources = new ArrayList<>();

    final Elements imageElements = document.getElementsByTag("img");
    resources.addAll(//from w  w w  .ja v a  2s .  com
            imageElements.stream().filter(imageElement -> imageElement.hasAttr("src")).map(imageElement -> {
                final String src = imageElement.attr("src");
                imageElement.attr("src", "cid:" + src);
                return src;
            }).collect(Collectors.toList()));

    final String html = document.html();
    mailMessage.setText(html, true);

    for (final String res : resources) {
        final FileSystemResource templateResource = new FileSystemResource(new File(templatesPath, res));
        mailMessage.addInline(res, templateResource,
                MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(res));
    }

    return html;
}

From source file:com.flipkart.phantom.runtime.impl.spring.admin.SPConfigServiceImpl.java

/**
 * Interface method implementation.//from www .ja v  a 2 s  .com
 * @see com.flipkart.phantom.runtime.spi.spring.admin.SPConfigService#getHandlerConfig(java.lang.String)
 */
public Resource getHandlerConfig(String handlerName) {
    for (URI configFile : this.configURItoHandlerName.keySet()) {
        for (AbstractHandler handler : this.configURItoHandlerName.get(configFile)) {
            if (handler.getName().equals(handlerName)) {
                return new FileSystemResource(new File(configFile));
            }
        }
    }
    return null;
}

From source file:edu.usf.cutr.fdot7.main.Test.java

/**
 * Constructor of the main program. We use this to avoid static variable
 *//*from ww w  . jav a 2  s  .  c  o m*/
public Test() {
    //initialize logger
    org.apache.log4j.BasicConfigurator.configure();

    _log.info("Please log-in to upload data.");
    SessionForm sf = new SessionForm();

    sf.showDialog();
    try {
        mutex.acquire();
    } catch (InterruptedException ie) {
        _log.error(ie.getMessage());
    }

    sf.dispose();

    if (mainUsername == null || mainPassword == null) {
        _log.error("You must log-in sucessfully before continuing.");
        _log.info("Exit Program!");
        System.exit(0);
    }

    boolean isInputError = false;
    HashSet<String> errorFeeds = new HashSet<String>();
    ArrayList<AgencyInfo> ais = new ArrayList<AgencyInfo>();
    ArrayList<ArrayList<GenericGtfsData>> gtfsAgenciesData = new ArrayList<ArrayList<GenericGtfsData>>();
    _log.info("Reading 'AgencyInfo.csv'");
    ais.addAll(readAgencyInfo(
            System.getProperty("user.dir") + System.getProperty("file.separator") + "AgencyInfo.csv"));
    _log.info(ais.size() + " GTFS feeds to be processed.");

    factory = new XmlBeanFactory(new FileSystemResource(
            System.getProperty("user.dir") + System.getProperty("file.separator") + "data-source.xml"));

    for (int i = 0; i < ais.size(); i++) {
        AgencyInfo ai = ais.get(i);
        try {
            ArrayList<GenericGtfsData> gtfsAgencyData = new ArrayList<GenericGtfsData>();
            gtfsAgencyData.addAll(getDataFromAgency(ai));
            gtfsAgenciesData.add(gtfsAgencyData);
        } catch (IOException e) {
            errorFeeds.add(ai.getName());
            _log.error("Error reading input from " + ai.getName());
            _log.error(e.getMessage());
            isInputError = true;
            continue;
        }
    }

    if (!isInputError) {
        _log.info("Complete checking and reading " + ais.size() + " GTFS feeds.");
        _log.info("Start to upload data.");
        uploadAgenciesData(gtfsAgenciesData, mainUsername, mainPassword);
    } else {
        _log.info("Please check agency dataset from " + errorFeeds.toString()
                + " again! No data will be uploaded.");
    }
}