Beispiel #1
0
        public static byte[] Init(Int32 size, bool encodeKey, bool encodeTimestamp)
        {
            if (encodeKey)
            {
                //using (DataOutput dos = new DataOutput())
                //{
                dos.Reset();
                try
                {
                    Int32 index = 1234;
                    dos.WriteInt32(index);
                    //dos.Write(index);
                    if (encodeTimestamp)
                    {
                        DateTime startTime = DateTime.Now;
                        long     timestamp = startTime.Ticks * (1000000 / TimeSpan.TicksPerMillisecond);
                        //dos.Write(timestamp);
                        dos.WriteInt64(timestamp);
                    }
                }
                catch (Exception e)
                {
                    //FwkException("Unable to write to stream {0}", e.Message);
                    throw new Exception(e.Message);
                }

                /*
                 * byte[] b = baos.GetBuffer();
                 * if (b.Length > size)
                 * {
                 * throw new Exception("Unable to encode into byte array of size");
                 * }
                 * byte[] result = new byte[size];
                 * System.Array.Copy(b, 0, result, 0, b.Length);
                 * return CacheableBytes.Create(result);
                 * //return result;
                 */

                Int32  bufSize = size;
                byte[] buf     = new byte[bufSize];

                for (int i = 0; i < bufSize; i++)
                {
                    buf[i] = 123;
                }
                //buf.CopyTo(dos.GetBuffer(), (int)dos.BufferLength);
                System.Array.Copy(dos.GetBuffer(), 0, buf, 0, dos.BufferLength);
                //Console.WriteLine("rjk: size of byte array is {0} , dataoutput lenght {1} and object is {2}", sizeof(byte) * buf.Length, dos.BufferLength, buf.ToString());
                Int32 rsiz = (bufSize <= 20) ? bufSize : 20;
                return(buf);

                //}
            }
            else if (encodeTimestamp)
            {
                throw new Exception("Should not happen");
                //FwkException("Should not happen");
            }
            else
            {
                return(new byte[size]);
                //return new byte[size];
            }
        }