コード例 #1
0
 public void Normalize()
 {
     while (Range < kTopValue)
     {
         Code    = (Code << 8) | (byte)Stream.ReadByte();
         Range <<= 8;
     }
 }
コード例 #2
0
        public static AlertRecord Deserialise(System.IO.Stream stream)
        {
            AlertRecord result = new AlertRecord();

            result._AlertLevel       = (TAlertLevel)stream.ReadByte();
            result._AlertDescription = (TAlertDescription)stream.ReadByte();
            return(result);
        }
コード例 #3
0
 public static int DecodeU16(System.IO.Stream buffer, out UInt16 value)
 {
     if (buffer.Position >= buffer.Length)
     {
         value = 0;
         return(0);
     }
     value = (UInt16)((buffer.ReadByte() << 8) | buffer.ReadByte());
     return(2);
 }
コード例 #4
0
 public static int DecodeU32(System.IO.Stream buffer, out UInt32 value)
 {
     if (buffer.Position >= buffer.Length)
     {
         value = 0;
         return(0);
     }
     value = (UInt32)((buffer.ReadByte() << 24) | (buffer.ReadByte() << 16) | (buffer.ReadByte() << 8) | buffer.ReadByte());
     return(4);
 }
コード例 #5
0
        /// <summary> Convert 2 bytes into a signed integer.
        ///
        /// </summary>
        /// <param name="raf">*
        /// </param>
        /// <returns> integer value
        /// </returns>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.Stream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        public static int int2(System.IO.Stream raf)
        {
            //byte[] bytes = ReadBytes(raf, 2);
            //return (int)BitConverter.ToInt16(bytes, 0);

            int a = raf.ReadByte();
            int b = raf.ReadByte();

            return(int2(a, b));
        }
コード例 #6
0
        static public int ReadLength(System.IO.Stream stream)
        {
            var b = stream.ReadByte();

            if ((b & 0x80) == 0)
            {
                return(b);
            }
            return(((b & 0x7F) << 24) + (stream.ReadByte() << 16) + (stream.ReadByte() << 8) + stream.ReadByte());
        }
コード例 #7
0
ファイル: SocketsModule.cs プロジェクト: parhelia512/nginz
            private IodineByteArray receiveRaw(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineInteger n = args [0] as IodineInteger;

                byte[] buf = new byte[n.Value];
                for (int i = 0; i < n.Value; i++)
                {
                    buf [i] = (byte)stream.ReadByte();
                }
                return(new IodineByteArray(buf));
            }
コード例 #8
0
 private int ReadUInt16Variant(System.IO.Stream stream, out int value)
 {
     value = stream.ReadByte();
     if ((value & 0x80) == 0)
     {
         return(1);
     }
     value &= 0x7F;
     value |= (stream.ReadByte() & 0x7F) << 7;
     return(2);
 }
コード例 #9
0
        public static long ReadTo(byte[] pattern, System.IO.Stream stream, out System.Collections.Generic.List <byte> readBytes, int[] kmpFailureFunction)
        {
            readBytes = new List <byte>();
            //I will have to implement some sort of linear string matching algorithm.
            long startPosition = stream.Position;
            //Knuth-Morris-Pratt algorithm:
            //int[] f=kmpFailureFunction(pattern);
            //int i=0;
            int j   = 0;
            int tmp = stream.ReadByte();

            if (tmp < 0)
            {
                return(tmp);//end of stream
            }
            byte t = (byte)tmp;

            readBytes.Add(t);
            while (stream.Position < stream.Length + 1)
            {
                if (pattern[j] == t)
                {
                    if (j == pattern.Length - 1)                  //see if we have a match
                    {
                        return(stream.Position - pattern.Length); //i-m+1
                    }
                    //i++;//do I need this?
                    tmp = stream.ReadByte();
                    if (tmp < 0)
                    {
                        return(tmp);//end of stream
                    }
                    t = (byte)tmp;
                    readBytes.Add(t);
                    j++;
                }
                else if (j > 0)//move forward in the pattern
                {
                    j = kmpFailureFunction[j - 1];
                }
                else
                {
                    //i++;
                    tmp = stream.ReadByte();
                    if (tmp < 0)
                    {
                        return(tmp);//end of stream
                    }
                    t = (byte)tmp;
                    readBytes.Add(t);
                }
            }
            return(-1);//There is no matching substring
        }
