Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSInputFile$MyOutputStream


        if (gridFile != null) {
            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }
View Full Code Here


    public void set(File file, String type) throws IOException {
        if (!file.exists()) {
            Logger.warn("File not exists: %s", file);
            return;
        }
        GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(file);
        inputFile.setContentType(type);
        inputFile.save();
        this.file = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString()));
    }
View Full Code Here

   

    @Override
    public void set(InputStream is, String type) {
        String rand = RandomStringUtils.randomAlphanumeric(10);
        GridFSInputFile inputFile = MorphiaPlugin.gridFs().createFile(is);
        inputFile.setContentType(type);
        inputFile.put("name", rand);
        inputFile.save();
        file = MorphiaPlugin.gridFs().findOne(new ObjectId(inputFile.getId().toString()));
    }
View Full Code Here

    return _convertedFiles;
  }
 
  @Override
  public long convert(Object data) {
    GridFSInputFile file;
    if (data instanceof byte[]) {
      file = _gridFS.createFile((byte[])data);
      file.put(BINARY_TYPE, BYTEARRAY);
    } else if (data instanceof float[]) {
      file = _gridFS.createFile(new FloatArrayInputStream((float[])data));
      file.put(BINARY_TYPE, FLOATARRAY);
    } else if (data instanceof InputStream) {
      file = _gridFS.createFile((InputStream)data);
      file.put(BINARY_TYPE, INPUTSTREAM);
    } else if (data instanceof ByteBuffer) {
      ByteBuffer bb = (ByteBuffer)data;
      byte[] buf;
      if (bb.hasArray()) {
        buf = bb.array();
      } else {
        bb.rewind();
        buf = new byte[bb.remaining()];
        bb.get(buf);
      }
      file = _gridFS.createFile(buf);
      file.put(BINARY_TYPE, BYTEBUFFER);
    } else if (data instanceof FloatBuffer) {
      FloatBuffer bb = (FloatBuffer)data;
      float[] buf;
      if (bb.hasArray()) {
        buf = bb.array();
      } else {
        bb.rewind();
        buf = new float[bb.remaining()];
        bb.get(buf);
      }
      file = _gridFS.createFile(new FloatArrayInputStream(buf));
      file.put(BINARY_TYPE, FLOATBUFFER);
    } else {
      return 0;
    }

    long oid = _counter.getNextId();
    file.put(MongoDBVLargeCollection.OID, oid);
    _convertedFiles.add(file);
    return oid;
  }
View Full Code Here

        if (gridFile != null) {
            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }
View Full Code Here

        logger.debug("Content in bytes: {}", content.length);

        GridFS gridFS = new GridFS(mongoDB);
        for (int i = 0; i < count; i++) {

            GridFSInputFile in = gridFS.createFile(content);
            in.setFilename("lorem-" + i + ".pdf");
            in.setContentType("application/pdf");
            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());
            ids.add(id);
        }

        CountResponse countResponse;
View Full Code Here

        try {
            createDatabase();
            byte[] content = copyToBytesFromClasspath(RiverMongoWithGridFSTest.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");
            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());

            createRiver();
            Thread.sleep(wait);
            refreshIndex();

            CountResponse countResponse = getNode().client().count(countRequest(getIndex())).actionGet();
            logger.debug("Index total count: {}", countResponse.getCount());
            assertThat(countResponse.getCount(), equalTo(1l));

            GetResponse getResponse = getNode().client().get(getRequest(getIndex()).id(id)).get();
            logger.debug("Get request for id {}: {}", id, getResponse.isExists());
            assertThat(getResponse.isExists(), equalTo(true));

            SearchResponse response = getNode().client().prepareSearch(getIndex()).setQuery(QueryBuilders.queryString("Aliquam")).execute()
                    .actionGet();
            logger.debug("SearchResponse {}", response.toString());
            long totalHits = response.getHits().getTotalHits();
            logger.debug("TotalHits: {}", totalHits);
            assertThat(totalHits, equalTo(1l));

            in = gridFS.createFile(content);
            in.setFilename("test-attachment-2.html");
            in.setContentType("text/html");
            in.save();
            in.validate();

            id = in.getId().toString();

            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 = getNode().client().count(countRequest(getIndex())).actionGet();
View Full Code Here

            createAlias();
            super.createRiver(TEST_MONGODB_RIVER_GRIDFS_JSON);
            byte[] content = copyToBytesFromClasspath(RiverMongoWithGridFSTest.TEST_ATTACHMENT_HTML);
            logger.debug("Content in bytes: {}", content.length);
            GridFS gridFS = new GridFS(mongoDB, getCollection());
            GridFSInputFile in = gridFS.createFile(content);
            in.setFilename("test-attachment.html");
            in.setContentType("text/html");
            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

        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");
            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

        try {
            // createDatabase();
            byte[] content = copyToBytesFromClasspath(TEST_ATTACHMENT_PDF);
            logger.debug("Content in bytes: {}", content.length);
            GridFS gridFS = new GridFS(mongoDB);
            GridFSInputFile in = gridFS.createFile(content);
            in.setFilename("lorem.pdf");
            in.setContentType("application/pdf");
            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

TOP

Related Classes of com.mongodb.gridfs.GridFSInputFile$MyOutputStream

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.