当前位置: 首页>>代码示例>>Java>>正文


Java GridFSDBFile类代码示例

本文整理汇总了Java中com.mongodb.gridfs.GridFSDBFile的典型用法代码示例。如果您正苦于以下问题:Java GridFSDBFile类的具体用法?Java GridFSDBFile怎么用?Java GridFSDBFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GridFSDBFile类属于com.mongodb.gridfs包,在下文中一共展示了GridFSDBFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isExistedImage

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
private String isExistedImage(BundleEntry entry) {
    GridFS gridFS = getInstance();
    DBObject query = new BasicDBObject();
    query.put("crc",entry.crc);
    query.put("md5_source",entry.md5);
    GridFSDBFile _current = gridFS.findOne(query);
    //根据MD5值查询,检测是否存在
    if(_current == null) {
        return null;
    }
    String format = (String)_current.get("format");
    if(format.startsWith(".")) {
        return _current.getFilename() + format;
    }
    return _current.getFilename() + "." + format;
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:17,代码来源:GridFSClient.java

示例2: apply

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public FileEntry apply(GridFSDBFile input) {
    FileEntry fe = new FileEntry();
    fe.setId((ObjectId) input.getId());
    fe.setName(input.getFilename());
    fe.setSize(input.getLength());
    fe.setMime(input.getContentType());
    fe.setCtime(input.getUploadDate());
    //
    DBObject metadata = input.getMetaData();
    if (null != metadata) {
        fe.setCreator((String) metadata.get("creator"));
        fe.setPrivateFile((Boolean) metadata.get("private"));
        fe.setDescription((String) metadata.get("description"));
    }
    //
    return fe;
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:19,代码来源:FileStoreService.java

示例3: execute

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
public String execute() throws IOException {
    String[] fids = fid.split(",");
    File[] files = new File[fids.length];
    String username = (String) httpSession.get("username");
    System.out.println("fids: " + Arrays.toString(fids));

    for (int i = 0; i < files.length; i++) {
        GridFSDBFile gridFSDBFile = boxService.download(fids[i]);
        files[i] = new File(gridFSDBFile.getFilename());
        gridFSDBFile.writeTo(files[i]);
    }
    filename = "/tmp/download.zip";
    ZipFileUtil.compressFiles2Zip(files, filename);

    inputStream = new FileInputStream(new File(filename));
    filename = "download.zip";
    return SUCCESS;
}
 
开发者ID:0x603,项目名称:SixBox,代码行数:19,代码来源:DownloadMultiFile.java

示例4: getFile

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public GridFSDBFile getFile(String boardId, String fileId) throws FileNotFoundException {
    User user = getAuthorizedUser();

    Board board = boardRepository.findOne(boardId);

    if(!user.hasRole(UserRole.ADMIN) && !board.getOwner().equals(user) && !board.getUsers().contains(user)) {
        log.warn("User {} has no rights on board {}", user.getUsername(), boardId);
        throw new AccessDeniedException("User does not have rights to access this board");
    }

    FSFile file = filesRepository.findOne(fileId);
    if ( file == null ) {
        log.debug("No File with given ID " + fileId + " found.");
        throw new FileNotFoundException();
    }
    return fileStore.read(file);
}
 
开发者ID:Morbrolhc,项目名称:kanbanboard,代码行数:19,代码来源:FileServiceImpl.java

示例5: storeBlob

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public Boolean storeBlob(CallingContext context, String docPath, InputStream newContent, Boolean append) {
    GridFS gridFS = getGridFS();
    GridFSInputFile file;
    if (!append) {
        gridFS.remove(docPath);
        file = createNewFile(docPath, newContent);
    } else {
        GridFSDBFile existing = gridFS.findOne(docPath);
        if (existing != null) {
            try {
                file = updateExisting(context, docPath, newContent, gridFS, existing);
            } catch (IOException e) {
                file = null;
                log.error(String.format("Error while appending to docPath %s: %s", docPath, ExceptionToString.format(e)));
            }

        } else {
            file = createNewFile(docPath, newContent);
        }
    }
    return file != null;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:GridFSBlobHandler.java

示例6: getBlob

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public InputStream getBlob(CallingContext context, String docPath) {
    GridFS gridFS = getGridFS();
    String lockKey = createLockKey(gridFS, docPath);
    LockHandle lockHandle = grabLock(context, lockKey);
    InputStream retVal = null;
    try {
        GridFSDBFile file = gridFS.findOne(docPath);
        if (file != null) {
            retVal = file.getInputStream();
        }
    } finally {
        releaseLock(context, lockKey, lockHandle);
    }
    return retVal;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:GridFSBlobHandler.java

示例7: create

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@RequestMapping(method = POST)
@PreAuthorize("isAuthenticated()")
@ResponseBody
@ResponseStatus(CREATED)
public String create(
        @RequestParam("assetData") final MultipartFile assetData
) throws IOException {

    // Check duplicates
    final GridFSDBFile file = this.gridFs.findOne(Query.query(Criteria.where("filename").is(assetData.getOriginalFilename())));
    if (file != null) {
        throw new DataIntegrityViolationException(String.format("Asset with name '%s' already exists", assetData.getOriginalFilename()));
    } else {
        try (InputStream usedStream = TikaInputStream.get(assetData.getInputStream())) {
            MediaType mediaType = null;
            try {
                mediaType = MediaType.parse(tika.detect(usedStream, assetData.getOriginalFilename()));
            } catch (IOException e) {
                log.warn("Could not detect content type", e);
            }
            this.gridFs.store(assetData.getInputStream(), assetData.getOriginalFilename(), Optional.ofNullable(mediaType).map(MediaType::toString).orElse(null));
            return assetData.getOriginalFilename();
        }
    }
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:26,代码来源:AssetApiController.java

示例8: get

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@RequestMapping({"/{filename:.+}"})
public void get(
        @PathVariable final String filename,
        final HttpServletRequest request,
        final HttpServletResponse response
) throws IOException {
    final GridFSDBFile file = this.gridFs.findOne(Query.query(Criteria.where("filename").is(filename)));
    if (file == null) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {
        final int cacheForDays = 365;
        response.setHeader("Content-Type", file.getContentType());
        response.setHeader("Content-Disposition", String.format("inline; filename=\"%s\"", file.getFilename()));
        response.setHeader("Expires", now(of("UTC")).plusDays(cacheForDays).format(RFC_1123_DATE_TIME));
        response.setHeader("Cache-Control", String.format("max-age=%d, %s", TimeUnit.DAYS.toSeconds(cacheForDays), "public"));
        file.writeTo(response.getOutputStream());
        response.flushBuffer();
    }
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:20,代码来源:AssetApiController.java

示例9: createShouldThrowException

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Test
public void createShouldThrowException() throws Exception {
    final MockMultipartFile multipartFile = new MockMultipartFile("assetData", this.getClass().getResourceAsStream("/eu/euregjug/site/assets/asset.png"));
    when(this.gridFsTemplate.findOne(any(Query.class))).thenReturn(mock(GridFSDBFile.class));

    mvc
            .perform(
                    fileUpload("/api/assets")
                    .file(multipartFile)
            )
            .andExpect(status().isConflict())
            .andExpect(content().string(""));

    verify(this.gridFsTemplate).findOne(any(Query.class));
    verifyNoMoreInteractions(this.gridFsTemplate);
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:17,代码来源:AssetApiControllerTest.java

示例10: createPreviewPdfFile

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public Id createPreviewPdfFile(GridFSDBFile file) {
    for (DocumentConverter converter : getConverters()) {
        if (converter.canConvert(file.getContentType())) {
            ByteArrayOutputStream stream = converter.convert(file.getInputStream());
            if (stream == null)
                return null;

            Id id = app.nextId();
            createGridFsFile(id, new ByteArrayInputStream(stream.toByteArray()), "preview_" + file.getFilename(),
                "application/pdf");
            return id;
        }
    }
    return null;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:17,代码来源:DefaultMediaAssetHelper.java

示例11: createPreview

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public void createPreview(MediaAssetFile mediaAssetFile, GridFSDBFile file) {
    if (file.getContentType().contains("image")) {
        mediaAssetFile.setPreviewImageId(mediaAssetFile.getId());
        mediaAssetFile.setPreviewDocumentMimeType(mediaAssetFile.getMimeType());
    } else if (file.getContentType().contains("pdf")) {
        mediaAssetFile.setPreviewDocId(mediaAssetFile.getId());
        mediaAssetFile.setPreviewDocumentMimeType("aplication/pdf");
        mediaAssetFile.setPreviewImageId(createPreviewImage(file));
        mediaAssetFile.setPreviewDocumentMimeType("image/png");
    } else {
        Id docId = createPreviewPdfFile(file);
        if (docId != null) {
            mediaAssetFile.setPreviewDocId(docId);
            mediaAssetFile.setPreviewDocumentMimeType("aplication/pdf");
            Id imgId = createPreviewImage(mediaAssetService.getGridFsFile(docId));
            if (imgId != null) {
                mediaAssetFile.setPreviewImageId(imgId);
                mediaAssetFile.setPreviewDocumentMimeType("image/png");
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:24,代码来源:DefaultMediaAssetHelper.java

示例12: update

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public MediaAsset update(Id mediaAssetId, InputStream inputStream, String filename) {

    String basename = FilenameUtils.getBaseName(filename);
    String extension = FilenameUtils.getExtension(filename);
    filename = Strings.slugify2(basename) + "." + extension;
    String mimeType = getMimeType(filename);

    MediaAssetFile mediaAssetFile = app.model(MediaAssetFile.class);
    mediaAssetFile.setId(app.nextId());
    mediaAssetFile.setMediaAssetId(mediaAssetId);
    mediaAssetFile.setName(filename);
    mediaAssetFile.setMimeType(mimeType);
    mediaAssetFile.setActive(false);
    mediaAssetFile
        .setSize(createGridFsFile(mediaAssetFile.getId(), inputStream, filename, mediaAssetFile.getMimeType()));
    GridFSDBFile file = getGridFsFile(mediaAssetFile.getId());
    mediaAssetFile.setMetadata(importMetadata(file.getInputStream()));
    mediaAssetHelper.createPreview(mediaAssetFile, file);
    mediaAssetFiles.add(mediaAssetFile);

    return mediaAssets.findById(MediaAsset.class, mediaAssetId);

}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:25,代码来源:DefaultMediaAssetService.java

示例13: validate

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Path("/validate")
@POST
public void validate(@PathParam("baseScreenshotId") String baseScreenshotId,
    @PathParam("newScreenshotId") String newScreenshotId) {
    logger.info(String.format("Validating: baseScreenshotId: '%s', newScreenshotId: ''%s",
        baseScreenshotId, newScreenshotId));

    String diffImageFileName = String.format("%s|%s|%s", baseScreenshotId, newScreenshotId, "-differences");
    ObjectId newBaseScreenshotId = new ObjectId(newScreenshotId);

    // pull the diff image from the DB, mark the field for processed screenshots to true
    BasicDBObject diffImageQuery = new BasicDBObject();
    diffImageQuery.put("filename", diffImageFileName);

    GridFSDBFile diffFile = GFS_DIFF_PHOTOS.find(diffImageQuery).iterator().next();
    diffFile.put("screenshotsHaveBeenReviewed", true);
    diffFile.save();

    // update the image id of the base screenshot with the id of the new screenshot
    BasicDBObject baseQuery = new BasicDBObject();
    baseQuery.put("imageId", new ObjectId(baseScreenshotId));

    DBObject baseObject = BASE_IMAGES.find(baseQuery).next();
    baseObject.put("imageId", newBaseScreenshotId);
    BASE_IMAGES.save(baseObject);
}
 
开发者ID:web-innovate,项目名称:selenium-screenshot-watcher,代码行数:27,代码来源:ReviewScreenshots.java

示例14: getScreenshotFromDb

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@GET
@Produces("image/png")
public Response getScreenshotFromDb(@PathParam("collection") String collection, @PathParam("_id") String imgId,
    @Context Request request) {
    EndpointUtil.printClientInfo(request);
    BasicDBObject screenshotQuery = new BasicDBObject();
    screenshotQuery.put("_id", new ObjectId(imgId));
    GridFSDBFile screenshotFound = null;
    switch (collection.toLowerCase()) {
        case "photo":
            screenshotFound = GFS_PHOTO.findOne(screenshotQuery);
            break;
        case "diff_photos":
            screenshotFound = GFS_DIFF_PHOTOS.findOne(screenshotQuery);
            break;
    }
    return Response.ok().entity(screenshotFound.getInputStream()).build();
}
 
开发者ID:web-innovate,项目名称:selenium-screenshot-watcher,代码行数:19,代码来源:RetrieveScreenshot.java

示例15: getEstimatedSizeBytes

import com.mongodb.gridfs.GridFSDBFile; //导入依赖的package包/类
@Override
public long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
  Mongo mongo = spec.connectionConfiguration().setupMongo();
  try {
    GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
    DBCursor cursor = createCursor(gridfs);
    long size = 0;
    while (cursor.hasNext()) {
      GridFSDBFile file = (GridFSDBFile) cursor.next();
      size += file.getLength();
    }
    return size;
  } finally {
    mongo.close();
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:MongoDbGridFSIO.java


注:本文中的com.mongodb.gridfs.GridFSDBFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。