コード例 #10
0
        /// <summary>
        /// 主要针对Web中POST请求中数据流读取。
        /// 当然,我认为可读数据流可能都能试用。
        /// </summary>
        /// <param name="postRequestInputStream">数据流</param>
        /// <returns></returns>
        public static string ReadPostInputStream(System.IO.Stream postRequestInputStream)
        {
            int read = postRequestInputStream.ReadByte();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            while (read >= 0)
            {
                sb.Append((char)read);
                read = postRequestInputStream.ReadByte();
            }
            return(sb.ToString());
        }
コード例 #11
0
        /// <summary>
        /// Write everything from input stream to output stream, byte by byte then
        /// close the streams
        ///
        ///
        /// </summary>
        /// <param name="in">
        /// </param>
        /// <param name="out">
        /// </param>
        /// <throws>  IOException </throws>
        public static void  writeFromInputToOutput(System.IO.Stream in_Renamed, System.IO.Stream out_Renamed, long[] tally)
        {
            int val = in_Renamed.ReadByte();

            while (val != -1)
            {
                out_Renamed.WriteByte((System.Byte)val);
                incr(tally);
                val = in_Renamed.ReadByte();
            }
            in_Renamed.Close();
        }
コード例 #12
0
        internal static ParameterRequestListOption Read(System.IO.Stream stream)
        {
            int length = stream.ReadByte();

            OptionType[] options = new OptionType[length];
            for (int i = 0; i < length; i++)
            {
                options[i] = (OptionType)stream.ReadByte();
            }

            return(new ParameterRequestListOption(options));
        }
コード例 #13
0
        public Unknown0x80byteArea(System.IO.Stream stream, uint refStringStart, EndianUtils.Endianness endian)
        {
            UnknownUInt = stream.ReadUInt32().FromEndian(endian);
            stream.DiscardBytes(4);
            UnknownByte1 = (byte)stream.ReadByte();
            UnknownByte2 = (byte)stream.ReadByte();
            stream.DiscardBytes(2);
            UnknownFloat1 = stream.ReadUInt32().FromEndian(endian).UIntToFloat();
            UnknownFloat2 = stream.ReadUInt32().FromEndian(endian).UIntToFloat();

            stream.DiscardBytes(0x6C);
        }
コード例 #14
0
        public static NetMessage Unpack(System.IO.Stream stream)
        {
            var msglenbuf = new byte[4];

            stream.Read(msglenbuf, 0, 4);
            UInt32     msglen   = BitConverter.ToUInt32(msglenbuf, 0);
            var        posstart = stream.Position;
            NetMessage msg      = new NetMessage();
            {//read msg
                var isnull = stream.ReadByte();
                if (isnull != 0)
                {
                    var cl     = stream.ReadByte();
                    var strbuf = new byte[cl];
                    stream.Read(strbuf, 0, cl);
                    msg.Cmd = System.Text.Encoding.UTF8.GetString(strbuf);
                }
                else
                {
                    msg.Cmd = null;
                }

                isnull = stream.ReadByte();
                if (isnull != 0)
                {
                    var il    = stream.ReadByte();
                    var idbuf = new byte[il];
                    stream.Read(idbuf, 0, il);
                    msg.ID = System.Text.Encoding.UTF8.GetString(idbuf);
                }
                else
                {
                    msg.ID = null;
                }

                isnull = stream.ReadByte();
                if (isnull != 0)
                {
                    msg.Param = Param.Deserialize(stream);
                }
                else
                {
                    msg.Param = null;
                }
            }
            var posend = stream.Position;

            if (posend - posstart != msglen)
            {
                throw new Exception("bad msg.");
            }
            return(msg);
        }
コード例 #15
0
 public static int DecodeU16(System.IO.Stream buffer, Encodings encoding, out UInt16 value)
 {
     if ((encoding & Encodings.LittleEndian) == Encodings.BigEndian)
     {
         value = (UInt16)((buffer.ReadByte() << 8) | (buffer.ReadByte() << 0));
     }
     else
     {
         value = (UInt16)((buffer.ReadByte() << 0) | (buffer.ReadByte() << 8));
     }
     return(2);
 }
コード例 #16
0
        public Unknown0x80byteArea(System.IO.Stream stream, uint refStringStart)
        {
            UnknownUInt = stream.ReadUInt32().SwapEndian();
            stream.DiscardBytes(4);
            UnknownByte1 = (byte)stream.ReadByte();
            UnknownByte2 = (byte)stream.ReadByte();
            stream.DiscardBytes(2);
            UnknownFloat1 = stream.ReadUInt32().SwapEndian().UIntToFloat();
            UnknownFloat2 = stream.ReadUInt32().SwapEndian().UIntToFloat();

            stream.DiscardBytes(0x6C);
        }
