Search in sources :

Example 6 with GridFSDBFile

use of com.mongodb.gridfs.GridFSDBFile in project mongo-hadoop by mongodb.

the class GridFSInputFormat method getSplits.

@Override
public List<InputSplit> getSplits(final JobContext context) throws IOException, InterruptedException {
    Configuration conf = context.getConfiguration();
    DBCollection inputCollection = MongoConfigUtil.getInputCollection(conf);
    MongoClientURI inputURI = MongoConfigUtil.getInputURI(conf);
    GridFS gridFS = new GridFS(inputCollection.getDB(), inputCollection.getName());
    DBObject query = MongoConfigUtil.getQuery(conf);
    List<InputSplit> splits = new LinkedList<InputSplit>();
    for (GridFSDBFile file : gridFS.find(query)) {
        // One split per file.
        if (MongoConfigUtil.isGridFSWholeFileSplit(conf)) {
            splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength()));
        } else // One split per file chunk.
        {
            for (int chunk = 0; chunk < file.numChunks(); ++chunk) {
                splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength(), chunk));
            }
        }
    }
    LOG.debug("Found GridFS splits: " + splits);
    return splits;
}
Also used : DBCollection(com.mongodb.DBCollection) GridFSSplit(com.mongodb.hadoop.input.GridFSSplit) Configuration(org.apache.hadoop.conf.Configuration) ObjectId(org.bson.types.ObjectId) GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) MongoClientURI(com.mongodb.MongoClientURI) GridFS(com.mongodb.gridfs.GridFS) DBObject(com.mongodb.DBObject) InputSplit(org.apache.hadoop.mapreduce.InputSplit) LinkedList(java.util.LinkedList)

Example 7 with GridFSDBFile

use of com.mongodb.gridfs.GridFSDBFile in project play-cookbook by spinscale.

the class Application method showImage.

public static void showImage(String id) {
    GridFSDBFile file = GridFsHelper.getFile(id);
    notFoundIfNull(file);
    renderBinary(file.getInputStream(), file.getFilename(), file.getLength(), file.getContentType(), true);
}
Also used : GridFSDBFile(com.mongodb.gridfs.GridFSDBFile)

Example 8 with GridFSDBFile

use of com.mongodb.gridfs.GridFSDBFile in project mongomvcc by igd-geo.

the class DefaultConvertStrategy method convert.

@Override
public Object convert(long oid) throws IOException {
    GridFSDBFile file = _gridFS.findOne(new BasicDBObject(MongoDBVLargeCollection.OID, oid));
    if (file == null) {
        return null;
    }
    int type = (Integer) file.get(BINARY_TYPE);
    Object r;
    if (type == BYTEARRAY) {
        r = toByteArray(file);
    } else if (type == INPUTSTREAM) {
        r = file.getInputStream();
    } else if (type == BYTEBUFFER) {
        r = ByteBuffer.wrap(toByteArray(file));
    } else if (type == FLOATARRAY) {
        r = toFloatArray(file);
    } else if (type == FLOATBUFFER) {
        r = FloatBuffer.wrap(toFloatArray(file));
    } else {
        // no information. simply forward the input stream
        r = file.getInputStream();
    }
    return r;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) BasicDBObject(com.mongodb.BasicDBObject)

Example 9 with GridFSDBFile

use of com.mongodb.gridfs.GridFSDBFile in project leopard by tanhaichao.

the class DfsGridImpl method read.

@Override
public byte[] read(String filename) throws IOException {
    GridFSDBFile file = getGridFS().findOne(filename);
    if (file == null) {
        throw new FileNotFoundException(filename);
    }
    InputStream input = file.getInputStream();
    try {
        return IOUtils.toByteArray(input);
    } finally {
        input.close();
    }
}
Also used : GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException)

Example 10 with GridFSDBFile

use of com.mongodb.gridfs.GridFSDBFile in project pmph by BCSquad.

the class CmsManualServiceImpl method addCmsManual.

@Override
public CmsManual addCmsManual(CmsManual cmsManual) throws CheckedServiceException {
    if (ObjectUtil.isNull(cmsManual)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "CmsManual对象参数为空");
    }
    if (ObjectUtil.isNull(cmsManual.getAttachment())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "附件id参数为空");
    }
    /*if (StringUtil.isEmpty(cmsManual.getNote())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.CMS,
                                              CheckedExceptionResult.NULL_PARAM, "备注参数为空");
        }*/
    if (ObjectUtil.isNull(cmsManual.getUserId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "上传者id参数为空");
    }
    if (cmsManual.getManualName().length() > 50) {
        throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "操作手册名称不能超过50个字!");
    }
    String fileName = "操作手册.doc";
    GridFSDBFile file = fileService.get(cmsManual.getAttachment());
    if (ObjectUtil.notNull(file)) {
        fileName = file.getFilename();
    }
    cmsManual.setManualName(fileName);
    cmsManualDao.addCmsManual(cmsManual);
    return cmsManual;
}
Also used : GridFSDBFile(com.mongodb.gridfs.GridFSDBFile) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Aggregations

GridFSDBFile (com.mongodb.gridfs.GridFSDBFile)20 BasicDBObject (com.mongodb.BasicDBObject)8 InputStream (java.io.InputStream)8 DBObject (com.mongodb.DBObject)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 Test (org.junit.Test)4 GridFS (com.mongodb.gridfs.GridFS)3 GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)3 FileInputStream (java.io.FileInputStream)3 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LogDetail (com.bc.pmpheep.annotation.LogDetail)2 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)2 Content (com.bc.pmpheep.general.po.Content)2 DBCollection (com.mongodb.DBCollection)2 DBCursor (com.mongodb.DBCursor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2