use of com.mongodb.gridfs.GridFSDBFile in project mongo-hadoop by mongodb.
the class GridFSInputFormat method getSplits.
@Override
public List<InputSplit> getSplits(final JobContext context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
DBCollection inputCollection = MongoConfigUtil.getInputCollection(conf);
MongoClientURI inputURI = MongoConfigUtil.getInputURI(conf);
GridFS gridFS = new GridFS(inputCollection.getDB(), inputCollection.getName());
DBObject query = MongoConfigUtil.getQuery(conf);
List<InputSplit> splits = new LinkedList<InputSplit>();
for (GridFSDBFile file : gridFS.find(query)) {
// One split per file.
if (MongoConfigUtil.isGridFSWholeFileSplit(conf)) {
splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength()));
} else // One split per file chunk.
{
for (int chunk = 0; chunk < file.numChunks(); ++chunk) {
splits.add(new GridFSSplit(inputURI, (ObjectId) file.getId(), (int) file.getChunkSize(), file.getLength(), chunk));
}
}
}
LOG.debug("Found GridFS splits: " + splits);
return splits;
}
use of com.mongodb.gridfs.GridFSDBFile in project play-cookbook by spinscale.
the class Application method showImage.
public static void showImage(String id) {
GridFSDBFile file = GridFsHelper.getFile(id);
notFoundIfNull(file);
renderBinary(file.getInputStream(), file.getFilename(), file.getLength(), file.getContentType(), true);
}
use of com.mongodb.gridfs.GridFSDBFile in project mongomvcc by igd-geo.
the class DefaultConvertStrategy method convert.
@Override
public Object convert(long oid) throws IOException {
GridFSDBFile file = _gridFS.findOne(new BasicDBObject(MongoDBVLargeCollection.OID, oid));
if (file == null) {
return null;
}
int type = (Integer) file.get(BINARY_TYPE);
Object r;
if (type == BYTEARRAY) {
r = toByteArray(file);
} else if (type == INPUTSTREAM) {
r = file.getInputStream();
} else if (type == BYTEBUFFER) {
r = ByteBuffer.wrap(toByteArray(file));
} else if (type == FLOATARRAY) {
r = toFloatArray(file);
} else if (type == FLOATBUFFER) {
r = FloatBuffer.wrap(toFloatArray(file));
} else {
// no information. simply forward the input stream
r = file.getInputStream();
}
return r;
}
use of com.mongodb.gridfs.GridFSDBFile in project leopard by tanhaichao.
the class DfsGridImpl method read.
@Override
public byte[] read(String filename) throws IOException {
GridFSDBFile file = getGridFS().findOne(filename);
if (file == null) {
throw new FileNotFoundException(filename);
}
InputStream input = file.getInputStream();
try {
return IOUtils.toByteArray(input);
} finally {
input.close();
}
}
use of com.mongodb.gridfs.GridFSDBFile in project pmph by BCSquad.
the class CmsManualServiceImpl method addCmsManual.
@Override
public CmsManual addCmsManual(CmsManual cmsManual) throws CheckedServiceException {
if (ObjectUtil.isNull(cmsManual)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "CmsManual对象参数为空");
}
if (ObjectUtil.isNull(cmsManual.getAttachment())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "附件id参数为空");
}
/*if (StringUtil.isEmpty(cmsManual.getNote())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS,
CheckedExceptionResult.NULL_PARAM, "备注参数为空");
}*/
if (ObjectUtil.isNull(cmsManual.getUserId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "上传者id参数为空");
}
if (cmsManual.getManualName().length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.ILLEGAL_PARAM, "操作手册名称不能超过50个字!");
}
String fileName = "操作手册.doc";
GridFSDBFile file = fileService.get(cmsManual.getAttachment());
if (ObjectUtil.notNull(file)) {
fileName = file.getFilename();
}
cmsManual.setManualName(fileName);
cmsManualDao.addCmsManual(cmsManual);
return cmsManual;
}
Aggregations