{"id":2120,"date":"2016-01-13T17:12:16","date_gmt":"2016-01-13T17:12:16","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2120"},"modified":"2016-01-13T17:12:16","modified_gmt":"2016-01-13T17:12:16","slug":"storing-blobs-in-couchbase-for-content-management","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/","title":{"rendered":"Storing Blobs in Couchbase for Content Management"},"content":{"rendered":"<p><em style=\"line-height: normal; text-align: left;\">This blog was originally posted on Cecile Le Pape&apos;s personal blog. To see to original blog post, click\u00a0<a href=\"https:\/\/cecilelepape.blogspot.fr\/2016\/01\/storing-blobs-in-couchbase-for-content.html\">here<\/a>.\u00a0<\/em><\/p>\n<p>\u00a0<\/p>\n<p>In my <a href=\"https:\/\/cecilelepape.blogspot.fr\/2015\/09\/flexible-and-scalable-content.html\">previous post<\/a>, I talked about how to setup a flexible content management service using Couchbase as the metadata repository, on top of an Apache Chemistry server. The blobs themselves (pdf, pptx, docx, etc) are stored in a separate file system or in a blob store. Today, I would like to show how Couchbase can be used to store the blobs themselves, using a custom chunk manager. The idea is to store not only the metadata of a document (date of creation, creator, name, etc.) but in addition the blob itself.<\/p>\n<p>The purpose of this new architecture is to reduce the number of different systems (and licences to pay) and also to benefit directly from the replication features offered by Couchbase.<\/p>\n<p>First, let\u2019s remember that Couchbase is not a blob store. This a memory-based document store, with an adhoc cache management tuned so that most of the data stored in Couchbase should be in RAM for fast querying. Data are also replicated between nodes (if replication is enabled) inside the cluster and optionnaly outside the cluster if XDCR is used. This is why data stored in Couchbase can not be larger than 20 MB. This is a hard limit, and in real life 1MB is already a large document to store.<\/p>\n<p>Knowing that, the point is: how can I store large binary data in Couchbase ? Simple answer: chunk it!<\/p>\n<p>The new architecture looks now like this:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/january\/storing-blobs-in-couchbase-for-content-management\/cecileblog1.png\" \/><\/p>\n<p>There is now 2 buckets in Couchbase:<\/p>\n<ol>\n<li><em>cmismeta<\/em> : used to store metadata<\/li>\n<li><em>cmisstore<\/em> : used to store blobs<\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<p>When a folder is created, only the bucket cmismeta is modified with a new entry because of course, a folder is not associated to any blob. This is simply a structure used by the user to organise the documents and navigate in the folder tree. Folders are virtuals. The entry point of the structure is the root folder as described <a href=\"https:\/\/cecilelepape.blogspot.fr\/2015\/09\/flexible-and-scalable-content.html\">previously<\/a>.<\/p>\n<p>When a document (for instance a pdf or a pptx) is inserted into a folder, 3 things happen:<\/p>\n<ul>\n<li>A json document containing all its metadata is inserted into the cmismeta bucket, with a unique key. Let\u2019s say for instance that the document has the key <span style=\"color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal; text-align: left;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=<\/span>.<\/li>\n<li>A new json document with the same key is created in the cmisstore bucket. This document contains the number of chunk, the max size of each chunk (same for all chunk except for the last one that might be smaller) and the application mime type.<\/li>\n<li>The blob attached to the document is chunked into binary pieces (the size depends on a parameter you can set in the properties of the project). By default, a chunk is 500KB large. Each chunk is stored in the cmisstore bucket as a binary document, with the same key \u201c<span style=\"color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal; text-align: left;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=<\/span>\u201d as prefix, and a suffix &#8220;::partxxx\u201d where xxx is the number of the chunk (0, 1, 2, \u2026).<\/li>\n<\/ul>\n<p>For instance, if a insert a pptx called CouchbaseOverview.pptx which size is 4476932 bytes into Couchbase, I get:<\/p>\n<ul>\n<li>In bucket cmismeta, a json document called\u00a0<span style=\"color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal; text-align: left;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><span style=\"color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal; text-align: left;\"><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/january\/storing-blobs-in-couchbase-for-content-management\/cecileblog2.png\" \/><\/span><\/p>\n<ul>\n<li>In bucket cmisstore, a json document also called<span style=\"color: rgb(51, 51, 51); line-height: 20.8px; text-align: left;\">\u00a0<\/span><span style=\"text-align: left; color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><span style=\"text-align: left; color: rgb(68, 68, 68); font-family: Menlo; font-size: 11px; line-height: normal;\">\u200b<\/span>\u00a0\u00a0<img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/january\/storing-blobs-in-couchbase-for-content-management\/cecileblog3.png\" \/><\/p>\n<ul>\n<li style=\"padding-top: 0.25em; padding-bottom: 0.25em; margin-bottom: 0.25em; border: none;\">\n<p>9 chunks containing binary data and called<span style=\"font-family: Menlo; font-size: 11px; line-height: normal;\"><span style=\"font-family: -webkit-standard; font-size: 14px; text-align: center;\">\u00a0<\/span><span style=\"text-align: center;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=::part0,\u00a0<\/span><span style=\"text-align: center;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=::part1, \u2026 ,\u00a0<\/span><span style=\"text-align: center;\">L0NvdWNoYmFzZU92ZXJ2aWV3LnBwdHg=::part8<\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 0.25em; padding-bottom: 0.25em; margin-bottom: 0.25em; border: none; text-align: center;\"><span style=\"font-family: Menlo; font-size: 11px; line-height: normal;\"><span style=\"text-align: center;\">\u200b<img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/january\/storing-blobs-in-couchbase-for-content-management\/cecileblog4.png\" \/><\/span><\/span><\/p>\n<p style=\"padding-top: 0.25em; padding-bottom: 0.25em; margin-bottom: 0.25em; border: none;\">\u00a0<\/p>\n<p>The CouchbaseStorageService is the class implementing the StorageService interface already used for local storage or S3 storage as I showed into <a href=\"https:\/\/cecilelepape.blogspot.fr\/2015\/09\/flexible-and-scalable-content.html\">my previous blog<\/a>. The first difference is the reuse of the same CouchbaseCluster instance as the one used for the MetadataService because only one Couchbase Environnement should be instantiated to save lots of resources (RAM, CPU, Network, etc).<\/p>\n<p>Now let\u2019s see the writeContent method itself:<\/p>\n<p>\u00a0<\/p>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(79, 118, 203); font-family: Monaco; font-size: 11px; line-height: normal;\">\/**<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(79, 118, 203); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0* ContentStream is split into parts<\/span><br \/>\n<span style=\"color: rgb(79, 118, 203); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0*\/<\/span><br \/>\n<span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">public<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">void<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0writeContent(String\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">, ContentStream\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">contentStream<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">)<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">throws<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException {<\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(78, 144, 114); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ count the number of parts<\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 long<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">contentStream<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.getLength();<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 long<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0\/\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">BUFFER_SIZE<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(78, 144, 114); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ the last part<\/span>\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 if<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0&#8211;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0*\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">BUFFER_SIZE<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">\u00a0> 0)<\/span><\/span>\u00a0\u00a0<span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">++;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 JsonObject\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">doc<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">\u00a0= JsonObject.empty();<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.put(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;count&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.put(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;mimetype&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">contentStream<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.getMimeType());<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.put(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;length&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(147, 26, 104); line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 long<\/span><span style=\"line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">totalLength<\/span>\u00a0= 0;\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 int<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">read<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0= 0;\u00a0<\/span><span style=\"color: rgb(78, 144, 114); font-family: Monaco; font-size: 11px; line-height: normal;\">\/\/ The number of bytes not yet read<\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 byte<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[]\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">byteArray<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">new<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">byte<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">BUFFER_SIZE<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">];<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 int<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">offset<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">\u00a0= 0;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 for<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0(<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">int<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0= 0;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">++) {<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">\u00a0{<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 read<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">contentStream<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.getStream()<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.read(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">byteArray<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">, 0,\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">BUFFER_SIZE<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span>\u00a0\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span>\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 totalLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">read<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">offset<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">read<\/span><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">;\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 writeContentPart(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">PART_SUFFIX<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">byteArray<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">read<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.put(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">PART_SUFFIX<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">read<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">catch<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0(IOException\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">e<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">) {<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0e<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.printStackTrace();<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span>\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 if<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">totalLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0!=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">)<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0throw<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">new<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;Wrong number of bytes&#8221;<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span><br \/>\n<span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0JsonDocument\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">jsondoc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0= JsonDocument.create(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">doc<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0bucket<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.upsert(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">jsondoc<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(147, 26, 104); line-height: normal;\">\u00a0\u00a0\u00a0\u00a0\u00a0private<\/span><span style=\"line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">void<\/span><span style=\"line-height: normal;\">\u00a0writeContentPart(String\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">partId<\/span><span style=\"line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">byte<\/span><span style=\"line-height: normal;\">[]\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">bytesArray<\/span><span style=\"line-height: normal;\">,\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">int<\/span><span style=\"line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">length<\/span>)\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0throws<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException {<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">BinaryDocument\u00a0<span style=\"color: rgb(126, 80, 79); line-height: normal;\">bDoc<\/span><span style=\"line-height: normal;\">\u00a0= BinaryDocument.create(<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">partId<\/span>,\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0Unpooled.copiedBuffer(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">bytesArray<\/span><span style=\"line-height: normal;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">));<\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\"><span style=\"color: rgb(3, 38, 204); line-height: normal;\">bucket<\/span><span style=\"line-height: normal;\">.upsert(<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">bDoc<\/span><span style=\"line-height: normal;\">);<\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/span>\u00a0<\/div>\n<p>\u00a0<\/p>\n<p>Now what to do to retrieve the file from Couchbase ? The main idea is to get each part, concatenate each other is the same order they were cut and send the byte array to the stream. There is probably a lot of way to do this, I simply implement a straightforward one using a single byte array where I write each byte into.<\/p>\n<p>\u00a0<\/p>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">private<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0InputStream getInputStream(String\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">, StringBuffer\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">mimeType<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">)<\/span><br \/>\n<span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">throws<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException {<br \/>\nJsonDocument\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">bucket<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.get(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">);<br \/>\nJsonObject\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">json<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">doc<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.content();<br \/>\nInteger\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">json<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.getInt(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;count&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">);<br \/>\nInteger\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">json<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.getInt(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;length&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">);<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0<\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0if<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">nbparts<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">==<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">null<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0||\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">==<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">null<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0||\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">mimeType<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">==<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">null<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">)\u00a0<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0throw<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">new<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;Document invalid&#8221;<\/span><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">);<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0mimeType<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.append(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">json<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.getString(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;mimetype&#8221;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">));<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0byte<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[]\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">byteArray<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">new<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">byte<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">length<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">];<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(78, 144, 114); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\/\/ for each part, read the content into the byteArray<\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0int<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">offset<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">\u00a0= 0;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0Integer\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">partLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">null<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(147, 26, 104); line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(147, 26, 104); line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0for<\/span><span style=\"line-height: normal;\">\u00a0(<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">int<\/span><span style=\"line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">i<\/span><span style=\"line-height: normal;\">\u00a0= 0;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">i<\/span><span style=\"line-height: normal;\">\u00a0<\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">nbparts<\/span><span style=\"line-height: normal;\">;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">i<\/span>++) {\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span>\u00a0<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0partLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">json<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.getInt(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dataId<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(3, 38, 204); font-family: Monaco; font-size: 11px; line-height: normal;\">PART_SUFFIX<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">);\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0if<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">partLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0==\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">null<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">)\u00a0<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0throw\u00a0<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">new<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0StorageException(<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8220;length of part &#8220;<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">+<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">i<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">+<\/span><span style=\"color: rgb(57, 51, 255); font-family: Monaco; font-size: 11px; line-height: normal;\">&#8221; is mandatory&#8221;<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0BinaryDocument\u00a0<span style=\"color: rgb(126, 80, 79); line-height: normal;\">bDoc<\/span><span style=\"line-height: normal;\">\u00a0=\u00a0<\/span><\/span><\/span><br \/>\n<span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(3, 38, 204); line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 bucket<\/span><span style=\"line-height: normal;\">.get(<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">dataId<\/span><span style=\"line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(3, 38, 204); line-height: normal;\">PART_SUFFIX<\/span><span style=\"line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">i<\/span>,<\/span><\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">BinaryDocument.<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">class<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0ByteBuf\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">part<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">bDoc<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.content();<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\"><span style=\"color: rgb(147, 26, 104); line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0byte<\/span><span style=\"line-height: normal;\">[]\u00a0<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">dst<\/span><span style=\"line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">new<\/span><span style=\"line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">byte<\/span><span style=\"line-height: normal;\">[<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">partLength<\/span>];\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0part<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">.readBytes(<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dst<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">);<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0for<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0(<\/span><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">int<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">k<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0= 0;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">k<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">partLength<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">;\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">k<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">++) {<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0byteArray<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">k<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">offset<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">] =\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">dst<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">[<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">k<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">];<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0}\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0offset<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0+=\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">partLength<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">;<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0part<\/span><span style=\"font-family: Monaco;\"><span style=\"font-size: 11px;\">.release();<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0InputStream\u00a0<span style=\"color: rgb(126, 80, 79); line-height: normal;\">stream<\/span><span style=\"line-height: normal;\">\u00a0=\u00a0<\/span><span style=\"color: rgb(147, 26, 104); line-height: normal;\">new<\/span><span style=\"line-height: normal;\">\u00a0ByteArrayInputStream(<\/span><span style=\"color: rgb(126, 80, 79); line-height: normal;\">byteArray<\/span>);\u00a0<span style=\"white-space: pre;\"> <\/span>\u00a0<\/span><\/span>\u00a0<span style=\"white-space: pre;\"> <\/span><span style=\"white-space: pre;\"> <\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"color: rgb(147, 26, 104); font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0return<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">\u00a0<\/span><span style=\"color: rgb(126, 80, 79); font-family: Monaco; font-size: 11px; line-height: normal;\">stream<\/span><span style=\"font-family: Monaco; font-size: 11px; line-height: normal;\">;<\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\"><span style=\"font-size: 11px;\"><span style=\"font-family: Monaco;\">}<\/span><\/span><\/div>\n<div style=\"color: rgb(68, 68, 68); font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; text-align: start; font-size: 14px;\">\u00a0<\/div>\n<p>Finally let\u2019s see what happens in the workbench tool provided by Apache Chemistry ? I can see the document in the root folder and if I double click on it, the content is streamed from Couchbase and displayed in the associated viewer (here powerpoint) based on the mime type.\u00a0<\/p>\n<p>\u00a0<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/wp-content\/original-assets\/2016\/january\/storing-blobs-in-couchbase-for-content-management\/cecileblog5.png\" \/><\/p>\n<p style=\"text-align: center;\"><em>Workbench and document opened in powerpoint after double click\u00a0<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog was originally posted on Cecile Le Pape&apos;s personal blog. To see to original blog post, click\u00a0here.\u00a0 \u00a0 In my previous post, I talked about how to setup a flexible content management service using Couchbase as the metadata repository, [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815],"tags":[],"ppma_author":[9040],"class_list":["post-2120","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Storing Blobs in Couchbase for Content Management - The Couchbase Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Storing Blobs in Couchbase for Content Management\" \/>\n<meta property=\"og:description\" content=\"This blog was originally posted on Cecile Le Pape&amp;apos;s personal blog. To see to original blog post, click\u00a0here.\u00a0 \u00a0 In my previous post, I talked about how to setup a flexible content management service using Couchbase as the metadata repository, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-13T17:12:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Cecile Le Pape, Solutions Architect, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cecile Le Pape, Solutions Architect, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\"},\"author\":{\"name\":\"Cecile Le Pape, Solutions Architect, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/28d00738232281d64e4a632c5acc69b1\"},\"headline\":\"Storing Blobs in Couchbase for Content Management\",\"datePublished\":\"2016-01-13T17:12:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\"},\"wordCount\":717,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Best Practices and Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\",\"name\":\"Storing Blobs in Couchbase for Content Management - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2016-01-13T17:12:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Storing Blobs in Couchbase for Content Management\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/28d00738232281d64e4a632c5acc69b1\",\"name\":\"Cecile Le Pape, Solutions Architect, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/97438b032f142721b48bf7eae0f50bcd\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6c0a378c3c8e07dce943defd33929845a490ea466c6fddbb9ee24a71bdc8aa6c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6c0a378c3c8e07dce943defd33929845a490ea466c6fddbb9ee24a71bdc8aa6c?s=96&d=mm&r=g\",\"caption\":\"Cecile Le Pape, Solutions Architect, Couchbase\"},\"description\":\"After 10 years at University of Paris 6 (France) where she worked in the database team on replication, consistency, XML, p2p, syndication and mobile projects, Cecile decided to move on and start a new life experience in industry. Cecile joined the architect team of a small company called Oceane Consulting to develop document management projects. She is now a Solutions Architect at Couchbase and very happy to be involved both on the technical field and sales.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/cecile-le-pape\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Storing Blobs in Couchbase for Content Management - The Couchbase Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/","og_locale":"en_US","og_type":"article","og_title":"Storing Blobs in Couchbase for Content Management","og_description":"This blog was originally posted on Cecile Le Pape&apos;s personal blog. To see to original blog post, click\u00a0here.\u00a0 \u00a0 In my previous post, I talked about how to setup a flexible content management service using Couchbase as the metadata repository, [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/","og_site_name":"The Couchbase Blog","article_published_time":"2016-01-13T17:12:16+00:00","og_image":[{"width":1800,"height":630,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png","type":"image\/png"}],"author":"Cecile Le Pape, Solutions Architect, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Cecile Le Pape, Solutions Architect, Couchbase","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/"},"author":{"name":"Cecile Le Pape, Solutions Architect, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/28d00738232281d64e4a632c5acc69b1"},"headline":"Storing Blobs in Couchbase for Content Management","datePublished":"2016-01-13T17:12:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/"},"wordCount":717,"commentCount":1,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Best Practices and Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/","url":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/","name":"Storing Blobs in Couchbase for Content Management - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2016-01-13T17:12:16+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/storing-blobs-in-couchbase-for-content-management\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Storing Blobs in Couchbase for Content Management"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/28d00738232281d64e4a632c5acc69b1","name":"Cecile Le Pape, Solutions Architect, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/97438b032f142721b48bf7eae0f50bcd","url":"https:\/\/secure.gravatar.com\/avatar\/6c0a378c3c8e07dce943defd33929845a490ea466c6fddbb9ee24a71bdc8aa6c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6c0a378c3c8e07dce943defd33929845a490ea466c6fddbb9ee24a71bdc8aa6c?s=96&d=mm&r=g","caption":"Cecile Le Pape, Solutions Architect, Couchbase"},"description":"After 10 years at University of Paris 6 (France) where she worked in the database team on replication, consistency, XML, p2p, syndication and mobile projects, Cecile decided to move on and start a new life experience in industry. Cecile joined the architect team of a small company called Oceane Consulting to develop document management projects. She is now a Solutions Architect at Couchbase and very happy to be involved both on the technical field and sales.","url":"https:\/\/www.couchbase.com\/blog\/author\/cecile-le-pape\/"}]}},"authors":[{"term_id":9040,"user_id":68,"is_guest":0,"slug":"cecile-le-pape","display_name":"Cecile Le Pape, Solutions Architect, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/6c0a378c3c8e07dce943defd33929845a490ea466c6fddbb9ee24a71bdc8aa6c?s=96&d=mm&r=g","author_category":"","last_name":"Le Pape","first_name":"Cecile","job_title":"","user_url":"","description":"After 10 years at University of Paris 6 (France) where she worked in the database team on replication, consistency, XML, p2p, syndication and mobile projects, Cecile decided to move on and start a new life experience in industry. Cecile joined the architect team of a small company called Oceane Consulting to develop document management projects. She is now a Solutions Architect at Couchbase and very happy to be involved both on the technical field and sales."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=2120"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/2120\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=2120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=2120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=2120"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=2120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}