Read() public method

public Read ( ) : int
return int
Example #1
0
        public ExexEntry(BinaryReader reader)
            : this()
        {
            auraId = reader.ReadUInt16();
            auraSlot = reader.ReadUInt16();

            particleColor = readColor(reader);
            reader.Read(data1, 0, data1.Length);

            outerGlowColor = readColor(reader);
            innerGlowColor = readColor(reader);
            reader.Read(data2, 0, data2.Length);

            smoke1Color = readColor(reader);
            smoke1Invert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data3, 0, data3.Length);

            smoke2Color = readColor(reader);
            smoke2Invert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data4, 0, data4.Length);

            boltsColor = readColor(reader);
            boltsInvert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data5, 0, data5.Length);
        }
		private static string StreamToHexString(Stream stream)
		{
			byte[] buffer = new byte[4096];

			StringBuilder strB = new StringBuilder(4096);

			using (BinaryReader br = new BinaryReader(stream))
			{
				int byteRead = br.Read(buffer, 0, buffer.Length);

				while (byteRead > 0)
				{
					for (int i = 0; i < byteRead; i++)
					{
						if (strB.Length == 0)
							strB.Append("0X");

						strB.AppendFormat("{0:X2}", buffer[i]);
					}

					byteRead = br.Read(buffer, 0, buffer.Length);
				}
			}

			if (strB.Length == 0)
				strB.Append("NULL");

			return strB.ToString();
		}
        public void Read(Stream stream)
        {
            BinaryReader reader = new BinaryReader (stream);
                int headerSize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int keySize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int valueSize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int packetVersion = reader.ReadByte();
                if (packetVersion != PACKET_VERSION)
                {
                    //throw new Exception("Packet versions do not match. Expected " + PACKET_VERSION + " but found " + packetVersion);
                }
                readHeader(reader);

                try
                {
                    this.key = new byte[keySize];
                    if (keySize > 0)
                        reader.Read(this.key, 0, keySize);
                    this.value = new byte[valueSize];
                    if (valueSize > 0)
                    {
                        int x = reader.Read(this.value, 0, valueSize);
                        if (x != valueSize) {
                            Console.WriteLine("Esit degil: " + x + "::" + valueSize + "");
                            Thread.Sleep(10000);
                        }
                    }
                }catch (Exception e) {
                    Console.WriteLine("Keysize" + keySize + ": " + valueSize);
                    Console.WriteLine(e.StackTrace);
                }
        }
Example #4
0
 public void Close()
 {
     if (writer == null)
         return;
     writer.Close();
     writer = null;
     using (BinaryWriter bw2 = new BinaryWriter(wavR.OpenResourceForWrite()))
     {
         bw2.Write((Int32)1179011410);
         bw2.Write((Int32)44 + length - 8);
         bw2.Write((Int32)1163280727);
         bw2.Write((Int32)544501094);
         bw2.Write((Int32)16);
         bw2.Write((Int16)1);
         bw2.Write((Int16)channels);
         bw2.Write((Int32)sRate);
         bw2.Write((Int32)(sRate * channels * (bits / 8)));
         bw2.Write((Int16)(channels * (bits / 8)));
         bw2.Write((Int16)bits);
         bw2.Write((Int32)1635017060);
         bw2.Write((Int32)length);
         using (BinaryReader br = new BinaryReader(tempR.OpenResourceForRead()))
         {
             byte[] buffer = new byte[1024];
             int count = br.Read(buffer, 0, buffer.Length);
             while (count > 0)
             {
                 bw2.Write(buffer, 0, count);
                 count = br.Read(buffer, 0, buffer.Length);
             }
         }
     }
     tempR.DeleteResource();
 }
Example #5
0
        public static BitmapImage GetImageFromUrl(string url)
        {
            var image = new BitmapImage();
            int BytesToRead = 100;
            var responseStream = Network.GetStream(url);
            if (responseStream == null)
            {
                return null;
            }
            BinaryReader reader = new BinaryReader(responseStream);
            MemoryStream memoryStream = new MemoryStream();

            byte[] bytebuffer = new byte[BytesToRead];
            int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

            while (bytesRead > 0)
            {
                memoryStream.Write(bytebuffer, 0, bytesRead);
                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
            }

            image.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);

            image.StreamSource = memoryStream;
            image.EndInit();

            return image;
        }
