本文整理汇总了Java中com.mongodb.gridfs.GridFSFile.validate方法的典型用法代码示例。如果您正苦于以下问题:Java GridFSFile.validate方法的具体用法?Java GridFSFile.validate怎么用?Java GridFSFile.validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.gridfs.GridFSFile
的用法示例。
在下文中一共展示了GridFSFile.validate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDataSetAttachment
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* Save the attachment for a data set.
* @param metadata The metadata of the attachment.
* @return The GridFs filename.
* @throws IOException thrown when the input stream is not closable
*/
public String createDataSetAttachment(MultipartFile multipartFile,
DataSetAttachmentMetadata metadata) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String currentUser = SecurityUtils.getCurrentUserLogin();
metadata.setVersion(0L);
metadata.setCreatedDate(LocalDateTime.now());
metadata.setCreatedBy(currentUser);
metadata.setLastModifiedBy(currentUser);
metadata.setLastModifiedDate(LocalDateTime.now());
String filename = buildFileName(metadata);
String contentType = mimeTypeDetector.detect(multipartFile);
GridFSFile gridFsFile = this.operations.store(in,
filename, contentType, metadata);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}
示例2: createInstrumentAttachment
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* Save the attachment for an instrument.
* @param metadata The metadata of the attachment.
* @return The GridFs filename.
* @throws IOException thrown when the input stream cannot be closed
*/
public String createInstrumentAttachment(MultipartFile multipartFile,
InstrumentAttachmentMetadata metadata) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String currentUser = SecurityUtils.getCurrentUserLogin();
metadata.setVersion(0L);
metadata.setCreatedDate(LocalDateTime.now());
metadata.setCreatedBy(currentUser);
metadata.setLastModifiedBy(currentUser);
metadata.setLastModifiedDate(LocalDateTime.now());
String contentType = mimeTypeDetector.detect(multipartFile);
GridFSFile gridFsFile = this.operations.store(in,
buildFileName(metadata), contentType, metadata);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}
示例3: createSurveyAttachment
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* Save the attachment for a survey.
* @param metadata The metadata of the attachment.
* @return The GridFs filename.
* @throws IOException thrown when the input stream is not closable
*/
public String createSurveyAttachment(MultipartFile multipartFile,
SurveyAttachmentMetadata metadata) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String currentUser = SecurityUtils.getCurrentUserLogin();
metadata.setVersion(0L);
metadata.setCreatedDate(LocalDateTime.now());
metadata.setCreatedBy(currentUser);
metadata.setLastModifiedBy(currentUser);
metadata.setLastModifiedDate(LocalDateTime.now());
String contentType = mimeTypeDetector.detect(multipartFile);
String filename = buildFileName(metadata);
GridFSFile gridFsFile = this.operations.store(in,
filename, contentType, metadata);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}
示例4: createStudyAttachment
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* Save the attachment for a study.
* @param metadata The metadata of the attachment.
* @return The GridFs filename.
* @throws IOException thrown when the input stream cannot be closed
*/
public String createStudyAttachment(MultipartFile multipartFile,
StudyAttachmentMetadata metadata) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String currentUser = SecurityUtils.getCurrentUserLogin();
metadata.setVersion(0L);
metadata.setCreatedDate(LocalDateTime.now());
metadata.setCreatedBy(currentUser);
metadata.setLastModifiedBy(currentUser);
metadata.setLastModifiedDate(LocalDateTime.now());
metadata.generateId();
String contentType = mimeTypeDetector.detect(multipartFile);
GridFSFile gridFsFile = this.operations.store(in,
StudyAttachmentFilenameBuilder.buildFileName(metadata), contentType, metadata);
gridFsFile.validate();
javers.commit(currentUser, metadata);
return gridFsFile.getFilename();
}
}
示例5: saveTempFile
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* Save the given stream to mongo in a "temp directory" and return the final filename.
*
* @param stream The bytes to save
* @param fileName The fileName which gets prefixed with /tmp/
* @param contentType the content type of the file
* @return the final filename
* @throws IOException thrown when the input stream cannot be closed
*/
public String saveTempFile(InputStream stream, String fileName, String contentType)
throws IOException {
try (InputStream inputStream = stream) {
GridFSFile gridFsFile =
this.gridfOperations.store(inputStream, "/tmp/" + fileName, contentType);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}
示例6: saveQuestionImage
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* This method save an image into GridFS/MongoDB based on a byteArrayOutputStream.
* Existing image should be deleted before saving/updating an image
* @param questionId The id of the question to be saved
* @return return the name of the saved image in the GridFS / MongoDB.
* @throws IOException Thrown when the input stream cannot be closed
*/
public String saveQuestionImage(MultipartFile multipartFile,
String questionId) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String contentType = mimeTypeDetector.detect(multipartFile);
GridFSFile gridFsFile = this.operations.store(in,
"/questions/" + questionId, contentType);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}
示例7: saveSurveyImage
import com.mongodb.gridfs.GridFSFile; //导入方法依赖的package包/类
/**
* This method save an image into GridFS/MongoDB based on a byteArrayOutputStream.
* Existing image should be deleted before saving/updating an image
* @param surveyId The id of the question to be saved
* @return return the name of the saved image in the GridFS / MongoDB.
* @throws IOException thrown if the input stream cannot be closed
*/
public String saveSurveyImage(MultipartFile multipartFile,
String surveyId, String fileName) throws IOException {
try (InputStream in = multipartFile.getInputStream()) {
String relativePathWithName = "/surveys/" + surveyId + "/" + fileName;
String contentType = mimeTypeDetector.detect(multipartFile);
GridFSFile gridFsFile = this.operations.store(in, relativePathWithName, contentType);
gridFsFile.validate();
return gridFsFile.getFilename();
}
}