Exemple #1
0
 internal static void WriteInternal(
     byte[] @object,
     DataOutput output)
 {
     output.WriteInt(@object.Length);
     output.Write(@object);
 }
Exemple #2
0
 /// <summary>
 /// Writes a byte array.
 /// <p>
 /// The length is written as a <code>short</code>, followed
 /// by the bytes.
 /// </summary>
 public virtual void Write(byte[] bytes, int off, int len)
 {
     Debug.Assert(bytes != null);
     Debug.Assert(off >= 0 && off + len <= bytes.Length);
     Debug.Assert(len >= 0);
     Os.WriteShort((short)len);
     Os.Write(bytes, off, len);
 }
Exemple #3
0
 private static void WriteBytes(
     DataOutput output,
     ByteBuffer value)
 {
     var bytes = value.Array;
     output.WriteInt(bytes.Length);
     output.Write(bytes);
 }
Exemple #4
0
        /// <summary>
        /// Serialize object
        /// </summary>
        /// <param name="value">value to serialize</param>
        /// <param name="output">output stream</param>
        /// <throws>IOException when a problem occurs</throws>
        public static void SerializeTo(
            object value,
            DataOutput output)
        {
            var result = ObjectToByteArr(value);

            output.WriteInt(result.Length);
            output.Write(result);
        }
Exemple #5
0
 public void Write(
     object @object,
     DataOutput output,
     byte[] pageFullKey,
     EventBeanCollatedWriter writer)
 {
     byte[] objectBytes = ObjectToByteArr(@object);
     output.WriteInt(objectBytes.Length);
     output.Write(objectBytes);
 }
        private void WriteInternal(
            byte[] @object,
            DataOutput output)
        {
            if (@object == null)
            {
                output.WriteInt(-1);
                return;
            }

            output.WriteInt(@object.Length);
            output.Write(@object);
        }
Exemple #7
0
            /// <summary>
            /// Serialize
            /// <see cref="#created"/>
            ///
            /// </summary>
            /// <exception cref="System.IO.IOException"/>
            private void WriteCreated(DataOutput @out)
            {
                IList <INode> created = GetList(Diff.ListType.Created);

                @out.WriteInt(created.Count);
                foreach (INode node in created)
                {
                    // For INode in created list, we only need to record its local name
                    byte[] name = node.GetLocalNameBytes();
                    @out.WriteShort(name.Length);
                    @out.Write(name);
                }
            }
Exemple #8
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void Write(DataOutput @out)
            {
                if (0 == len)
                {
                    return;
                }
                int written = 0;

                if (!disableRead)
                {
                    WritableUtils.WriteVInt(@out, len);
                    written -= WritableUtils.GetVIntSize(len);
                }
                if (len > 1024)
                {
                    if (null == b || b.Length < len)
                    {
                        b = new byte[2 * len];
                    }
                    Arrays.Fill(b, fillChar);
                    do
                    {
                        int write = Math.Min(len - written, r.Next(len));
                        @out.Write(b, 0, write);
                        written += write;
                    }while (written < len);
                    NUnit.Framework.Assert.AreEqual(len, written);
                }
                else
                {
                    for (int i = written; i < len; ++i)
                    {
                        @out.Write(fillChar);
                    }
                }
            }
Exemple #9
0
        /// <summary>
        /// NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="bigInteger">value</param>
        /// <param name="stream">output</param>
        /// <throws>IOException io error</throws>
        public static void WriteBigInt(
            BigInteger bigInteger,
            DataOutput stream)
        {
            var byteArray = bigInteger.ToByteArray();

            if (byteArray.Length > Int16.MaxValue)
            {
                throw new ArgumentException("BigInteger byte array is larger than 0x7fff bytes");
            }

            var length = (short)byteArray.Length;

            stream.WriteShort(length);
            stream.Write(byteArray, 0, byteArray.Length);
        }
        private void WriteInternal(
            object[] @object,
            DataOutput output)
        {
            if (@object == null)
            {
                output.WriteInt(-1);
                return;
            }

            output.WriteInt(@object.Length);

            foreach (var obj in @object)
            {
                byte[] data = DIOSerializableObjectSerde.ObjectToByteArr(obj);
                output.WriteInt(data.Length);
                output.Write(data);
            }
        }
 /// <exception cref="System.IO.IOException"/>
 public override void Write(DataOutput @out)
 {
     @out.Write(proto.ToByteArray());
 }
 /// <exception cref="System.IO.IOException"/>
 public override void Write(DataOutput @out)
 {
     Log.Debug("Writing NMTokenIdentifier to RPC layer: " + this);
     @out.Write(proto.ToByteArray());
 }
