Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile


        this.gridFS = gridFS;
    }

    @Override
    public Long execute() throws Exception {
        GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        if (gridFSDBFile == null) {
            throw new Exception("Blob does not exist");
        }
        return gridFSDBFile.getLength();
    }
View Full Code Here


    response.setHeader("Content-disposition", "attachment;filename="
        + new String(fileName.getBytes(), "iso8859-1"));

    OutputStream os = response.getOutputStream();
    GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
    GridFSDBFile gridFSDBFile = gridFs.findOne(fileName);

    FileCopyUtils.copy(gridFSDBFile.getInputStream(), os);
   
    os.flush();
    os.close();
  }
View Full Code Here

    }

    public int readBlob(String blobId, long pos, byte[] buff, int off,
            int length) throws Exception {

        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
        if (f == null) {
            throw new NotFoundException(blobId);
        }
        // todo provide a more efficient implementation (gridfs stores the data in chunks)
        //long nChunk = pos / f.getChunkSize();
        InputStream in = f.getInputStream();
        try {
            in.skip(pos);
            return in.read(buff, off, length);
        } finally {
            IOUtils.closeQuietly(in);
View Full Code Here

            IOUtils.closeQuietly(in);
        }
    }

    public long getBlobLength(String blobId) throws Exception {
        GridFSDBFile f = fs.findOne(new ObjectId(blobId));
        if (f == null) {
            throw new NotFoundException(blobId);
        }

        return f.getLength();
    }
View Full Code Here

        // Optional bucket, default is "fs"
        String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET);
        GridFS files = new GridFS(db, bucket);

        GridFSDBFile file = files.findOne(objectId);
        if (file == null) {
            sendError(message, "File does not exist: " + objectId.toString());
            return;
        }

        JsonObject fileInfo = new JsonObject()
                .putString("filename", file.getFilename())
                .putString("contentType", file.getContentType())
                .putNumber("length", file.getLength())
                .putNumber("chunkSize", file.getChunkSize())
                .putNumber("uploadDate", file.getUploadDate().getTime());

        DBObject metadata = file.getMetaData();
        if (metadata != null) {
            fileInfo.putObject("metadata", new JsonObject(JSON.serialize(metadata)));
        }

        // Send file info
View Full Code Here

    {
      BasicDBObject query = new BasicDBObject();
      query.put("filename", filename);

      List<GridFSDBFile> results = fs.find(query);
      GridFSDBFile gridFile = null;
      /*
       * We need to iterate over these manually, rather than performing a
       * generic query with sortBy(), because GridFSDBFile.putAll currently
       * throws an UnsupportedOperationException
       */
      for (GridFSDBFile file : results)
      {
        if (gridFile == null)
        {
          gridFile = file;
        }
        else
        {
          if ((Long) gridFile.get("timestamp") < (Long) file.get("timestamp"))
          {
            gridFile = file;
          }
        }
      }
View Full Code Here

    {
      BasicDBObject query = new BasicDBObject();
      query.put("filename", filename);

      List<GridFSDBFile> results = fs.find(query);
      GridFSDBFile gridFile = null;
      /*
       * We need to iterate over these manually, rather than performing a
       * generic query with sortBy(), because GridFSDBFile.putAll currently
       * throws an UnsupportedOperationException
       */
      for (GridFSDBFile file : results)
      {
        if (gridFile == null)
        {
          gridFile = file;
        }
        else
        {
          if ((Long) gridFile.get("timestamp") > (Long) file.get("timestamp"))
          {
            gridFile = file;
          }
        }
      }
View Full Code Here

   * @throws DBException
   */
  public void downloadFile(File destinationDir, String filename)
      throws DBException
  {
    GridFSDBFile gridFile = null;
    try
    {
      //gridFile = fs.findOne(filename);
      gridFile = findLatestGridFileWithName(filename);
    }
View Full Code Here

   * @throws DBException
   */
  public void downloadFile(File destinationDir, String filename, String renameTo)
      throws DBException
  {
    GridFSDBFile gridFile = null;
    try
    {
//      gridFile = fs.findOne(filename);
      gridFile = findLatestGridFileWithName(filename);
    }
View Full Code Here

            RepositoryDocument rd = new RepositoryDocument();
            if (Logging.connectors.isDebugEnabled()) {
                Logging.connectors.debug("GridFS: Processing document _id = " + _id);
            }

            GridFSDBFile document = gfs.findOne(new ObjectId(_id));

            if (document == null) {
                activities.deleteDocument(_id);
                i++;
                continue;
            }

            DBObject metadata = document.getMetaData();
            if (metadata == null) {
                Logging.connectors.warn("GridFS: Document " + _id + " has a null metadata - skipping.");
                i++;
                continue;
            }

            String urlValue = document.getMetaData().get(this.url) == null
                    ? StringUtils.EMPTY
                    : document.getMetaData().get(this.url).toString();
            if (!StringUtils.isEmpty(urlValue)) {
                if (!scanOnly[i]) {
                    boolean validURL;
                    try {
                        new java.net.URI(urlValue);
                        validURL = true;
                    } catch (java.net.URISyntaxException e) {
                        validURL = false;
                    }
                    if (validURL) {
                        long fileLenght = document.getLength();
                        InputStream is = document.getInputStream();
                        try {
                            Date indexingDate = new Date();
                            rd.setBinary(is, fileLenght);
                            rd.setCreatedDate(document.getUploadDate());
                            rd.setFileName(document.getFilename());
                            rd.setIndexingDate(indexingDate);
                            rd.setMimeType(document.getContentType());
                            String[] aclsArray = null;
                            String[] denyAclsArray = null;
                            if (acl != null) {
                                try {
                                    Object aclObject = document.getMetaData().get(acl);
                                    if (aclObject != null) {
                                        List<String> acls = (List<String>) aclObject;
                                        aclsArray = (String[]) acls.toArray();
                                    }
                                } catch (ClassCastException e) {
                                    // This is bad because security will fail
                                    Logging.connectors.warn("GridFS: Document " + _id + " metadata ACL field doesn't contain List<String> type.");
                                    throw new ManifoldCFException("Security decoding error: "+e.getMessage(),e);
                                }
                            }
                            if (denyAcl != null) {
                                try {
                                    Object denyAclObject = document.getMetaData().get(denyAcl);
                                    if (denyAclObject != null) {
                                        List<String> denyAcls = (List<String>) denyAclObject;
                                        denyAcls.add(GLOBAL_DENY_TOKEN);
                                        denyAclsArray = (String[]) denyAcls.toArray();
                                    }
View Full Code Here

TOP

Related Classes of com.mongodb.gridfs.GridFSDBFile

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.