コード例 #17
0
        internal static MessageOption Read(System.IO.Stream stream)
        {
            int length = stream.ReadByte();

            OptionType[] options = new OptionType[length];
            for (int i = 0; i < length; i++)
            {
                options[i] = (OptionType)stream.ReadByte();
            }

            return(new MessageOption(options));
        }
コード例 #18
0
        public int Ping()
        {
            int pingTime = 0;

            try
            {
                Stopwatch sw = new Stopwatch();
                LastError = "";

                using (WebClientEx wc = new WebClientEx())
                {
                    wc.Timeout = (timeOut * 1000);
                    wc.UseDefaultCredentials = true;

                    if (ProxyServer.Length > 0)
                    {
                        wc.Proxy             = new System.Net.WebProxy(ProxyServer);
                        wc.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    }
                    else
                    {
                        wc.Proxy = null;
                    }
                    wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);

                    sw.Start();
                    using (System.IO.Stream webRequest = wc.OpenRead(Url))
                    {
                        if (webRequest.CanRead)
                        {
                            int readByte = webRequest.ReadByte();
                            while (readByte != -1)
                            {
                                readByte = webRequest.ReadByte();
                            }
                        }
                        else
                        {
                            throw new Exception("Could not read web request stream");
                        }
                    }
                    sw.Stop();
                }
                pingTime = (int)sw.ElapsedMilliseconds;
            }
            catch (Exception ex)
            {
                LastError = ex.Message;
                pingTime  = int.MaxValue;
            }

            return(pingTime);
        }
コード例 #19
0
        public override void LoadFromBinaryReader(System.IO.Stream binaryReader)
        {
            base.LoadFromBinaryReader(binaryReader);

            Colors = new Color[256];
            for (int i = 0; i < Colors.Length; i++)
            {
                var r = binaryReader.ReadByte();
                var g = binaryReader.ReadByte();
                var b = binaryReader.ReadByte();

                Colors[i] = Color.FromArgb(r, g, b);
            }
        }
コード例 #20
0
        private SmalltalkArchive readFrom(System.IO.Stream stream)
        {
            var header = readHeaderFrom(stream);

            var classes = DefaultClasses;

            int tag;

            while ((tag = stream.ReadByte()) != NUL)
            {
                var  classId           = readInteger(stream);
                var  className         = readString(stream, NUL);
                byte rep               = (byte)stream.ReadByte();
                var  numNamedInstVars  = readInteger(stream);
                var  filedInstVarNames = new List <string>();

                for (int i = 0; i < numNamedInstVars; i++)
                {
                    filedInstVarNames.Add(readString(stream, NUL));
                }

                var componentName = readString(stream, NUL);

                classes.Add(classId, new SmalltalkClass(tag, classId, className, rep, filedInstVarNames));
            }

            var archive = new SmalltalkArchive()
            {
                Header  = header,
                Classes = classes
            };

            loadObjectDescriptors(stream, archive);
            //restoreInstanceVariables(archive);

            // Read to end or next ESC
            int nextByte = stream.ReadByte();

            while (nextByte >= 0)
            {
                if (nextByte == ESC)      // Start of next archive
                {
                    stream.Position -= 1; // backup 1
                    break;                // then quick
                }
                nextByte = stream.ReadByte();
            }

            return(archive);
        }
コード例 #21
0
 public override int ReadByte()
 {
     if (currentBit == 0)
     {
         return(byteStream.ReadByte());
     }
     else
     {
         int nextByte = byteStream.ReadByte();
         int result   = ((currentByte << currentBit) | (nextByte >> (8 - currentBit))) & 0xFF;
         currentByte = nextByte;
         return(result);
     }
 }
コード例 #22
0
        /// <summary> Convert 3 bytes into a signed integer.
        ///
        /// </summary>
        /// <param name="raf">*
        /// </param>
        /// <returns> integer value
        /// </returns>
        /// <throws>  IOException </throws>
        public static int int3(System.IO.Stream raf)
        {
//            byte[] bytes = ReadBytes(raf, 3);
//            byte[] fourBytes = new byte[4];
//            bytes.CopyTo(fourBytes, 0);
//            fourBytes[3] = 0;
//            return BitConverter.ToInt32(fourBytes, 0);

            int a = raf.ReadByte();
            int b = raf.ReadByte();
            int c = raf.ReadByte();

            return((1 - ((a & 128) >> 6)) * ((a & 127) << 16 | b << 8 | c));
        }