Exemple #13
0
 /// <summary>Write to out</summary>
 /// <exception cref="System.IO.IOException"/>
 public void Write(DataOutput @out)
 {
     @out.Write(OP.code);
 }
Exemple #14
0
        /// <summary>
        ///     Writes a string to the specified DataOutput using
        ///     <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
        ///     encoding in a machine-independent manner.
        /// </summary>
        /// <remarks>
        ///     Writes a string to the specified DataOutput using
        ///     <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
        ///     encoding in a machine-independent manner.
        ///     <p>
        ///         First, two bytes are written to out as if by the <code>writeShort</code>
        ///         method giving the number of bytes to follow. This value is the number of
        ///         bytes actually written out, not the length of the string. Following the
        ///         length, each character of the string is output, in sequence, using the
        ///         modified UTF-8 encoding for the character. If no exception is thrown, the
        ///         counter <code>written</code> is incremented by the total number of
        ///         bytes written to the output stream. This will be at least two
        ///         plus the length of <code>str</code>, and at most two plus
        ///         thrice the length of <code>str</code>.
        /// </remarks>
        /// <param name="str">a string to be written.</param>
        /// <param name="out">destination to write to</param>
        /// <returns>The number of bytes written out.</returns>
        /// <exception>
        ///     IOException
        ///     if an I/O error occurs.
        /// </exception>
        /// <exception cref="System.IO.IOException" />
        internal static int WriteUTF(string str, DataOutput @out)
        {
            var strlen = str.Length;
            var utflen = 0;
            int c;
            var count = 0;

            /* use charAt instead of copying String to char array */
            for (var i = 0; i < strlen; i++)
            {
                c = str[i];
                if (c >= 0x0001 && c <= 0x007F)
                {
                    utflen++;
                }
                else if (c > 0x07FF)
                {
                    utflen += 3;
                }
                else
                {
                    utflen += 2;
                }
            }

            if (utflen > 65535)
            {
                throw new UTFDataFormatException("encoded string too long: " + utflen + " bytes");
            }
            byte[] bytearr = null;
            if (@out is DataOutputStream)
            {
                var dos = (DataOutputStream)@out;
                if (dos.bytearr == null || dos.bytearr.Length < utflen + 2)
                {
                    dos.bytearr = new byte[utflen * 2 + 2];
                }
                bytearr = dos.bytearr;
            }
            else
            {
                bytearr = new byte[utflen + 2];
            }

            bytearr[count++] = unchecked ((byte)((int)((uint)utflen >> 8) & 0xFF));
            bytearr[count++] = unchecked ((byte)((int)((uint)utflen >> 0) & 0xFF));
            var i_1 = 0;

            for (i_1 = 0; i_1 < strlen; i_1++)
            {
                c = str[i_1];
                if (!(c >= 0x0001 && c <= 0x007F))
                {
                    break;
                }
                bytearr[count++] = unchecked ((byte)c);
            }

            for (; i_1 < strlen; i_1++)
            {
                c = str[i_1];
                if (c >= 0x0001 && c <= 0x007F)
                {
                    bytearr[count++] = unchecked ((byte)c);
                }
                else if (c > 0x07FF)
                {
                    bytearr[count++] = unchecked ((byte)(0xE0 | ((c >> 12) & 0x0F)));
                    bytearr[count++] = unchecked ((byte)(0x80 | ((c >> 6) & 0x3F)));
                    bytearr[count++] = unchecked ((byte)(0x80 | ((c >> 0) & 0x3F)));
                }
                else
                {
                    bytearr[count++] = unchecked ((byte)(0xC0 | ((c >> 6) & 0x1F)));
                    bytearr[count++] = unchecked ((byte)(0x80 | ((c >> 0) & 0x3F)));
                }
            }

            @out.Write(bytearr, 0, utflen + 2);
            return(utflen + 2);
        }
