Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSInputFile


        try {
            // createDatabase();
            byte[] content = copyToBytesFromClasspath(TEST_ATTACHMENT_HTML);
            logger.debug("Content in bytes: {}", content.length);
            GridFS gridFS = new GridFS(mongoDB);
            GridFSInputFile in = gridFS.createFile(content);
            in.setFilename("test-attachment.html");
            in.setContentType("text/html");
            BasicDBObject metadata = new BasicDBObject();
            metadata.put("attribut1", "value1");
            metadata.put("attribut2", "value2");
            in.put("metadata", metadata);
            in.save();
            in.validate();

            String id = in.getId().toString();
            logger.debug("GridFS in: {}", in);
            logger.debug("Document created with id: {}", id);

            GridFSDBFile out = gridFS.findOne(in.getFilename());
            logger.debug("GridFS from findOne: {}", out);
            out = gridFS.findOne(new ObjectId(id));
            logger.debug("GridFS from findOne: {}", out);
            Assert.assertEquals(out.getId(), in.getId());

            Thread.sleep(wait);
            refreshIndex();

            CountResponse countResponse = getNode().client().count(countRequest(getIndex())).actionGet();
View Full Code Here


            throw ExceptionFactory.convert(e);
        }
    }

    public String writeBlob(InputStream in) throws Exception {
        GridFSInputFile f = fs.createFile(in, true);
        //f.save(0x20000);   // save in 128k chunks
        f.save();

        return f.getId().toString();
    }
View Full Code Here

    // a second database query.
    if (getAttachment(waveletName, id) != null) {
      return false;
    } else {
      String completeAttachmentId = computeCompleteAttachmentId(waveletName, id);
      GridFSInputFile file = getAttachmentGrid().createFile(data, completeAttachmentId);

      try {
        file.save();
      } catch (MongoException e) {
        // Unfortunately, file.save() wraps any IOException thrown in a
        // 'MongoException'. Since the interface explicitly throws IOExceptions,
        // we unwrap any IOExceptions thrown.
        Throwable innerException = e.getCause();
View Full Code Here

    Assert.notNull(content);
    Assert.hasText(filename);
    Assert.notNull(metadata);

    GridFSInputFile file = getGridFs().createFile(content);
    file.setFilename(filename);
    file.setMetaData(metadata);
    file.save();

    return file;
  }
View Full Code Here

TOP

Related Classes of com.mongodb.gridfs.GridFSInputFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.