onContentSet (Namespace nameSpace, Namespace contentNamespace, long callbackId) { if (contentNamespace.getName().size() == namespace_.getName().size() + 2 && contentNamespace.getName()[-2].equals(fileMarker_)) { var version = contentNamespace.getName()[-1]; if (version.isVersion()) { // Got the file marker for the version such as // <namespace>/%C1.FS.file/<version>. Fetch the segmented content. var segmentedContent = new SegmentedContent(namespace_[version]); segmentedContent.start(); } } else if (contentNamespace.getName().size() == namespace_.getName().size() + 1 && contentNamespace.getName()[-1].isVersion()) { // We got the assembled content from the SegmentedContent handler. if (onVersionContentSet_ != null) { onVersionContentSet_(this, contentNamespace, (Blob)contentNamespace.getContent()); } } }
onSegment (SegmentStream segmentStream, Namespace segmentNamespace, long callbackId) { if (finished_) { // We already finished and called onContent. (We don't expect this.) return; } if (segmentNamespace != null) { segments_.Add((Blob)segmentNamespace.getContent()); totalSize_ += ((Blob)segmentNamespace.getContent()).size(); } else { // Finished. We don't need the callback anymore. segmentStream.removeCallback(callbackId); // Concatenate the segments. var content = ByteBuffer.wrap(new byte[totalSize_]); for (var i = 0; i < segments_.Count; ++i) { content.put(segments_[i].buf()); // Free the memory. segments_[i] = new Blob(); } content.flip(); // Free memory. segments_.Clear(); finished_ = true; // Debug: Fix this hack. How can we attach content to a namespace // node which has no associated Data packet? Who is authorized to do so? segmentStream_.getNamespace().debugOnContentTransformed (null, new Blob(content, false)); } }