private void updateContents(DBObject metaData, byte[] contents, int offset,
int len) throws IOException {
Object fileId = metaData.get("_id");
ContentPointer oldContents = getContentPointer(metaData);
String filename = (String) metaData.get("filename");
String contentType = (String) metaData.get("contentType");
// for up to 55 bytes, storing the complete file inline
// takes less space than just storing the SHA-1 and length
// 20 (SHA-1) + 1 (sha - in) + 6 (length) + 4 (int32) + 2*12
// (ObjectId back-references)
BSONObject newContent = storage.inlineOrInsertContentsAndBackRefs(55,
contents, offset, len, fileId, filename, contentType);
// check if it has changed
ContentPointer newContents = getContentPointer(newContent);
if (newContents.contentEquals(oldContents))
return;
metaData.removeField("sha");
metaData.removeField("length");
metaData.removeField("in");