Example usage for org.springframework.data.mongodb.gridfs GridFsResource GridFsResource

List of usage examples for org.springframework.data.mongodb.gridfs GridFsResource GridFsResource

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.gridfs GridFsResource GridFsResource.

Prototype

public GridFsResource(GridFSFile file) 

Source Link

Document

Creates a new GridFsResource from the given GridFSFile .

Usage

From source file:org.swarmcom.jsynapse.dao.ContentRepositoryImpl.java

@Override
public ContentResource download(String mediaId) {
    GridFSDBFile file = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(mediaId)));
    if (null == file) {
        return null;
    }/* w  w  w.j a v  a2s  .  c  om*/
    GridFsResource gridFsResource = new GridFsResource(file);
    return new ContentResource(gridFsResource.getContentType(), file.getLength(), gridFsResource);
}

From source file:com.sangupta.dryrun.mongo.DryRunGridFSTemplate.java

@Override
public GridFsResource getResource(String fileName) {
    DryRunGridFSDBFile file = this.files.get(fileName);
    if (file == null) {
        return null;
    }//from   ww  w .  ja v  a  2s  . c o m

    return new GridFsResource(file);
}

From source file:com.sangupta.dryrun.mongo.DryRunGridFSTemplate.java

@Override
public GridFsResource[] getResources(String filenamePattern) {
    if (AssertUtils.isEmpty(filenamePattern)) {
        return new GridFsResource[0];
    }//from  w w w  .java 2 s .  c  om

    DryRunAntPath path = new DryRunAntPath(filenamePattern);

    if (path.isPattern()) {
        Query query = Query.query(Criteria.where("filename").regex(path.toRegex()));
        List<GridFSDBFile> files = this.findObjects(query.getQueryObject(), -1);
        List<GridFsResource> resources = new ArrayList<GridFsResource>(files.size());

        for (GridFSDBFile file : files) {
            resources.add(new GridFsResource(file));
        }

        return resources.toArray(new GridFsResource[resources.size()]);
    }

    return new GridFsResource[] { getResource(filenamePattern) };
}