コード例 #23
0
ファイル: HallOfFame.cs プロジェクト: mhwu95/HyoutaTools
            public HallOfFamePokemon(System.IO.Stream stream)
            {
                TrainerId        = stream.ReadUInt16();
                SecretId         = stream.ReadUInt16();
                PersonalityValue = stream.ReadUInt32();
                int speciesLow    = stream.ReadByte();
                int speciesHighLv = stream.ReadByte();

                Species = (ushort)(speciesLow | ((speciesHighLv & 0x1) << 8));
                Level   = (byte)((speciesHighLv & 0xFE) >> 1);
                // Nickname is always English, Japanese names are prepended with 0xFC15 which switches the text renderer to JP mode and appended with 0xFC16 to switch back.
                // This works because Japanese names are limited to 5 characters.
                Nickname = new String3(String3.Region.Western, stream, 10);
            }
コード例 #24
0
            private IodineObject Receive(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineInteger n     = args [0] as IodineInteger;
                StringBuilder accum = new StringBuilder();

                for (int i = 0; i < n.Value; i++)
                {
                    int b = stream.ReadByte();
                    if (b != -1)
                    {
                        accum.Append((char)b);
                    }
                }
                return(new IodineString(accum.ToString()));
            }
コード例 #25
0
        private void addWord(System.IO.Stream s, string sName)
        {
            int lo = s.ReadByte();
            int hi = s.ReadByte();

            fldIco = (hi * 256) + lo;

            host.UI.icoLst.Items.Add(
                posIco.ToString() + ": " +
                sName + ": " +
                hi.ToString() + " | " + lo.ToString() +
                " ( " + fldIco.ToString() + " )");

            posIco += 2;
        }
コード例 #26
0
ファイル: Authorization.cs プロジェクト: junbao520/AndroidApp
 public string ReadAuthFile(string FileName = "Auth.ini")
 {
     try
     {
         Java.Lang.StringBuffer sb = new Java.Lang.StringBuffer();
         //文件不存在
         if (!System.IO.File.Exists(FileName))
         {
             return(string.Empty);
         }
         System.IO.Stream fis = context.OpenFileInput(FileName);
         int ch;
         while ((ch = fis.ReadByte()) != -1)
         {
             sb.Append((char)ch);
         }
         fis.Close();
         string AuthMsg = sb.ToString();
         Logger.Debug("AuthMsg:" + AuthMsg);
         if (string.IsNullOrEmpty(AuthMsg))
         {
             AuthMsg = ReadDecryptorFile(AuthFileName);
             Logger.Debug("ReadDecryptorFile:" + AuthMsg);
         }
         return(AuthMsg);
     }
     catch (Exception exp)
     {
         //记录详细日志
         Logger.Error(exp, GetType().ToString());
         return(string.Empty);
     }
 }
コード例 #27
0
        public Dictionary <string, IList <Token> > Project_FromPacketStream(System.IO.Stream instream)
        {
            Dictionary <string, IList <Token> > project = new Dictionary <string, IList <Token> >();

            byte[] buf = new byte[8];
            instream.Read(buf, 0, 8);
            string filehead = System.Text.Encoding.UTF8.GetString(buf, 0, 8);

            if (filehead != "CQuark-DLL")
            {
                return(null);
            }
            instream.Read(buf, 0, 2);
            UInt16 count = BitConverter.ToUInt16(buf, 0);

            for (int i = 0; i < count; i++)
            {
                int    slen        = instream.ReadByte();
                byte[] buffilename = new byte[slen];
                instream.Read(buffilename, 0, slen);
                string key   = System.Text.Encoding.UTF8.GetString(buffilename, 0, slen);
                var    tlist = tokenParser.ReadTokenList(instream);
                project[key] = tlist;
            }
            return(project);
        }
コード例 #28
0
        public override DecodedObject <object> decodeReal(DecodedObject <object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Primitive, UniversalTags.Real, elementInfo))
            {
                return(null);
            }
            DecodedObject <int> len = decodeLength(stream);
            int realPreamble        = stream.ReadByte();

            Double result   = 0.0D;
            int    szResult = len.Value;

            if ((realPreamble & 0x40) == 1)
            {
                // 01000000 Value is PLUS-INFINITY
                result = Double.PositiveInfinity;
            }
            if ((realPreamble & 0x41) == 1)
            {
                // 01000001 Value is MINUS-INFINITY
                result    = Double.NegativeInfinity;
                szResult += 1;
            }
            else
            if (len.Value > 0)
            {
                int szOfExp = 1 + (realPreamble & 0x3);
                int sign    = realPreamble & 0x40;
                int ff      = (realPreamble & 0x0C) >> 2;
                DecodedObject <object> exponentEncFrm = decodeLongValue(stream, new DecodedObject <int>(szOfExp));
                long exponent = (long)exponentEncFrm.Value;
                DecodedObject <object> mantissaEncFrm = decodeLongValue(stream, new DecodedObject <int>(szResult - szOfExp - 1));
                // Unpack mantissa & decrement exponent for base 2
                long mantissa = (long)mantissaEncFrm.Value << ff;
                while ((mantissa & 0x000ff00000000000L) == 0x0)
                {
                    exponent  -= 8;
                    mantissa <<= 8;
                }
                while ((mantissa & 0x0010000000000000L) == 0x0)
                {
                    exponent  -= 1;
                    mantissa <<= 1;
                }
                mantissa &= 0x0FFFFFFFFFFFFFL;
                long lValue = (exponent + 1023 + 52) << 52;
                lValue |= mantissa;
                if (sign == 1)
                {
                    lValue = (long)((ulong)lValue | 0x8000000000000000L);
                }
#if PocketPC
                byte[] dblValAsBytes = System.BitConverter.GetBytes(lValue);
                result = System.BitConverter.ToDouble(dblValAsBytes, 0);
#else
                result = System.BitConverter.Int64BitsToDouble(lValue);
#endif
            }
            return(new DecodedObject <object>(result, len.Value + len.Size));
        }
