com.mongodb.gridfs.GridFS.getChunksCollection()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.mongodb.gridfs.GridFS.getChunksCollection()方法的一些代码示例,展示了GridFS.getChunksCollection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridFS.getChunksCollection()方法的具体详情如下:
包路径:com.mongodb.gridfs.GridFS
类名称:GridFS
方法名:getChunksCollection

GridFS.getChunksCollection介绍

[英]Gets the DBCollection in which the binary chunks are stored.
[中]获取存储二进制块的DBCollection。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Removes file from GridFS i.e. removes documents from files and chunks collections.
  3. */
  4. void remove() {
  5. fs.getFilesCollection().remove(new BasicDBObject("_id", id));
  6. fs.getChunksCollection().remove(new BasicDBObject("files_id", id));
  7. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Dumps a new chunk into the chunks collection. Depending on the flag, also partial buffers (at the end) are going to be written
  3. * immediately.
  4. *
  5. * @param writePartial Write also partial buffers full.
  6. * @throws MongoException if there's a failure
  7. */
  8. private void dumpBuffer(final boolean writePartial) {
  9. if ((currentBufferPosition < chunkSize) && !writePartial) {
  10. // Bail out, chunk not complete yet
  11. return;
  12. }
  13. if (currentBufferPosition == 0) {
  14. // chunk is empty, may be last chunk
  15. return;
  16. }
  17. byte[] writeBuffer = buffer;
  18. if (currentBufferPosition != chunkSize) {
  19. writeBuffer = new byte[currentBufferPosition];
  20. System.arraycopy(buffer, 0, writeBuffer, 0, currentBufferPosition);
  21. }
  22. DBObject chunk = createChunk(id, currentChunkNumber, writeBuffer);
  23. fs.getChunksCollection().save(chunk);
  24. currentChunkNumber++;
  25. totalBytes += writeBuffer.length;
  26. messageDigester.update(writeBuffer);
  27. currentBufferPosition = 0;
  28. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. private byte[] getChunk(final int chunkNumber) {
  2. if (fs == null) {
  3. throw new IllegalStateException("No GridFS instance defined!");
  4. }
  5. DBObject chunk = fs.getChunksCollection().findOne(new BasicDBObject("files_id", id).append("n", chunkNumber));
  6. if (chunk == null) {
  7. throw new MongoException("Can't find a chunk! file id: " + id + " chunk: " + chunkNumber);
  8. }
  9. return (byte[]) chunk.get("data");
  10. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Removes file from GridFS i.e. removes documents from files and chunks collections.
  3. */
  4. void remove() {
  5. fs.getFilesCollection().remove(new BasicDBObject("_id", id));
  6. fs.getChunksCollection().remove(new BasicDBObject("files_id", id));
  7. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Dumps a new chunk into the chunks collection. Depending on the flag, also partial buffers (at the end) are going to be written
  3. * immediately.
  4. *
  5. * @param writePartial Write also partial buffers full.
  6. * @throws MongoException if there's a failure
  7. */
  8. private void dumpBuffer(final boolean writePartial) {
  9. if ((currentBufferPosition < chunkSize) && !writePartial) {
  10. // Bail out, chunk not complete yet
  11. return;
  12. }
  13. if (currentBufferPosition == 0) {
  14. // chunk is empty, may be last chunk
  15. return;
  16. }
  17. byte[] writeBuffer = buffer;
  18. if (currentBufferPosition != chunkSize) {
  19. writeBuffer = new byte[currentBufferPosition];
  20. System.arraycopy(buffer, 0, writeBuffer, 0, currentBufferPosition);
  21. }
  22. DBObject chunk = createChunk(id, currentChunkNumber, writeBuffer);
  23. fs.getChunksCollection().save(chunk);
  24. currentChunkNumber++;
  25. totalBytes += writeBuffer.length;
  26. messageDigester.update(writeBuffer);
  27. currentBufferPosition = 0;
  28. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. private byte[] getChunk(final int chunkNumber) {
  2. if (fs == null) {
  3. throw new IllegalStateException("No GridFS instance defined!");
  4. }
  5. DBObject chunk = fs.getChunksCollection().findOne(new BasicDBObject("files_id", id).append("n", chunkNumber));
  6. if (chunk == null) {
  7. throw new MongoException("Can't find a chunk! file id: " + id + " chunk: " + chunkNumber);
  8. }
  9. return (byte[]) chunk.get("data");
  10. }

相关文章