/// <summary> Returns an array of bytes for the first (or only) field that has the name /// specified as the method parameter. This method will return <code>null</code> /// if no binary fields with the specified name are available. /// There may be non-binary fields with the same name. /// /// </summary> /// <param name="name">the name of the field. /// </param> /// <returns> a <code>byte[]</code> containing the binary field value. /// </returns> public byte[] GetBinaryValue(System.String name) { for (int i = 0; i < fields.Count; i++) { Field field = (Field)fields[i]; if (field.Name().Equals(name) && (field.IsBinary())) { return(field.BinaryValue()); } } return(null); }
/// <summary> Returns an array of byte arrays for of the fields that have the name specified /// as the method parameter. This method will return <code>null</code> if no /// binary fields with the specified name are available. /// /// </summary> /// <param name="name">the name of the field /// </param> /// <returns> a <code>byte[][]</code> of binary field values. /// </returns> public byte[][] GetBinaryValues(System.String name) { System.Collections.IList result = new System.Collections.ArrayList(); for (int i = 0; i < fields.Count; i++) { Field field = (Field)fields[i]; if (field.Name().Equals(name) && (field.IsBinary())) { byte[] byteArray = field.BinaryValue(); byte[] resultByteArray = new byte[byteArray.Length]; for (int index = 0; index < byteArray.Length; index++) { resultByteArray[index] = (byte)byteArray[index]; } result.Add(resultByteArray); } } if (result.Count == 0) { return(null); } System.Collections.ICollection c = result; System.Object[] objects = new byte[result.Count][]; System.Type type = objects.GetType().GetElementType(); System.Object[] objs = (System.Object[])Array.CreateInstance(type, c.Count); System.Collections.IEnumerator e = c.GetEnumerator(); int ii = 0; while (e.MoveNext()) { objs[ii++] = e.Current; } // If objects is smaller than c then do not return the new array in the parameter if (objects.Length >= c.Count) { objs.CopyTo(objects, 0); } return((byte[][])objs); }
public virtual void TestBinaryField() { Document doc = new Document(); Fieldable stringFld = new Field("string", binaryVal, Field.Store.YES, Field.Index.NO); Fieldable binaryFld = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal), Field.Store.YES); Fieldable binaryFld2 = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal2), Field.Store.YES); doc.Add(stringFld); doc.Add(binaryFld); Assert.AreEqual(2, doc.fields_ForNUnit.Count); Assert.IsTrue(binaryFld.IsBinary()); Assert.IsTrue(binaryFld.IsStored()); Assert.IsFalse(binaryFld.IsIndexed()); Assert.IsFalse(binaryFld.IsTokenized()); System.String binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(doc.GetBinaryValue("binary"))); Assert.IsTrue(binaryTest.Equals(binaryVal)); System.String stringTest = doc.Get("string"); Assert.IsTrue(binaryTest.Equals(stringTest)); doc.Add(binaryFld2); Assert.AreEqual(3, doc.fields_ForNUnit.Count); byte[][] binaryTests = doc.GetBinaryValues("binary"); Assert.AreEqual(2, binaryTests.Length); binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[0])); System.String binaryTest2 = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[1])); Assert.IsFalse(binaryTest.Equals(binaryTest2)); Assert.IsTrue(binaryTest.Equals(binaryVal)); Assert.IsTrue(binaryTest2.Equals(binaryVal2)); doc.RemoveField("string"); Assert.AreEqual(2, doc.fields_ForNUnit.Count); doc.RemoveFields("binary"); Assert.AreEqual(0, doc.fields_ForNUnit.Count); }
public virtual void TestBinaryField() { Document doc = new Document(); Fieldable stringFld = new Field("string", binaryVal, Field.Store.YES, Field.Index.NO); Fieldable binaryFld = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal), Field.Store.YES); Fieldable binaryFld2 = new Field("binary", System.Text.UTF8Encoding.UTF8.GetBytes(binaryVal2), Field.Store.YES); doc.Add(stringFld); doc.Add(binaryFld); Assert.AreEqual(2, doc.fields_ForNUnit.Count); Assert.IsTrue(binaryFld.IsBinary()); Assert.IsTrue(binaryFld.IsStored()); Assert.IsFalse(binaryFld.IsIndexed()); Assert.IsFalse(binaryFld.IsTokenized()); System.String binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(doc.GetBinaryValue("binary"))); Assert.IsTrue(binaryTest.Equals(binaryVal)); System.String stringTest = doc.Get("string"); Assert.IsTrue(binaryTest.Equals(stringTest)); doc.Add(binaryFld2); Assert.AreEqual(3, doc.fields_ForNUnit.Count); byte[][] binaryTests = doc.GetBinaryValues("binary"); Assert.AreEqual(2, binaryTests.Length); binaryTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[0])); System.String binaryTest2 = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(binaryTests[1])); Assert.IsFalse(binaryTest.Equals(binaryTest2)); Assert.IsTrue(binaryTest.Equals(binaryVal)); Assert.IsTrue(binaryTest2.Equals(binaryVal2)); doc.RemoveField("string"); Assert.AreEqual(2, doc.fields_ForNUnit.Count); doc.RemoveFields("binary"); Assert.AreEqual(0, doc.fields_ForNUnit.Count); }
/// <summary> Returns an array of values of the field specified as the method parameter. /// This method can return <code>null</code>. /// /// </summary> /// <param name="name">the name of the field /// </param> /// <returns> a <code>String[]</code> of field values /// </returns> public System.String[] GetValues(System.String name) { System.Collections.ArrayList result = new System.Collections.ArrayList(); for (int i = 0; i < fields.Count; i++) { Field field = (Field)fields[i]; if (field.Name().Equals(name) && (!field.IsBinary())) { result.Add(field.StringValue()); } } if (result.Count == 0) { return(null); } return((System.String[])(result.ToArray(typeof(System.String)))); }
private static KeyValuePair<string, RavenJToken> CreateProperty(Field fld, Document document) { if(fld.IsBinary()) return new KeyValuePair<string, RavenJToken>(fld.Name(), fld.GetBinaryValue()); var stringValue = fld.StringValue(); if (document.GetField(fld.Name() + "_ConvertToJson") != null) { var val = RavenJToken.Parse(fld.StringValue()) as RavenJObject; return new KeyValuePair<string, RavenJToken>(fld.Name(), val); } if (stringValue == Constants.NullValue) stringValue = null; if (stringValue == Constants.EmptyString) stringValue = string.Empty; return new KeyValuePair<string, RavenJToken>(fld.Name(), stringValue); }