public static RiakObject Load(Bucket bucket, string keyName, Document part) { RiakObject ro = new RiakObject { Bucket = bucket, KeyName = keyName }; ro.LoadDocumentHeaders(part); ro._cachedData = part.Content; return ro; }
protected static Document Load(Stream stream, Dictionary<string,string> headers, Document parent) { // if the header indicated a content length then respect that otherwise // read everything left over. long contentLength = headers.ContainsKey(HttpWellKnownHeader.ContentLength) ? long.Parse(headers[HttpWellKnownHeader.ContentLength]) : Math.Max(0, stream.Length - stream.Position); byte[] content = new byte[contentLength]; Util.CopyStream(stream, content); Document doc = Util.IsMultiPart(headers[HttpWellKnownHeader.ContentType]) ? new MultiPartDocument(headers, content, parent) : new Document(headers, content, parent); return doc; }
public MultiPartDocument(Dictionary<string,string> headers, byte[] content, Document parent) : base(headers, content, parent) { _content = content; _boundary = LoadBoundary(); _boundaryBytes = Encoding.GetEncoding(28591).GetBytes(BoundaryPrefix + _boundary); LoadParts(); }
protected Document(Dictionary<string,string> headers, byte[] content, Document parent) { Headers = headers; Content = content; Parent = parent; }
protected static Document Load(Stream stream, Document parent) { Dictionary<string, string> headers = LoadHeadersFromStream(stream); return Load(stream, headers, parent); }
protected virtual void LoadDocumentHeaders(Document document) { MultiPartDocument mpParent = document.Parent as MultiPartDocument; HasSiblings = (mpParent != null && mpParent.Parts.Count > 1); VClock = document.GetLocalOrParentHeader(HttpWellKnownHeader.RiakVClock); ContentType = document.Headers[HttpWellKnownHeader.ContentType]; ETag = document.Headers[HttpWellKnownHeader.ETag]; if (document.Headers.ContainsKey(HttpWellKnownHeader.LastModified)) { LastModified = DateTime.Parse(document.Headers[HttpWellKnownHeader.LastModified]); } ContentLength = document.Content.Length; Links = LinkCollection.Create(document.Headers[HttpWellKnownHeader.Link]); }
private static void CheckData(Document document, string expectedString) { byte[] expected = Encoding.GetEncoding(28591).GetBytes(expectedString); Assert.AreEqual(expected.Length, document.Content.Length); for(int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], document.Content[i]); } }