Example usage for com.mongodb.gridfs GridFS GridFS

List of usage examples for com.mongodb.gridfs GridFS GridFS

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFS GridFS.

Prototype

public GridFS(final DB db) 

Source Link

Document

Creates a GridFS instance for the default bucket "fs" in the given database.

Usage

From source file:org.craftercms.social.services.impl.SupportDataAccessImpl.java

License:Open Source License

@Override
public Attachment getAttachment(ObjectId attachmentId) {
    try {//from   w w w  . j a va 2s  . co m
        GridFS gFS = new GridFS(mongoTemplate.getDb());
        GridFSDBFile file = gFS.find(attachmentId);
        if (file != null) {
            Attachment attach = null;
            attach = new Attachment(file.getContentType(), file.getLength(), file.getFilename());
            return attach;
        } else {
            log.error("Attachment with id {} does not exist", attachmentId);
            throw new DataRetrievalFailureException(
                    "Attachment with id" + attachmentId.toString() + " does not exist");
        }
    } catch (Exception e) {
        log.error("Could not get attachment.", e);
        return null;
    }
}

From source file:org.craftercms.studio.impl.repository.mongodb.services.impl.GridFSServiceImpl.java

License:Open Source License

public void setJongoCollectionFactory(JongoCollectionFactory jongoCollectionFactory) {
    this.gridFs = new GridFS(jongoCollectionFactory.getDatabase());
}

From source file:org.i3xx.step.mongo.core.impl.FileStoreImpl.java

License:Apache License

public FileStoreImpl(DB dbs) {
    fs = new GridFS(dbs);
}

From source file:org.mongodb.demos.binary.GridFSDemo.java

License:Apache License

/**
 * Save the file into MongoDB using GridFS
 * @param fileName/*  www. j a v a 2  s . c  o  m*/
 * @return
 * @throws IOException
 */
public Object saveLargeFile(String fileName) throws IOException {
    System.out.println("\n== ==  WRITE IN GRIFS / MONGODB  == == == ");
    GridFS fs = new GridFS(db);
    // large file
    byte[] fileAsBytes = extractBytes(fileName);
    GridFSInputFile in = fs.createFile(fileAsBytes);
    in.save();
    System.out.println("File ID : " + in.getId());
    System.out.println("\n== ==  == == == ");
    return in.getId();
}

From source file:org.mongodb.demos.binary.GridFSDemo.java

License:Apache License

/**
 * Read the file stored in GridFS and  save it into the fileToSave location
 * @param id//from ww w  .j a v a  2  s  . com
 * @param fileToSave
 * @throws Exception
 */
public void readLargeFile(Object id, String fileToSave) throws Exception {
    GridFS fs = new GridFS(db);
    GridFSDBFile out = fs.findOne(new BasicDBObject("_id", id));
    out.writeTo(fileToSave);

    System.out.println("File saved into " + fileToSave);
}

From source file:org.mule.module.mongo.api.MongoClientImpl.java

License:Open Source License

protected GridFS getGridFs() {
    return new GridFS(db);
}

From source file:org.openspotlight.storage.mongodb.MongoStorageSessionImpl.java

License:Open Source License

private GridFS getCachedGridFSForPartition(final String partition) {
    GridFS fs = gridFSMap.get(partition);
    if (fs == null) {
        final DB db = getCachedDbForPartition(partition);
        fs = new GridFS(db);
        gridFSMap.put(partition, fs);/* w w w .  j a  va  2  s. c  o  m*/
    }
    return fs;
}

From source file:org.rhq.enterprise.server.plugins.drift.mongodb.dao.FileDAO.java

License:Open Source License

public FileDAO(DB db) {
    this.db = db;
    gridFS = new GridFS(this.db);
}

From source file:org.sipfoundry.commons.userdb.profile.UserProfileServiceImpl.java

License:Open Source License

@Override
public InputStream getAvatar(String userName) {
    GridFS avatarFS = new GridFS(m_template.getDb());
    GridFSDBFile imageForOutput = avatarFS.findOne(String.format(AVATAR_NAME, userName));
    if (imageForOutput != null) {
        return imageForOutput.getInputStream();
    }//from  ww w .ja  v  a2s. com
    // try default avatar
    imageForOutput = avatarFS.findOne(String.format(AVATAR_NAME, "default"));
    if (imageForOutput != null) {
        return imageForOutput.getInputStream();
    }
    return null;
}

From source file:org.sipfoundry.commons.userdb.profile.UserProfileServiceImpl.java

License:Open Source License

@Override
public void deleteAvatar(String userName) {
    GridFS avatarFS = new GridFS(m_template.getDb());
    avatarFS.remove(String.format(AVATAR_NAME, userName));
}