Example #1
0
 /// <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);
 }
Example #2
0
        /// <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);
        }