本文整理汇总了Java中com.mongodb.gridfs.GridFSDBFile.containsField方法的典型用法代码示例。如果您正苦于以下问题:Java GridFSDBFile.containsField方法的具体用法?Java GridFSDBFile.containsField怎么用?Java GridFSDBFile.containsField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.gridfs.GridFSDBFile
的用法示例。
在下文中一共展示了GridFSDBFile.containsField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFile
import com.mongodb.gridfs.GridFSDBFile; //导入方法依赖的package包/类
public GridFSDBFile getFile(String path){
if(!this.isConnected()) return null;
GridFSDBFile file = null;
if(path.indexOf('$') > 0){
String[] t = path.split("\\$", 2);
file = getGridFS(t[0]).findOne(t[1]);
}else{
file = defaultFs.findOne(path);
}
if(file != null && file.containsField("localLength")){
file.put("localPath", new File(this.rootPath, file.getFilename()).getAbsolutePath());
file.put("length", (Long)file.get("localLength"));
}
return file;
}
示例2: serveFile
import com.mongodb.gridfs.GridFSDBFile; //导入方法依赖的package包/类
private void serveFile(String path,
HttpServletRequest request,
HttpServletResponse response) throws IOException{
GridFSDBFile file = HDFSArchiver.getArchiver().getFile(path);
if(file != null){
String content = null;
if(request.getParameter("download") == null){
content = file.getContentType();
}else {
content = "application/octet-stream";
}
if(content == null){
content = getContentType(path);
}
response.setContentType(content);
log.debug("Response file:" + path + ", content:" + content);
if(file.containsField("localPath")){
log.debug("local from local path:" + file.get("localPath"));
byte[] buffer = new byte[1024 * 40];
InputStream in = new FileInputStream(new File(file.get("localPath").toString()));
for(int len = buffer.length; len == buffer.length; ){
len = in.read(buffer);
response.getOutputStream().write(buffer, 0, len);
}
in.close();
}else {
file.writeTo(response.getOutputStream());
}
}else {
log.debug("Not found file:" + path);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().write("Not found file:" + path);
}
}
示例3: getBlob
import com.mongodb.gridfs.GridFSDBFile; //导入方法依赖的package包/类
@Override
public ByteArrayFileCache getBlob(final MD5 md5,
final ByteArrayFileCacheManager bafcMan)
throws NoSuchBlobException, BlobStoreCommunicationException,
FileCacheIOException, FileCacheLimitExceededException {
final GridFSDBFile out;
try {
out = getFile(md5);
if (out == null) {
throw new NoSuchBlobException(
"Attempt to retrieve non-existant blob with chksum " +
md5.getMD5());
}
final boolean sorted;
if (!out.containsField(Fields.GFS_SORTED)) {
sorted = false;
} else {
sorted = (Boolean)out.get(Fields.GFS_SORTED);
}
final InputStream file = out.getInputStream();
try {
return bafcMan.createBAFC(file, true, sorted);
} finally {
try {
file.close();
} catch (IOException ioe) {
throw new RuntimeException("Something is broken", ioe);
}
}
} catch (MongoException me) {
throw new BlobStoreCommunicationException(
"Could not read from the mongo database", me);
}
}