Example #6
0
        private void cryptBtn_Click(object sender, EventArgs e)
        {
            // Copy header
            byte[] header = new byte[54];
            List<Byte> body = new List<byte>();
            byte[] temp = new byte[1];

            using (BinaryReader sourceF = new BinaryReader(File.Open(this.selFileTb.Text, FileMode.Open)))
            {
                sourceF.Read(header, 0, header.Length);
                using (BinaryWriter newF = new BinaryWriter(File.Open(this.newFileTb.Text, FileMode.OpenOrCreate)))
                {
                    newF.Write(header, 0, header.Length);
                    int len = 0;
                    while (sourceF.BaseStream.Position != sourceF.BaseStream.Length)
                    {
                        sourceF.Read(temp, 0, 1);
                        body.Add(temp[0]);
                        len++;
                    }
                    byte[] b = body.ToArray();

                    newF.Write(this.Crypt(b), 0, len);
                }
            }
        }
Example #7
0
        public static void LoadElf(string FileName, SPU spu, bool setProgramCounter)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(FileName));
            // GetElfHeader
            byte[] elfMagic = new byte[4];
            br.Read(elfMagic, 0, 4);
            if (elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F)
            {
                MessageBox.Show("Elf Magic Wrong (" + FileName + ")");
                return;
            }
            br.BaseStream.Seek(0, SeekOrigin.Begin);
            byte[] eHDR = new byte[0x34];
            br.Read(eHDR, 0, eHDR.Length);
            uint phdr_offset = ConversionUtil.byteToUInt(eHDR, 0x1C);
            ushort n_phdrs = ConversionUtil.byteToUShort(eHDR, 0x2C);
            for (ushort i = 0; i < n_phdrs; i++)
            {
                int error = LoadElfPHDR(br, spu, phdr_offset, i);
                if (error == 1)
                    MessageBox.Show("Didn't Load phdr " + i + " of File " + FileName);
                else if (error == 2)
                    MessageBox.Show("Local Storage Overflow!");
            }

            if (setProgramCounter)
                spu.IP = ConversionUtil.byteToUInt(eHDR, 0x18);
            br.Close();
        }
Example #8
0
        public static List<DATFile> FindFiles(DAT dat, BinaryReader br)
        {
            List<DATFile> DatFiles = new List<DATFile>();

            uint FileIndex = 0;
            br.BaseStream.Seek(-(dat.TreeSize + 4), SeekOrigin.End);
            while (FileIndex < dat.FilesTotal)
            {
                DATFile file = new DATFile();
                file.br = br;
                file.FileNameSize = br.ReadInt32();
                char[] namebuf = new Char[file.FileNameSize];
                br.Read(namebuf, 0, (int)file.FileNameSize);
                file.Path = new String(namebuf, 0, namebuf.Length);
                file.FileName = Path.GetFileName(file.Path);
                file.Compression = br.ReadByte();
                file.UnpackedSize = br.ReadInt32();
                file.PackedSize = br.ReadInt32();
                if (file.Compression==0x00&&(file.UnpackedSize != file.PackedSize))
                        file.Compression = 1;
                file.Offset = br.ReadInt32();
                long oldoffset = br.BaseStream.Position;
                // Read whole file into a buffer
                br.BaseStream.Position = file.Offset;
                file.Buffer = new Byte[file.PackedSize];
                br.Read(file.Buffer, 0, file.PackedSize);
                br.BaseStream.Position = oldoffset;

                DatFiles.Add(file);
                FileIndex++;
            }
            return DatFiles;
        }
        // MEMO:
        // The purpose of using"IPAddress.NetworkToHostOrder()" method is changing endian from big endian to little endian.

        public static IEnumerable<byte[]> GetModuleFromSSHPublicKeyString(string pubKeySSHFormat)
        {
            if (string.IsNullOrEmpty(pubKeySSHFormat)) yield break;

            // Split each rows
            var pubKeyBodies = pubKeySSHFormat
                .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(row => row.Trim().Split(' ', '\t').Last());

            foreach (var pubKeyBody in pubKeyBodies)
            {
                var pubKeyBin = Convert.FromBase64String(pubKeyBody);
                using (var ms = new MemoryStream(pubKeyBin))
                using (var binReader = new BinaryReader(ms))
                {
                    // Get byte size of algorithm name.
                    var sizeOfAlgorithmName = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read and drop algorithm name (generally, this is "ssh-rsa" 7 bytes).
                    binReader.Read(new byte[sizeOfAlgorithmName], 0, sizeOfAlgorithmName);

                    // Get byte size of exponent.
                    var sizeOfExponent = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read and drop exponent.
                    binReader.Read(new byte[sizeOfExponent], 0, sizeOfExponent);

                    // Get byte size of module.
                    var sizeOfModule = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read module and return it.
                    var module = new byte[sizeOfModule];
                    binReader.Read(module, 0, sizeOfModule);
                    yield return module;
                }
            }
        }
        private static BitmapImage GetImageFromUrl(string url)
        {
            var image = new BitmapImage();
            const int bytesToRead = 100;
            var request =
                WebRequest.Create(
                    new Uri(url, UriKind.Absolute));
            request.Timeout = -1;
            var response = request.GetResponse();
            var responseStream = response.GetResponseStream();
            if (responseStream != null)
            {
                var reader = new BinaryReader(responseStream);
                var memoryStream = new MemoryStream();

                var bytebuffer = new byte[bytesToRead];
                var bytesRead = reader.Read(bytebuffer, 0, bytesToRead);

                while (bytesRead > 0)
                {
                    memoryStream.Write(bytebuffer, 0, bytesRead);
                    bytesRead = reader.Read(bytebuffer, 0, bytesToRead);
                }

                image.BeginInit();
                memoryStream.Seek(0, SeekOrigin.Begin);

                image.StreamSource = memoryStream;
            }
            image.EndInit();
            return image;
        }
