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));
            }
        }
        /// <summary>
        /// Create a SegmentedContent object to use the given segmentStream to
        /// assemble content. You should use getNamespace().addOnContentSet to add
        /// the callback which is called when the content is complete. Then you
        /// should call start().
        /// </summary>
        /// <param name="segmentStream">The SegmentStream where the Namespace is a
        /// node whose children are the names of segment Data packets.</param>
        public SegmentedContent(SegmentStream segmentStream)
        {
            segmentStream_ = segmentStream;

            segmentStream_.addOnSegment(onSegment);
        }