Exemple #15
0
        /// <summary>
        /// Writes a string to the specified DataOutput using
        /// <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
        /// encoding in a machine-independent manner.
        /// <para>
        /// First, two bytes are written to out as if by the <code>writeShort</code>
        /// method giving the number of bytes to follow. This value is the number of
        /// bytes actually written out, not the length of the string. Following the
        /// length, each character of the string is output, in sequence, using the
        /// modified UTF-8 encoding for the character. If no exception is thrown, the
        /// counter <code>written</code> is incremented by the total number of
        /// bytes written to the output stream. This will be at least two
        /// plus the length of <code>str</code>, and at most two plus
        /// thrice the length of <code>str</code>.
        ///
        /// </para>
        /// </summary>
        /// <param name="str">   a string to be written. </param>
        /// <param name="out">   destination to write to </param>
        /// <returns>     The number of bytes written out. </returns>
        /// <exception cref="IOException">  if an I/O error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static int writeUTF(String str, DataOutput out) throws IOException
        internal static int WriteUTF(String str, DataOutput @out)
        {
            int strlen = str.Length();
            int utflen = 0;
            int c, count = 0;

            /* use charAt instead of copying String to char array */
            for (int i = 0; i < strlen; i++)
            {
                c = str.CharAt(i);
                if ((c >= 0x0001) && (c <= 0x007F))
                {
                    utflen++;
                }
                else if (c > 0x07FF)
                {
                    utflen += 3;
                }
                else
                {
                    utflen += 2;
                }
            }

            if (utflen > 65535)
            {
                throw new UTFDataFormatException("encoded string too long: " + utflen + " bytes");
            }

            sbyte[] bytearr = null;
            if (@out is DataOutputStream)
            {
                DataOutputStream dos = (DataOutputStream)@out;
                if (dos.Bytearr == null || (dos.Bytearr.Length < (utflen + 2)))
                {
                    dos.Bytearr = new sbyte[(utflen * 2) + 2];
                }
                bytearr = dos.Bytearr;
            }
            else
            {
                bytearr = new sbyte[utflen + 2];
            }

            bytearr[count++] = unchecked ((sbyte)(((int)((uint)utflen >> 8)) & 0xFF));
            bytearr[count++] = unchecked ((sbyte)(((int)((uint)utflen >> 0)) & 0xFF));

            int i = 0;

            for (i = 0; i < strlen; i++)
            {
                c = str.CharAt(i);
                if (!((c >= 0x0001) && (c <= 0x007F)))
                {
                    break;
                }
                bytearr[count++] = (sbyte)c;
            }

            for (; i < strlen; i++)
            {
                c = str.CharAt(i);
                if ((c >= 0x0001) && (c <= 0x007F))
                {
                    bytearr[count++] = (sbyte)c;
                }
                else if (c > 0x07FF)
                {
                    bytearr[count++] = unchecked ((sbyte)(0xE0 | ((c >> 12) & 0x0F)));
                    bytearr[count++] = unchecked ((sbyte)(0x80 | ((c >> 6) & 0x3F)));
                    bytearr[count++] = unchecked ((sbyte)(0x80 | ((c >> 0) & 0x3F)));
                }
                else
                {
                    bytearr[count++] = unchecked ((sbyte)(0xC0 | ((c >> 6) & 0x1F)));
                    bytearr[count++] = unchecked ((sbyte)(0x80 | ((c >> 0) & 0x3F)));
                }
            }
            @out.Write(bytearr, 0, utflen + 2);
            return(utflen + 2);
        }
 /// <exception cref="System.IO.IOException"/>
 public static void WriteBytes(byte[] data, DataOutput @out)
 {
     @out.WriteShort(data.Length);
     @out.Write(data);
 }