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

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

Introduction

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

Prototype

public int getChunkSize() 

Source Link

Document

The size, in bytes, of each data chunk of this 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  w  w. ja  v  a  2 s.  co  m*/

    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;
}