Example #11
0
        public ObjectEntry(BinaryReader reader)
            : this()
        {
            id = reader.ReadUInt16();
            data1 = reader.ReadUInt16();
            data2 = reader.ReadUInt16();
            characterId = reader.ReadByte();
            costumeId = reader.ReadByte();
            objectEntryType = reader.ReadByte();
            objectEntrySlot = reader.ReadByte();

            for (int i = 0; i < MODEL_DATA_BYTES; i++)
            {
                modelData[i] = reader.ReadByte();
            }

            for (int i = 0; i < ATTACHMENT_IDS_ARRAY_SIZE; i++)
            {
                attachmentIds[i] = reader.ReadUInt16();
            }
            byte[] buffer = new byte[16];
            reader.Read(buffer, 0, 16);
            modelName = Encoding.ASCII.GetString(buffer).TrimEnd('\0');

            buffer = new byte[16];
            reader.Read(buffer, 0, 16);
            objxName = Encoding.ASCII.GetString(buffer).TrimEnd('\0');
        }
Example #12
0
        protected BitmapImage icon(string url)
        {
            var image = new BitmapImage();
            int BytesToRead = 100;

            WebRequest request = WebRequest.Create(new Uri(url, UriKind.Absolute));
            request.Timeout = -1;
            WebResponse response = request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            BinaryReader reader = new BinaryReader(responseStream);
            MemoryStream memoryStream = new MemoryStream();

            byte[] bytebuffer = new byte[BytesToRead];
            int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

            while (bytesRead > 0)
            {
                memoryStream.Write(bytebuffer, 0, bytesRead);
                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
            }

            image.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);

            image.StreamSource = memoryStream;
            image.EndInit();
            return image;
        }
 public void ParseInfo(long pos, string filePath)
 {
     byte[] array = new byte[100000];
     BinaryReader binaryReader = new BinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read));
     try
     {
         binaryReader.BaseStream.Position = pos + VolumePathOffset;
         binaryReader.Read(array, 0, VolumePathLength*2);
         string name = Encoding.Unicode.GetString(array).TrimEnd('\0'); //bytestostring_littleendian(array);
         binaryReader.BaseStream.Position = pos + FolderPathOffset;
         List<string> iFolderPaths = new List<string>();
         for (int i = 0; i < NumFolderPaths; i++)
         {
             byte[] array2 = new byte[100000];
             binaryReader.Read(array2, 0, 2);
             uint len = BitConverter.ToUInt16(array2, 0);
             binaryReader.Read(array2, 0, (int)len*2);
             string szPath = Encoding.Unicode.GetString(array2).TrimEnd('\0');
             if (szPath != "")
                 iFolderPaths.Add(szPath);
             binaryReader.Read(array2, 0, 2);
         }
         FolderPaths = iFolderPaths.ToArray();
     }
     finally
     {
         binaryReader.Close();
     }
 }
