Example usage for org.springframework.core.io Resource getFilename

List of usage examples for org.springframework.core.io Resource getFilename

Introduction

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

Prototype

@Nullable
String getFilename();

Source Link

Document

Determine a filename for this resource, i.e.

Usage

From source file:com.logsniffer.util.grok.GrokAppConfig.java

@Bean
public GroksRegistry groksRegistry() throws IOException, GrokException {
    GroksRegistry registry = new GroksRegistry();
    PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver();
    Resource[] classPathPatterns = pathMatcher.getResources("classpath*:/grok-patterns/*");
    Arrays.sort(classPathPatterns, new Comparator<Resource>() {
        @Override//  ww w.j a va  2s.c o m
        public int compare(final Resource o1, final Resource o2) {
            return o1.getFilename().compareTo(o2.getFilename());
        }
    });
    LinkedHashMap<String, String[]> grokBlocks = new LinkedHashMap<String, String[]>();
    for (Resource r : classPathPatterns) {
        grokBlocks.put(r.getFilename(), IOUtils.readLines(r.getInputStream()).toArray(new String[0]));
    }
    registry.registerPatternBlocks(grokBlocks);
    return registry;
}

From source file:org.wte4j.examples.showcase.server.hsql.ShowCaseDbInitializer.java

void createDateBaseFiles(Path dataBaseLocation, boolean overide) {
    Path hsqlScript = dataBaseLocation.resolve("wte4j-showcase.script");
    if (overide || !Files.exists(hsqlScript)) {
        try {//  w  ww  .  jav a  2 s.  c  om
            if (!Files.exists(dataBaseLocation)) {
                Files.createDirectories(dataBaseLocation);
            }
            Resource[] resources = resourceLoader.getResources("classpath:/db/*");
            for (Resource resource : resources) {
                Path filePath = dataBaseLocation.resolve(resource.getFilename());
                File source = resource.getFile();
                Files.copy(source.toPath(), filePath, StandardCopyOption.REPLACE_EXISTING);
            }
        } catch (IOException e) {
            throw new IllegalArgumentException("can not copy database files", e);
        }
    }
}

From source file:guru.nidi.languager.PropertiesFinder.java

public SortedMap<String, Message> findProperties() throws IOException {
    SortedMap<String, Message> messages = new TreeMap<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (String propertyLocation : propertyLocations) {
        Resource[] resources = resolver.getResources(propertyLocation + "*" + PROPERTIES);
        for (Resource resource : resources) {
            String lang = resource.getFilename();
            lang = lang.substring(Math.max(0, lang.length() - 20), lang.length() - PROPERTIES.length());
            int pos = lang.indexOf('_');
            if (pos < 0) {
                lang = "";
            } else {
                lang = lang.substring(pos + 1);
            }/*from  w w w. jav  a  2  s  .  c  o  m*/
            Properties props = new Properties();
            props.load(resource.getInputStream());
            for (String name : props.stringPropertyNames()) {
                Message message = messages.get(name);
                if (message == null) {
                    message = new Message(name, FOUND, null);
                    messages.put(name, message);
                }
                message.addValue(lang, props.getProperty(name));
            }
        }
    }
    return messages;
}

From source file:org.carewebframework.ui.command.CommandShortcuts.java

public CommandShortcuts(Resource mappings) {
    put("help", "#f1");
    String filename = " '" + mappings.getFilename() + "'.";
    InputStream is;//w w  w  .jav  a 2  s  .c  om

    try {
        if (!mappings.exists()) {
            log.info("No shortcut mappings found at" + filename);
            return;
        }

        is = mappings.getInputStream();

        if (is != null) {
            load(is);
            is.close();
            log.info("Shortcut mappings loaded from" + filename);
        }
    } catch (IOException e) {
        log.error("Error loading shortcut mappings from" + filename, e);
    }
}

From source file:com.siberhus.tdfl.excel.DefaultExcelWorkbookFactory.java

private String getFileExtension(Resource resource) {
    String ext = FilenameUtils.getExtension(resource.getFilename());
    ext = ext.toUpperCase();//  w  ww. jav a 2s .  co  m
    return ext;
}

From source file:org.apache.crunch.dotfile.DotfileService.java

public String getDotfileContent(String fileName) throws IOException {

    for (Resource res : getResources()) {
        if (res.getFilename().contains(fileName)) {
            return IOUtils.toString(res.getInputStream());
            // return Files.toString(res.getFile(),
            // Charset.forName("UTF-8"));
        }// w  ww. ja  va2  s. com
    }

    return "";
}

From source file:fi.helsinki.opintoni.service.BackgroundImageService.java

@PostConstruct
public void initFilePaths() throws IOException {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

    Resource[] resources = resolver.getResources(BACKGROUND_IMAGES_FOLDER_EXPRESSION);
    for (Resource resource : resources) {
        String filename = resource.getFilename();
        builder.put(filename, getFilePath(filename));
    }//www .  j  a  v a2 s.c  o  m
    fileNamesToPath = builder.build();
}

From source file:de.tudarmstadt.ukp.csniper.webapp.analysis.ExamplesRepository.java

@Required
public void setExamples(Map<String, Resource[]> aExamples) {
    examples = new HashMap<String, Map<String, Resource>>();
    for (String tool : aExamples.keySet()) {
        Map<String, Resource> toolExamples = examples.get(tool);
        if (toolExamples == null) {
            toolExamples = new HashMap<String, Resource>();
            examples.put(tool, toolExamples);
        }//  w  w w  .  ja va2 s  .  c  o m

        for (Resource res : aExamples.get(tool)) {
            toolExamples.put(res.getFilename(), res);
        }
    }
}

From source file:org.jasig.ssp.util.importer.job.csv.RawItemCsvWriter.java

@Override
public void setResource(Resource resource) {
    String fileName = resource.getFilename();
    try {//from w  ww .  ja  v a 2  s.c  om
        File file = new File(writeDirectory.getFile(), fileName);
        file.createNewFile();
        if (file.exists())
            logger.info("File created for writing file name: " + file);
        else
            logger.error("File not created for writing file name: " + file);
        super.setResource(new FileSystemResource(file));
    } catch (IOException e) {
        logger.error("Error attempting to create file " + fileName + "for writing raw output.", e);
        e.printStackTrace();
    }

}

From source file:org.vbossica.springbox.config.PropertyPlaceholderDebuggingConfigurer.java

public void setLocations(Resource[] locations) {
    super.setLocations(locations);
    if (log.isDebugEnabled()) {
        log.debug("Setting locations");
        for (Resource location : locations) {
            log.debug("resource: {}", location.getFilename());
        }//  w  ww. j  a v a 2 s  .  c om
    }
}