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:fr.acxio.tools.agia.io.ExpressionResourceFactoryTest.java

@Test
public void testExpression() throws Exception {
    ExpressionResourceFactory aFactory = new ExpressionResourceFactory();
    StandardEvaluationContextFactory aEvaluationContextFactory = new StandardEvaluationContextFactory();
    Map<String, Object> aVariables = new HashMap<String, Object>();
    aVariables.put("afile", "input.csv");
    aEvaluationContextFactory.setCommonObjects(aVariables);
    aFactory.setEvaluationContextFactory(aEvaluationContextFactory);
    aFactory.setExpression("file:src/test/resources/testFiles/@{#afile}");
    Resource aResource = aFactory.getResource();
    assertNotNull(aResource);// www.j a  va2  s  .com
    assertEquals("input.csv", aResource.getFilename());
}

From source file:org.mongeez.reader.FormattedJavascriptChangeSetReader.java

@Override
public boolean supports(Resource file) {
    return file.getFilename().endsWith(".js");
}

From source file:com.greglturnquist.springagram.fileservice.s3.FileService.java

public void deleteAll() throws IOException {

    for (Resource resource : this.findAll()) {
        this.deleteOne(resource.getFilename());
    }//from  w  ww .  j  a va 2s . c  om
}

From source file:de.taimos.dvalin.mongo.MongoDBInit.java

/**
 * init database with demo data// www . ja  v a  2  s  . co m
 */
@PostConstruct
public void initDatabase() {
    MongoDBInit.LOGGER.info("initializing MongoDB");
    String dbName = System.getProperty("mongodb.name");
    if (dbName == null) {
        throw new RuntimeException("Missing database name; Set system property 'mongodb.name'");
    }
    MongoDatabase db = this.mongo.getDatabase(dbName);

    try {
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources("classpath*:mongodb/*.ndjson");
        MongoDBInit.LOGGER.info("Scanning for collection data");
        for (Resource res : resources) {
            String filename = res.getFilename();
            String collection = filename.substring(0, filename.length() - 7);
            MongoDBInit.LOGGER.info("Found collection file: " + collection);
            MongoCollection<DBObject> dbCollection = db.getCollection(collection, DBObject.class);
            try (Scanner scan = new Scanner(res.getInputStream(), "UTF-8")) {
                int lines = 0;
                while (scan.hasNextLine()) {
                    String json = scan.nextLine();
                    Object parse = JSON.parse(json);
                    if (parse instanceof DBObject) {
                        DBObject dbObject = (DBObject) parse;
                        dbCollection.insertOne(dbObject);
                    } else {
                        MongoDBInit.LOGGER.error("Invalid object found: " + parse);
                        throw new RuntimeException("Invalid object");
                    }
                    lines++;
                }
                MongoDBInit.LOGGER.info("Imported " + lines + " objects into collection " + collection);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Error importing objects", e);
    }
}

From source file:edu.jhuapl.openessence.config.AppInitializer.java

private List<PropertySource<?>> getPropertySources(Collection<Resource> resources) {
    List<PropertySource<?>> propertySources = new ArrayList<PropertySource<?>>();

    for (Resource r : resources) {
        String filename = r.getFilename();
        if (filename == null) {
            throw new IllegalArgumentException("Cannot have resource with no file");
        }/*w w w.  ja  v a2 s.co  m*/

        String name = FilenameUtils.getBaseName(r.getFilename());

        Properties source;
        try {
            source = PropertiesLoaderUtils.loadProperties(r);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        propertySources.add(new PropertiesPropertySource(name, source));

        try {
            log.info("Adding file {} as property source named '{}'", r.getFile(), name);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    return propertySources;
}

From source file:de.kaiserpfalzEdv.commons.jee.spring.CommonsConfigurationConfigurer.java

private String getFileNameForResource(Resource location) {
    String filename = null;/*w w w.  j  a  v a 2 s  .c o m*/
    try {
        filename = location.getFilename();
    } catch (IllegalStateException ex) {
        // resource is not file-based.
    }
    return filename;
}

From source file:org.dineth.shooter.app.view.ImageController.java

@RequestMapping(value = "/get/{name}.{ext}")
public ResponseEntity<byte[]> getImage(@PathVariable("name") String name, @PathVariable("ext") String ext) {

    Resource resource = context.getResource("file:/home/dewmal/files/" + name + "." + ext);
    System.out.println(resource.getFilename());
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_PNG);
    try {//from ww  w.  j  a v  a  2  s  . c o  m
        return new ResponseEntity<>(IOUtils.toByteArray(resource.getInputStream()), headers,
                HttpStatus.CREATED);
    } catch (IOException ex) {
        Logger.getLogger(ImageController.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:de.codecentric.batch.web.JobMonitoringController.java

@RequestMapping(value = "/jobs", method = RequestMethod.GET)
public Set<String> findRegisteredJobs() throws IOException {
    Set<String> registeredJobs = new HashSet<>(jobOperator.getJobNames());
    // Add JSR-352 jobs
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    Resource[] xmlConfigurations = resourcePatternResolver
            .getResources("classpath*:/META-INF/batch-jobs/*.xml");
    for (Resource resource : xmlConfigurations) {
        registeredJobs.add(resource.getFilename().substring(0, resource.getFilename().length() - 4));
    }// ww  w  .  j a v a  2s  .com
    return registeredJobs;
}

From source file:org.eclipse.swordfish.core.test.util.base.TargetPlatformOsgiTestCase.java

private int getIndex(Resource[] bundles, String bundleNamePart) {
    int i = -1;//from ww  w.j  ava  2 s.c  om
    for (Resource resource : bundles) {
        i++;
        if (resource.getFilename().contains(bundleNamePart)) {
            return i;
        }
    }
    return i;
}

From source file:io.servicecomb.core.definition.loader.SchemaLoader.java

/**
 * resource??schemaId.yaml/*  w w w  . java2  s  . c  om*/
 */
public SchemaMeta registerSchema(String microserviceName, Resource resource) {
    try {
        String schemaId = FilenameUtils.getBaseName(resource.getFilename());

        String swaggerContent = IOUtils.toString(resource.getURL());
        SchemaMeta schemaMeta = registerSchema(microserviceName, schemaId, swaggerContent);

        return schemaMeta;
    } catch (Throwable e) {
        throw new Error(e);
    }
}