Example usage for com.mongodb.client.gridfs.model GridFSFile getMD5

List of usage examples for com.mongodb.client.gridfs.model GridFSFile getMD5

Introduction

In this page you can find the example usage for com.mongodb.client.gridfs.model GridFSFile getMD5.

Prototype

@Deprecated
@Nullable
public String getMD5() 

Source Link

Document

The hash of the contents of the stored file

Usage

From source file:com.imaginea.mongodb.services.impl.GridFSServiceImpl.java

License:Apache License

private JSONObject executeFind(GridFSBucket gridFS, String query, String sortBy, String limit, String skip)
        throws JSONException {
    Document queryObj = Document.parse(query);
    Document sortObj = Document.parse(sortBy);
    int filesLimit = Integer.parseInt(limit);
    int filesSkip = Integer.parseInt(skip);
    // Partial Keys cant be fetched for a file

    MongoCursor<GridFSFile> it = gridFS.find(queryObj).sort(sortObj).skip(filesSkip).limit(filesLimit)
            .iterator();/*from  w ww. j  ava  2 s . c  om*/

    JSONArray fileList = new JSONArray();
    while (it.hasNext()) {
        GridFSFile fsFile = it.next();

        JSONObject file = new JSONObject();

        file.put("_id", fsFile.getId().asObjectId().getValue());
        file.put("fileName", fsFile.getFilename());
        file.put("length", fsFile.getLength());
        file.put("chunkSize", fsFile.getChunkSize());
        file.put("uploadDate", fsFile.getUploadDate());
        file.put("md5", fsFile.getMD5());
        if (fsFile.getMetadata() != null) {
            file.put("metadata", fsFile.getMetadata());
        }

        fileList.put(file);

    }
    JSONObject result = new JSONObject();
    long count = fileList.length();
    result.put("documents", fileList);
    result.put("editable", true);
    result.put("count", count);
    return result;
}