示例#1
0
  public String getDocument(String GUID, OutputStream out) throws DocumentException {

    try {
      GridFS gridFS = new GridFS(dataBase);

      ObjectId key = new ObjectId(GUID);
      GridFSDBFile gridFSDBFile = gridFS.find(key);

      if (gridFSDBFile == null) {
        throw new DocumentException("No existe el documento");
      }
      if (out != null) gridFSDBFile.writeTo(out);
      CommandResult result = dataBase.getLastError();
      if (!result.ok()) {
        throw new DocumentException(result.getErrorMessage());
      }

      DBObject dbObject = gridFSDBFile.getMetaData();
      return JSON.serialize(dbObject);
    } catch (Exception e) {
      log.error("getDocument error:" + e.getMessage());
      e.printStackTrace();
      throw new DocumentException(e.getMessage());
    }
  }