本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
}