コード例 #1
0
ファイル: SqlObject.cs プロジェクト: svn2github/hsqldb
        /// <summary>
        /// Deserializes the specified array of octets.
        /// </summary>
        /// <remarks>
        /// If the given <c>value</c> starts with the
        /// <see cref="SerializationHeader"/>, then the value is deserialized
        /// using a .NET <c>BinaryFomatter</c>; otherwise, it is deserialized
        /// using a <c>java.io.ObjectInputStream</c>.
        /// </remarks>
        /// <param name="value">
        /// The array of octets to deserialize.
        /// </param>
        /// <param name="isJavaObject">
        /// <c>true</c> when the given <c>value</c> is the <em>serialed
        /// form</em> of a <c>java.lang.Object</c>; <c>false</c> when the
        /// given value is the <em>serialized form</em> of a
        /// <c>System.Object</c>.
        /// </param>
        /// <returns>
        /// The object graph obtained by deserializing the given array of
        /// octets.
        /// </returns>
        public static object Deserialize(byte[] value, out bool isJavaObject)
        {
            bool   hasHeader = StartsWithSerializationHeader(value);
            object obj;

            if (hasHeader)
            {
                isJavaObject = false;
                BinaryFormatter formatter = new BinaryFormatter();

                using (MemoryStream stream
                           = new MemoryStream(value, 16, value.Length - 16))
                {
                    obj = formatter.Deserialize(stream);
                }
            }
            else
            {
                isJavaObject = true;

                Serializable serializable = org.hsqldb.lib.InOutUtil.deserialize(value);

                obj = serializable.ToObject();
            }

            return(obj);
        }
コード例 #2
0
ファイル: SqlObject.cs プロジェクト: svn2github/hsqldb
        /// <summary>
        /// Serializes the specified value.
        /// </summary>
        /// <remarks>
        /// If the given value is <c>java.io.Serializable</c>, then it is
        /// serialed using a <c>java.io.ObjectOutputStream</c>; otherwise, it
        /// is serialized using a .NET <c>BinaryFormatter</c> and the
        /// resulting array of octets starts with the
        /// <see cref="SerializationHeader"/>.
        /// </remarks>
        /// <param name="value">The value to serialize.</param>
        /// <returns>The serialized form of the value.</returns>
        public static byte[] Serialize(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            bool isArray            = value.GetType().IsArray;
            int  rank               = (isArray ? ((Array)value).Rank : 0);
            bool isJavaSerializable = (isArray)
                ? Serializable.IsInstanceArray(value, rank)
                : Serializable.IsInstance(value);

            byte[] bytes;

            if (isJavaSerializable)
            {
                bytes = org.hsqldb.lib.InOutUtil.serialize(Serializable.Cast(value));
            }
            else
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    stream.Write(s_headerBytes, 0, s_headerBytes.Length);
                    formatter.Serialize(stream, value);

                    bytes = stream.ToArray();
                }
            }

            return(bytes);
        }
コード例 #3
0
            public static SqlObject ToOther(Serializable serValue)
            {
                object value = serValue.ToObject();

                return (value == null) ? null : new SqlObject(value);
            }
コード例 #4
0
ファイル: Parcel.cs プロジェクト: zhouweiaccp/XobotOS
 public void writeSerializable(java.io.Serializable s)
 {
     throw new System.NotImplementedException();
 }