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


  }

  @Override
  public void storeAttachment(AttachmentId attachmentId, InputStream data)
      throws IOException {
    GridFSInputFile file = getAttachmentGrid().createFile(data, attachmentId.serialise());

    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

    @Test(enabled = ENABLED)
    public void findFile() throws Exception {
        File file = createRandomFile();
        String hash = sha256(file);

        GridFSInputFile inputFile = gridFS.createFile(new FileInputStream(file));
        inputFile.put("_id", hash);
        inputFile.save();

        InputStream dbInputStream = dao.findOne(hash);

        assertNotNull(dbInputStream, "Expected to find file with name " + hash);
        File actualFile = new File(dataDir, "findFile.actual");
View Full Code Here

        }
        return dbFile.getInputStream();
    }

    public void save(File file) throws IOException {
        GridFSInputFile inputFile = gridFS.createFile(new BufferedInputStream(new FileInputStream(file)));
        inputFile.put("_id", file.getName());
        inputFile.save();
    }
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

        // + originalFilename);
        //
        // file.transferTo(dest);

        GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
        GridFSInputFile gfsFile = gridFs.createFile(file.getFileItem()
            .getInputStream());

        gfsFile.setFilename(originalFilename);
        gfsFile.save();

      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
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();

        IOUtils.closeQuietly(in);

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

    try
    {
      logger.info("Writing GridFS file: "+file.getAbsolutePath()
          + ", length: " + file.length()
          + ". Writing with chunk size: " + chunkSize);
      GridFSInputFile gridFile = fs.createFile(file);

      //Add user-defined properties
      for (String key : properties.keySet())
      {
        gridFile.put(key, properties.get(key));
      }
      gridFile.put("timestamp", System.currentTimeMillis());
      gridFile.put("uniqueId", UidGenerator.generateUid());


      gridFile.setFilename(renameTo);
      gridFile.save(chunkSize);
      gridFile.validate();
    }
    catch(IOException e)
    {
      throw new DBException("Failed to read input file: "
          +file.getAbsolutePath(), e);
View Full Code Here

  {
    DB db = DBUtils.connectDB("localhost", 27017, "test");

    GridFS fs = new GridFS(db);
   
    GridFSInputFile inputFile = fs.createFile(new File("./foo.txt"));
    System.out.println("GridFS file: "+inputFile.getFilename());


  }
View Full Code Here

   
    DB mdb = this.mongoConn.getDatabase(this.collection);
    GridFS gfsFile = new GridFS(mdb, this.namespace);
   
    // Load in a GridFS file the Inptustream
    GridFSInputFile gfsInputFile = gfsFile.createFile(is);
   
    // set a filename for identification purposes. We use the previously created UUID
    gfsInputFile.setFilename(uuid);
   
    // save the file file into mongoDB and disconnect
    gfsInputFile.save();
    this.mongoConn.disconnect();
   
    this.logger.info("[File][GridFS] File with " + uuid + "UUID data Stored");
   
    return uuid;
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.