Example #14
0
        private void ValidateDisposedExceptions(BinaryReader binaryReader)
        {
            byte[] byteBuffer = new byte[10];
            char[] charBuffer = new char[10];

            Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
        }
Example #15
0
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf = new byte[4];
            BinaryReader rd = new BinaryReader(strm);
            int numFiles;
            List<FileEntry> results = new List<FileEntry>();

            rd.Read(buf, 0, 4);
            if (Encoding.ASCII.GetString(buf, 0, 4) != "TGP0")
                return results;

            if (rd.ReadInt32() != 1)  // version check
                return results;

            if (rd.ReadInt32() != 0)  // should be zero
                return results;

            numFiles = rd.ReadInt32();
            buf = new byte[0x60];
            for (int i = 0; i < numFiles; i++)
            {
                FileEntry ent = new FileEntry();

                rd.Read(buf, 0, 0x60);
                ent.Filename = Encoding.ASCII.GetString(buf);
                ent.Filename = ent.Filename.Substring(0, ent.Filename.IndexOf('\0'));
                ent.Offset = rd.ReadInt64();
                ent.UncompressedSize = rd.ReadInt64();

                results.Add(ent);
            }

            return results;
        }
        private void CreateSettingsFile()
        {
            Assembly assembly = GetType().Assembly;
            BinaryReader reader = new BinaryReader(assembly.GetManifestResourceStream("D3.Commission.Settings.xml"));
            FileStream stream = new FileStream(FilePath, FileMode.Create);
            BinaryWriter writer = new BinaryWriter(stream);
            try
            {
                byte[] buffer = new byte[64 * 1024];
                int numread = reader.Read(buffer, 0, buffer.Length);

                while (numread > 0)
                {
                    writer.Write(buffer, 0, numread);
                    numread = reader.Read(buffer, 0, buffer.Length);
                }

                writer.Flush();
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
        public void Should_Read_Boolean_Value()
        {
            var reader = new BinaryReader(new MemoryStream(new byte[] {1, 0}));
            var value = reader.Read(DataType.Boolean);
            value.ShouldBeType<bool>();
            ((bool)value).ShouldBeTrue();

            reader.Read<bool>(DataType.Boolean).ShouldBeFalse();
        }
        public void Should_Read_Float_Value()
        {
            var reader = new BinaryReader(new MemoryStream(new byte[] { 174, 71, 1, 192, 174, 71, 129, 191, 0, 0, 0, 0,
                                                                        174, 71, 129, 63, 174, 71, 1, 64 }));
            var value = reader.Read(DataType.SingleFloat);
            value.ShouldBeType<float>();
            ((float)value).ShouldEqual(-2.02f);

            reader.Read<float>(DataType.SingleFloat).ShouldEqual(-1.01f);
            reader.Read<float>(DataType.SingleFloat).ShouldEqual(0.00f);
            reader.Read<float>(DataType.SingleFloat).ShouldEqual(1.01f);
            reader.Read<float>(DataType.SingleFloat).ShouldEqual(2.02f);
        }
Example #19
0
        /// <summary>This method creates a picture object from the contents
        /// of the passed in bitmap file.</summary>
        /// <remark>Note: The bitmap file is embedded as a resource in the 
        /// executable. The file is temporarily copied out to the client 
        /// file system by this function, since the OleLoadPictureFile 
        /// function requires the file to reside in the file system.</remark>
        ///	<param name="resourceName">File name of the bitmap embedded as
        /// a resource in the executable</param>
        /// <returns>stdole.IPictureDisp object created from the contents 
        /// of the file.</returns>
        public static IPictureDisp GetPicture( string resourceName )
        {
            int loadPictureResult;
            Object picture = null;

            try
            {
                string temporaryFile = Path.GetTempFileName();

                // Get an input stream of the bitmap file embedded
                // in the executable.
                Stream inStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( BasePath + resourceName );

                // Create a BinaryReader from the input stream.
                BinaryReader inReader = new BinaryReader( inStream );

                // Create the output stream for the temporary file.
                FileStream outStream = new FileStream( temporaryFile, FileMode.Create );

                // Create a BinaryWriter from the output stream.
                BinaryWriter outWriter = new BinaryWriter( outStream );

                byte[] buffer = new byte[ 1000 ];
                int bytesRead = inReader.Read( buffer, 0, buffer.Length );

                while ( bytesRead > 0 )
                {
                    outWriter.Write( buffer, 0, bytesRead );
                    bytesRead = inReader.Read( buffer, 0, buffer.Length );
                }

                inReader.Close();
                outWriter.Close();

                // Load the bitmap from the temporary file.
                loadPictureResult = OleLoadPictureFile( temporaryFile, out picture );

                // Delete the temporary file.
                File.Delete( temporaryFile );

                if ( loadPictureResult != 0 )
                    throw new COMException( "OleLoadPictureFailed", loadPictureResult );
            }
            catch ( COMException ex )
            {
                ESIMessageBox.ShowError(ex);
            }

            return (IPictureDisp) picture;
        }
        public void Should_Read_Double_With_Unit_Value()
        {
            var reader = new BinaryReader(new MemoryStream(new byte[] { 41, 92, 143, 194, 245, 40, 0, 192, 41, 92, 143, 194,
                                                                        245, 40, 240, 191, 0, 0, 0, 0, 0, 0, 0, 0, 41, 92,
                                                                        143, 194, 245, 40, 240, 63, 41, 92, 143, 194, 245,
                                                                        40, 0, 64 }));
            var value = reader.Read(DataType.DoubleFloatWithUnit);
            value.ShouldBeType<double>();
            ((double)value).ShouldEqual(-2.02);

            reader.Read<double>(DataType.DoubleFloatWithUnit).ShouldEqual(-1.01);
            reader.Read<double>(DataType.DoubleFloatWithUnit).ShouldEqual(0);
            reader.Read<double>(DataType.DoubleFloatWithUnit).ShouldEqual(1.01);
            reader.Read<double>(DataType.DoubleFloatWithUnit).ShouldEqual(2.02);
        }
Example #21
0
        private static byte[] ReadBeginningAndEnd(Stream stream)
        {
            if (stream.Length < BlockSize)
                return new byte[0];

            using (var binaryReader = new BinaryReader(stream))
            {
                var buffer = new byte[BlockSize * 2];
                binaryReader.BaseStream.Seek(0, SeekOrigin.Begin);
                binaryReader.Read(buffer, 0, BlockSize);
                binaryReader.BaseStream.Seek(-BlockSize, SeekOrigin.End);
                binaryReader.Read(buffer, BlockSize, BlockSize);
                return buffer;
            }
        }
        /// <summary>
        /// 保存上传文件到磁盘目录(此方法在http_service_handler的Upload中在文件类型校验合法后被调用)
        /// </summary>
        /// <param name="param">上传参数配置</param>
        /// <param name="fileHash">上传文件的物理路径Hashtable</param>
        internal static void SaveToDisk(UploadParameter param, System.Collections.Hashtable fileHash)
        {
            int cur_build = 0;      // 创建文件保存路径次数            
            string _filePath = string.Empty;

            if (!Directory.Exists(param.SaveToDir))
            {
                if (!param.AutoMKDir)
                    throw new APIFW_ArgumentException(" 上传目录不存在,请手动创建目录或将AutoMKDir参数设置为True ");
                fileHash.Add(-1, Directory.CreateDirectory(param.SaveToDir).FullName);
            }

            int size = 0;
            long completed = 0;
            byte[] buffer = new byte[param.BufferSize];

            for (int i = 0; i < param.FileUploads.Length; i++)
            {
                cur_build = 0;      // 上传文件名称重命名计数
                completed = 0;      // 当前上传文件已保存大小

                AdjustUploadItemFileName(param, ref param.FileUploads[i], ref cur_build, ref _filePath);

                if (param.FileUploads[i].IsValid && param.FileUploads[i].FileName != null &&
                    param.FileUploads[i].ContentLength > 0 && param.FileUploads[i].FileName.Length > 0)
                {
                    try
                    {
                        // 开始上传
                        param.ExcuteOnUploadItemStart(param.FileUploads[i]);

                        // request.Files.Get(param.FileUploads[i].ClientKey).SaveAs(_filePath);
                        using (FileStream fs = new FileStream(_filePath, FileMode.Create, FileAccess.ReadWrite))
                        {
                            using (BinaryWriter bw = new BinaryWriter(fs))
                            {
                                using (BinaryReader br = new BinaryReader(param.FileUploads[i].InputStream))
                                {
                                    while ((size = br.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        completed += size;
                                        bw.Write(buffer, 0, size);

                                        // 进度变化
                                        param.ExcuteOnUploadItemProgressChange(param.FileUploads[i], completed);
                                    }
                                }
                            }
                        }
                        // 上传完成
                        param.ExcuteOnUploadItemCompleted(param.FileUploads[i]);
                    }
                    catch (Exception ex)
                    {
                        // 上传出错
                        if (!param.ExcuteOnUploadItemFailedHandler(param.FileUploads[i], ex)) { throw ex; }
                    }
                }
            }
        }
 internal void ReadExtraData(BinaryReader reader)
 {
     if (this.extraSize > 0)
     {
         reader.Read(extraData, 0, extraSize);
     }
 }
Example #24
0
 public void WriteFontToStream(string fontPath, Stream outputStream)
 {
     lock (_accesslock)
     {
         int iCount;
         var buffer = new Byte[2048];
         if (!_cachedFonts.ContainsKey(fontPath))
         {
             var tempStream = new MemoryStream();
             using (var reader = new BinaryReader(File.OpenRead(fontPath)))
             {
                 while ((iCount = reader.Read(buffer, 0, 2048)) != 0)
                 {
                     tempStream.Write(buffer, 0, iCount);
                 }
             }
             _cachedFonts.Add(fontPath,tempStream);
         }
         MemoryStream fontStream = _cachedFonts[fontPath];
         fontStream.Seek(0, SeekOrigin.Begin);
         while ((iCount = fontStream.Read(buffer, 0, 2048)) != 0)
         {
             outputStream.Write(buffer,0, iCount);
         }
         
     }
 }
        public static ConnectionSettings Read(byte[] data)
        {
            var cs = new ConnectionSettings();
            using (var ms = new MemoryStream(data))
            using (var br = new BinaryReader(ms))
            {
                cs.Version = br.ReadInt32();
                cs.Counter = br.ReadInt32();
                cs.Autodetect = (Autodetect)br.ReadInt32();

                var len = br.ReadInt32();
                cs.ProxyServer = Utf8.GetString(br.ReadBytes(len));

                len = br.ReadInt32();
                cs.ExtraData = Utf8.GetString(br.ReadBytes(len));

                len = br.ReadInt32();
                cs.AutodetectScript = Utf8.GetString(br.ReadBytes(len));

                // So damn lazy.
                using (var ms2 = new MemoryStream())
                {
                    var ba = new byte[Environment.SystemPageSize];
                    while ((len = br.Read(ba, 0, ba.Length)) != 0)
                    {
                        ms2.Write(ba, 0, len);
                    }

                    cs.Junk = ms2.ToArray();
                }
            }

            return cs;
        }
Example #26
0
        /// <inheritdoc></inheritdoc>
        public override void ReadHeader()
        {
            byte[] header = new byte[176];
            using (Stream str = GetStream())
            {
                if (str == null) return;
                // Read important header content
                using (BinaryReader br = new BinaryReader(str))
                {
                    br.Read(header, 0, 176);
                }
            }

            PhiLam ll;
            ll.Phi = GetDouble(header, 24);
            ll.Lambda = -GetDouble(header, 72);

            double urPhi = GetDouble(header, 40);
            double urLam = -GetDouble(header, 56);

            PhiLam cs = new PhiLam();
            cs.Phi = GetDouble(header, 88);
            cs.Lambda = GetDouble(header, 104);

            NumLambdas = (int)(Math.Abs(urLam - ll.Lambda) / cs.Lambda + .5) + 1;
            NumPhis = (int)(Math.Abs(urPhi - ll.Phi) / cs.Phi + .5) + 1;
            ll.Lambda *= DEG_TO_RAD;
            ll.Phi *= DEG_TO_RAD;
            cs.Lambda *= DEG_TO_RAD;
            cs.Phi *= DEG_TO_RAD;

            LowerLeft = ll;
            CellSize = cs;
        }
Example #27
0
        public WebImage(Stream imageStream) {
            if (imageStream.CanSeek) {
                imageStream.Seek(0, SeekOrigin.Begin);

                _content = new byte[imageStream.Length];
                using (BinaryReader reader = new BinaryReader(imageStream)) {
                    reader.Read(_content, 0, (int)imageStream.Length);
                }
            }
            else {
                List<byte[]> chunks = new List<byte[]>();
                int totalSize = 0;
                using (BinaryReader reader = new BinaryReader(imageStream)) {
                    // Pick some size for chunks that is still under limit
                    // that causes them to be placed on the large object heap.
                    int chunkSizeInBytes = 1024 * 50;
                    byte[] nextChunk = null;
                    do {
                        nextChunk = reader.ReadBytes(chunkSizeInBytes);
                        totalSize += nextChunk.Length;
                        chunks.Add(nextChunk);
                    }
                    while (nextChunk.Length == chunkSizeInBytes);
                }

                _content = new byte[totalSize];
                int startIndex = 0;
                foreach (var chunk in chunks) {
                    chunk.CopyTo(_content, startIndex);
                    startIndex += chunk.Length;
                }
            }
            _initialFormat = ValidateImageContent(_content, "imageStream");
            _currentFormat = _initialFormat;
        }
Example #28
0
		/// <summary>
		/// Decompressed the data in the given stream.
		/// </summary>
		/// <param name="br">The stream containing the compressed data.</param>
		/// <param name="size">The number of byte to decompress.</param>
		/// <param name="outsize">The sixe of the decrompressed data.</param>
		/// <returns>A reader for the uncompressed data.</returns>
		protected static BinaryReader Decompress(BinaryReader br, int size, int outsize)
		{
			if (input.Length < size)
			{
				input = new byte[size];
			}
			if (output.Length < outsize)
			{
				output = new byte[outsize];
			}
			br.Read(input, 0, size);

			inf.SetInput(input, 0, size);
			try
			{
				inf.Inflate(output);
			}
			catch (ICSharpCode.SharpZipLib.SharpZipBaseException e)
			{
				//we ignore adler checksum mismatches, as I have a notion that they aren't always correctly
				// stored in the records.
				if (!e.Message.StartsWith("Adler"))
					throw e;
			}
			inf.Reset();

			ms.Position = 0;
			ms.Write(output, 0, outsize);
			ms.Position = 0;

			return compReader;
		}
Example #29
0
 public void CopyDatabase()
 {
     if (!File.Exists(dbPath)) //-------------------------------------------------------------------------Check if file exists
     {
         using (BinaryReader br = new BinaryReader(Assets.Open(dbName))) //-------------------------------if not opens database
         {
             try
             {
                 using (BinaryWriter bw = new BinaryWriter(new FileStream(dbPath, FileMode.Create))) //---writes file to phone
                 {
                     byte[] buffer = new byte[2048];
                     int len = 0;
                     while ((len = br.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         bw.Write(buffer, 0, len);
                     }
                 }
             }
             catch (Exception e)
             {
                 Console.WriteLine("{0} Exception caught.", e); //----------------------------------------write error to output
             }
         }
     }
 }
Example #30
0
        private void Load(BinaryReader br)
        {
            int length = br.ReadByte();

            if (this.Type == EventType.SystemExclusiveF0)
            {
                this.Data = new byte[length + 1];
                this.Data[0] = 0xf0;
                br.Read(this.Data, 1, length);
            }
            else
            {
                this.Data = new byte[length];
                br.Read(this.Data, 0, length);
            }
        }