Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSInputFile$MyOutputStream


      MongoRepository mongoRepository = (MongoRepository) repository;

      GridFS gridFS = mongoRepository.getGridFS();

      GridFSInputFile file = gridFS.createFile(new File(
          "test-files/sample.txt"));

      file.setId("sample.txt");

      file.save();

      List<GridFSDBFile> files = gridFS.find((DBObject) JSON
          .parse("{ _id : 'sample.txt' }"));

      assertNotNull(files);
View Full Code Here


            if (!databaseService.getDbList().contains(dbName)) {
                throw new DatabaseException(ErrorCodes.DB_DOES_NOT_EXISTS, "DB [" + dbName + "] DOES NOT EXIST");
            }

            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            GridFSInputFile fsInputFile = gridFS.createFile(inputStream, fileData.getFileName());
            fsInputFile.setContentType(formData.getMediaType().toString());
            fsInputFile.save();
            String objectId = JSON.serialize(fsInputFile.getId());
            JSONObject obj = new JSONObject();
            obj.put("name", fsInputFile.getFilename());
            obj.put("size", fsInputFile.getLength());
            obj.put("url", String.format("services/%s/%s/gridfs/getfile?id=%s&download=%s&connectionId=%s&ts=%s", dbName, bucketName, objectId, false, connectionId, new Date()));
            obj.put("delete_url", String.format("services/%s/%s/gridfs/dropfile?id=%s&connectionId=%s&ts=%s", dbName, bucketName, objectId, connectionId, new Date().getTime()));
            obj.put("delete_type", "GET");
            result.put(obj);
View Full Code Here

        ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy);

        try {

            if (cacheWriteEnable) {
                final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f);
                gfsFile.setFilename(f.getName());
                gfsFile.save();

                final Cache c = new Cache();
                c.setServletName(this.getClass().getName());
                c.setCacheKey(cacheKey);
                c.setGridId(gfsFile.getId().toString());

                ds.save(c);

            }
View Full Code Here

        try {

            if (cacheWriteEnable) {

                final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f);
                gfsFile.setFilename(f.getName());
                gfsFile.save();

                final Cache c = new Cache();
                c.setServletName(this.getClass().getName());
                c.setCacheKey(cacheKey);
                c.setGridId(gfsFile.getId().toString());

                ds.save(c);

            }
View Full Code Here

        ChartUtilities.saveChartAsJPEG(f, chart, dimx, dimy);

        try {

            if (cacheWriteEnable) {
                final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f);
                gfsFile.setFilename(f.getName());
                gfsFile.save();

                final Cache c = new Cache();
                c.setServletName(this.getClass().getName());
                c.setCacheKey(cacheKey);
                c.setGridId(gfsFile.getId().toString());

                ds.save(c);

            }
View Full Code Here

   */
  public GridFSFile store(InputStream content, String filename, String contentType, DBObject metadata) {

    Assert.notNull(content);

    GridFSInputFile file = getGridFs().createFile(content);

    if (filename != null) {
      file.setFilename(filename);
    }

    if (metadata != null) {
      file.setMetaData(metadata);
    }

    if (contentType != null) {
      file.setContentType(contentType);
    }

    file.save();
    return file;
  }
View Full Code Here

        .is(df.getDocumentId().getID())
        .and(FILENAME_KEY)
        .is(df.getFileName());
    documentfs.remove(qb.get());
   
    GridFSInputFile input = documentfs.createFile(df.getStream(), df.getFileName());
    input.put(DOCUMENT_KEY, df.getDocumentId().getID());
    input.put(ENCODING_KEY, df.getEncoding());
    input.put(MIMETYPE_KEY, df.getMimetype());
   
    input.save();
   
    /**
     * This is here because of random failures when trying to do this query from another thread.
     *
     * RemotePipelineTest.testSaveFile() failed 2 or 3 times out of 100.
View Full Code Here

    }
  }
 
  @Override
  public Object save(String fileName, InputStream file) {
    GridFSInputFile inputFile = pipelinefs.createFile(file, fileName);
    inputFile.save();
    return inputFile.getId();
  }
View Full Code Here

 
  @Override
  public boolean save(Object id, String fileName, InputStream file) {
    pipelinefs.remove(new BasicDBObject(MongoDocument.MONGO_ID_KEY, id));
   
    GridFSInputFile inputFile = pipelinefs.createFile(file, fileName);
    inputFile.put("_id", id);
    inputFile.save();
    return true;
  }
View Full Code Here

    public void tearDown() throws Exception {
        dropGridFsCollections();
    }

    private void insertTestFileInGridFS() {
        GridFSInputFile gridFile = gridFS.createFile(new byte[]{
                (byte) 0xCA,
                (byte) 0xFE,
                (byte) 0xBA,
                (byte) 0xBE});
        gridFile.setFilename("test.txt");
        gridFile.save();
    }
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.