コード例 #29
0
ファイル: ImgPFunc.cs プロジェクト: pimier15/CsChipVision
        /* can partial application */
        public static Dictionary <string, Func <dynamic> > ReaderDict(System.IO.Stream stream)
        {
            Dictionary <string, Func <dynamic> > output = new Dictionary <string, Func <dynamic> >();

            Func <byte[], byte[]> readbytearr = input =>
            {
                stream.Read(input, 0, input.Length);
                return(input);
            };

            Func <dynamic> ToByte  = () => (byte)stream.ReadByte();
            Func <dynamic> ToInt   = () => BitConverter.ToInt32(readbytearr(new byte[4]), 0);
            Func <dynamic> ToLong  = () => BitConverter.ToInt64(readbytearr(new byte[8]), 0);
            Func <dynamic> ToFloat = () => BitConverter.ToSingle(readbytearr(new byte[4]), 0);

            //Func <dynamic> CutHeader  = () => readbytearr(new byte[],0);
            byte[] tempman = new byte[2];

            output.Add("byte", ToByte);
            output.Add("int", ToInt);
            output.Add("long", ToLong);
            output.Add("float", ToFloat);

            return(output);
        }
コード例 #30
0
        public static string GetHTML(string url, Encoding enc)
        {
            string text = string.Empty;

            try
            {
                //HttpWebRequestの作成
                System.Net.HttpWebRequest webreq =
                    (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
                //               webreq.Timeout = webreq.Timeout * timeout;
                //HttpWebResponseの取得
                System.Net.HttpWebResponse webres =
                    (System.Net.HttpWebResponse)webreq.GetResponse();


                //応答データを受信するためのStreamを取得
                System.IO.Stream st = webres.GetResponseStream();

                List <byte> byteArray = new List <byte>();
                int         b;
                while ((b = st.ReadByte()) > -1)
                {
                    byteArray.Add((byte)b);
                }

                byte[] byteArray2 = byteArray.ToArray();
                text = enc.GetString(byteArray2);
            }
            catch
            {
                text = string.Empty;
            }
            return(text);
        }
コード例 #31
0
ファイル: RangeCoder.cs プロジェクト: RafaelRMachado/de4dot
		public void Init(System.IO.Stream stream)
		{
			// Stream.Init(stream);
			Stream = stream;

			Code = 0;
			Range = 0xFFFFFFFF;
			for (int i = 0; i < 5; i++)
				Code = (Code << 8) | (byte)Stream.ReadByte();
		}
コード例 #32
0
ファイル: GMKIn.cs プロジェクト: joshwyant/game-creator
 public GMKIn(System.IO.Stream source)
 {
     s = source;
     int tpos = (int)s.Position;
     len = (int)s.Length;
     s.Seek(0, System.IO.SeekOrigin.Begin);
     s.Read(buffer, 0, 16);
     int junk1 = BitConverter.ToInt32(buffer, 8);
     int junk2 = BitConverter.ToInt32(buffer, 12);
     s.Seek(junk1 * 4, System.IO.SeekOrigin.Current);
     s.Read(buffer, 8, 4);
     int seed = BitConverter.ToInt32(buffer, 8);
     table = GenerateSwapTable(seed);
     s.Seek(junk2 * 4, System.IO.SeekOrigin.Current);
     outlen = s.Length - (s.Position - 8L);
     outpos = 0;
     buffer[8] = (byte)s.ReadByte();
     bufferptrin = 9;
     bufferptrout = tpos;
     pos = (int)s.Position;
 }