当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadBytes方法代码示例

本文整理汇总了C#中BinaryReader.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadBytes方法的具体用法?C# BinaryReader.ReadBytes怎么用?C# BinaryReader.ReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VoxelData

 public VoxelData(string name, Material[] materials)
 {
     TextAsset asset = (TextAsset)Resources.Load("Meta/" + name);
     MemoryStream ms = new MemoryStream(asset.bytes);
     BinaryReader reader = new BinaryReader(ms);
     x_size = reader.ReadUInt32();
     z_size = reader.ReadUInt32();
     y_size = reader.ReadUInt32();
     x_offset = reader.ReadInt32();
     z_offset = reader.ReadInt32();
     y_offset = reader.ReadInt32();
     data = reader.ReadBytes((int)(x_size * y_size * z_size));
     byte[] raw_palette = reader.ReadBytes(256*3);
     palette = new Material[256];
     for (int i = 0; i < 256; i++) {
         float r = raw_palette[i*3] / 255.0f;
         float g = raw_palette[i*3+1] / 255.0f;
         float b = raw_palette[i*3+2] / 255.0f;
         Material result = null;
         foreach (Material mat in materials) {
             if (mat.color.r == r && mat.color.g == g && mat.color.b == b) {
                 result = mat;
                 break;
             }
         }
         palette[i] = result;
     }
 }
开发者ID:carriercomm,项目名称:voxie,代码行数:28,代码来源:AnimateScript.cs

示例2: LoadGameSave

    public static GameDataContainer LoadGameSave()
    {
        GameDataContainer data = new GameDataContainer ();

        // Ensure that the file exists, else returns
        if (!File.Exists ("Data/SaveGame.dat"))
            return data;

        using (BinaryReader br = new BinaryReader(File.OpenRead("Data/SaveGame.dat")))
        {
            br.ReadBytes(10); // Header

            int moneyBytes = br.ReadInt32(); // sizeof (money)
            data.Money = new BigInteger(Encoding.ASCII.GetString(br.ReadBytes(moneyBytes))); // money

            // Loop for product data
            for (int i = 0; i < (int)Products.Max; i++)
            {
                int level;
                level = br.ReadInt32();

                data.ProdList[i] = level;
            }

            int upgradeCount = br.ReadInt32();
            for (int i = 0; i < upgradeCount; i++) {
                int upId = br.ReadInt32();
                data.AcquiredUpgrades.Add(upId);
            }
        }

        return data;
    }
开发者ID:guilherme-gm,项目名称:numbers-game,代码行数:33,代码来源:GameLoader.cs

示例3: WaveAudio

            /// <summary>
            /// Initializes this WaveAudio object with Wave audio file.
            /// </summary>
            /// <param name="filepath">Path of Wave Audio file.</param>
            public WaveAudio(FileStream filepath)
            {
                this.fs = filepath;
                this.br = new BinaryReader(fs);

                this.riffID = br.ReadBytes(4);
                this.size = br.ReadUInt32();
                this.wavID = br.ReadBytes(4);
                this.fmtID = br.ReadBytes(4);
                this.fmtSize = br.ReadUInt32();
                this.format = br.ReadUInt16();
                this.channels = br.ReadUInt16();
                this.sampleRate = br.ReadUInt32();
                this.bytePerSec = br.ReadUInt32();
                this.blockSize = br.ReadUInt16();
                this.bit = br.ReadUInt16();
                this.dataID = br.ReadBytes(4);
                this.dataSize = br.ReadUInt32();

                this.leftStream = new List<short>();
                this.rightStream = new List<short>();
                for (int i = 0; i < this.dataSize / this.blockSize; i++)
                {
                    leftStream.Add((short)br.ReadUInt16());
                    rightStream.Add((short)br.ReadUInt16());
                }

                br.Close();
                fs.Close();
            }
开发者ID:kushalpandya,项目名称:WavStagno,代码行数:34,代码来源:WaveAudio.cs

示例4: Parse

    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseConvergePriorAttempt response = new ResponseConvergePriorAttempt();

        using (BinaryReader br = new BinaryReader(dataStream, Encoding.UTF8)) {
            int playerId = br.ReadInt32 ();
            int ecosystemId = br.ReadInt32 ();
            int attemptId = br.ReadInt32 ();
            bool allowHints = br.ReadBoolean ();
            int hintId = br.ReadInt32 ();
            short fldSize = br.ReadInt16 ();
            String config = System.Text.Encoding.UTF8.GetString (br.ReadBytes (fldSize));
            fldSize = br.ReadInt16 ();
            String csv = System.Text.Encoding.UTF8.GetString (br.ReadBytes (fldSize));

            ConvergeAttempt attempt = new ConvergeAttempt (playerId,
                                                           ecosystemId,
                                                           attemptId,
                                                           allowHints,
                                                           hintId,
                                                           config,
                                                           csv
                                                           //null
                                                           );

            response.attempt = attempt;
        }

        return response;
    }
开发者ID:hunvil,项目名称:ConvergeGame_Client,代码行数:30,代码来源:ConvergePriorAttemptProtocol.cs

示例5: SFOParser

    public SFOParser(string filePath)
    {
        FileAttributes attr = File.GetAttributes(filePath);

        //detect whether its a directory or file
        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            throw new Exception("不是正確的SFO檔");
        this.filePath = filePath;
        BinaryReader bs = new BinaryReader(new FileStream(filePath, FileMode.Open));
        byte[] tmpbuffer = bs.ReadBytes(Marshal.SizeOf(typeof(PsfHdr)));
        GCHandle handle = GCHandle.Alloc(tmpbuffer, GCHandleType.Pinned);
        psfHdr = (PsfHdr)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PsfHdr));
        handle.Free();

        if (!Enumerable.SequenceEqual( psfHdr.psf, new char[] {'\0','P', 'S', 'F'})) {
            throw new Exception("不是正確的SFO檔");
        }
        #if DEBUG
        Console.WriteLine("{0}個區塊", psfHdr.nsects);
        #endif
        psfSec = new PsfSec[psfHdr.nsects];
        for (int i = 0; i < psfHdr.nsects; i++) {
            tmpbuffer = bs.ReadBytes(Marshal.SizeOf(typeof(PsfSec)));
            handle = GCHandle.Alloc(tmpbuffer, GCHandleType.Pinned);
            psfSec[i] = (PsfSec)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PsfSec));
            handle.Free();
        }

        pairs = new SFOPair[psfHdr.nsects];
        for (int i = 0; i < psfHdr.nsects; i++) {
            bs.BaseStream.Position = psfSec[i].label_off + psfHdr.label_ptr;
            tmpbuffer = readByteString(bs);
            pairs[i] = new SFOPair();
            pairs[i].label = encode.GetString(tmpbuffer);
            pairs[i].psfsec = psfSec[i];
            bs.BaseStream.Position = psfSec[i].data_off + psfHdr.data_ptr;
            tmpbuffer = bs.ReadBytes(psfSec[i].datafield_used);
            pairs[i].type = psfSec[i].data_type;
            switch (psfSec[i].data_type) {
                case 0:
                    pairs[i].value = tmpbuffer;
                    break;
                case 2:
                    pairs[i].value = encode.GetString(tmpbuffer);
                    break;
                case 4:
                    pairs[i].value = BitConverter.ToInt32(tmpbuffer, 0);
                    break;
                default:
                    break;
            }
        #if DEBUG
            Console.WriteLine("Label:{0}, Type:{1:X}, Value:{2}", pairs[i].label, pairs[i].type, pairs[i].value);
        #endif
        }

        bs.Close();
    }
开发者ID:darkautism,项目名称:KautismSFOEditor,代码行数:58,代码来源:SFOParser.cs

示例6: SetExpertMode

 private static void SetExpertMode(string source, string dest, bool expertMode)
 {
     BinaryReader reader = new BinaryReader(new FileStream(source, FileMode.Open));
     int version = reader.ReadInt32();
     if (version < 149) {
         MessageBox.Show("Error: Outdated terraria version");
         return;
     }
     ulong magic = reader.ReadUInt64();
     if ((magic & 72057594037927935uL) != 27981915666277746uL) {
         MessageBox.Show("Error: Invalid header");
         return;
     }
     // Skip other file metadata...
     reader.ReadBytes(12);
     int positionCount = reader.ReadInt16();
     int afterMetadataPos = reader.ReadInt32();
     int afterHeaderPos = reader.ReadInt32();
     // Skip positions...
     reader.ReadBytes((positionCount - 2) * 4);
     // Skip frame importance...
     reader.ReadBytes(reader.ReadInt16() / 8 + 1);
     if (reader.BaseStream.Position != afterMetadataPos) {
         MessageBox.Show("After Metadata Position Mismatch: expected " +
             afterMetadataPos + ", was " + reader.BaseStream.Position);
         return;
     }
     // Skip the first part of the header...
     reader.ReadString();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     // Get the offset...
     long expertModeFlagOffset = reader.BaseStream.Position;
     bool wasExpertMode = reader.ReadBoolean();
     reader.Dispose();
     // Notify the user if the world is changed...
     if (wasExpertMode == expertMode) {
         MessageBox.Show(expertMode ? "World was already Expert Mode." : "World was already not Expert Mode.");
         return;
     }
     BinaryWriter writer = new BinaryWriter(new FileStream(dest, FileMode.Open));
     writer.BaseStream.Position = expertModeFlagOffset;
     writer.Write(expertMode);
     writer.Dispose();
     MessageBox.Show(expertMode ? "World is now Expert Mode!" : "World is no longer Expert Mode!");
 }
开发者ID:antag99,项目名称:TNoob,代码行数:51,代码来源:TNoob.cs

示例7: SaveToDisk

	public static void SaveToDisk(string resourceName, string fileName)
	{
		// Get a reference to the running application.
		Assembly assy = Assembly.GetExecutingAssembly();
		// Loop through each resource, looking for the image name (case-insensitive).
		foreach (string resource in assy.GetManifestResourceNames()) {
			if (resource.ToLower().IndexOf(resourceName.ToLower()) != -1) {
				// Get the embedded file from the assembly as a MemoryStream.
				using (System.IO.Stream resourceStream = assy.GetManifestResourceStream(resource)) {
					if (resourceStream != null) {
						using (BinaryReader reader = new BinaryReader(resourceStream)) {
							// Read the bytes from the input stream.
							byte[] buffer = reader.ReadBytes(Convert.ToInt32(resourceStream.Length));
							using (FileStream outputStream = new FileStream(fileName, FileMode.Create)) {
								using (BinaryWriter writer = new BinaryWriter(outputStream)) {
									// Write the bytes to the output stream.
									writer.Write(buffer);
								}
							}
						}
					}
				}
				break; // TODO: might not be correct. Was : Exit For
			}
		}
	}
开发者ID:bobbytdotcom,项目名称:iFaith,代码行数:26,代码来源:modFile.cs

示例8: btnUpload_Click

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);

        string GetExts = Path.GetExtension(filename);

        Stream str = fileUpload1.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(str);
        Byte[] size = br.ReadBytes((int)str.Length);

        using (ROPAEntities obj = new ROPAEntities())
        {
            UploadFile upld = new UploadFile();

            upld.GUID = Guid.NewGuid().ToString();
            //upld.FIleFor=100;
            upld.FIleFor = filename;
            upld.SurApp_Id = 47;
            upld.fileext = GetExts;

            obj.AddToUploadFiles(upld);
            obj.SaveChanges();
        }
        BindGridviewData();
    }
开发者ID:vanisandeep,项目名称:yogyata,代码行数:25,代码来源:InsertFile.aspx.cs

示例9: JoinFile

    public static void JoinFile(string inputFile, string outputFile, KsSplitJoinHandler handler)
    {
        long rwIncrament=500000;//updateInterval=400000, updateIndex=0;
        FileInfo fInfo=new FileInfo(inputFile);
        long iLen=fInfo.Length;
        FileStream ifs=new FileStream(inputFile, FileMode.Open);
        BinaryReader reader=new BinaryReader(ifs);
        //bool cont;

        FileInfo fi=new FileInfo(outputFile);
        FileMode fm=FileMode.Append;
        if(!fi.Exists) fm=FileMode.CreateNew;
        FileStream ofs=new FileStream(outputFile, fm);
        BinaryWriter writer=new BinaryWriter(ofs);

        long i=0, cnt;
        while(i<iLen) {
            cnt=rwIncrament;
            if((i+cnt)>=iLen) cnt=iLen-i;
            //byte val[cnt];
            writer.Write(reader.ReadBytes((int)cnt));
            i+=cnt;
            if(!handler.OnUpdate(inputFile, outputFile, i, iLen)) {
                ifs.Close(); reader.Close();
                ofs.Close(); writer.Close();
                handler.OnCanceled(inputFile, outputFile, i, iLen);
                return;
            }
        }

        ifs.Close(); reader.Close();
        ofs.Close(); writer.Close();
        handler.OnFinished(inputFile, outputFile, i, iLen);
    }
开发者ID:erin100280,项目名称:KnifeSpan,代码行数:34,代码来源:KsJoiner.cs

示例10: ResponseFile

 public bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullUrl, long _speed)
 {
     try
     {
         FileStream myFile = new FileStream(_fullUrl, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         BinaryReader br = new BinaryReader(myFile);
         try
         {
             _Response.AddHeader("Accept-Ranges", "bytes");
             _Response.Buffer = false;
             long fileLength = myFile.Length;
             long startBytes = 0;
             int pack = 10240; //10K bytes
             int sleep = (int)Math.Floor((double)(1000 * pack / _speed)) + 1;
             if (_Request.Headers["Range"] != null)
             {
                 _Response.StatusCode = 206;
                 string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
                 startBytes = Convert.ToInt64(range[1]);
             }
             _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
             if (startBytes != 0)
             {
                 _Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
             }
             _Response.AddHeader("Connection", "Keep-Alive");
             _Response.ContentType = "application/octet-stream";
             _Response.AddHeader("Content-Disposition", "attachment;filename="
                                 + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));
             br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
             int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1;
             for (int i = 0; i < maxCount; i++)
             {
                 if (_Response.IsClientConnected)
                 {
                     _Response.BinaryWrite(br.ReadBytes(pack));
                     Thread.Sleep(sleep);
                 }
                 else
                 {
                     i = maxCount;
                 }
             }
         }
         catch
         {
             return false;
         }
         finally
         {
             br.Close();
             myFile.Close();
         }
     }
     catch
     {
         return false;
     }
     return true;
 }
开发者ID:Raistlin97,项目名称:demo-projects,代码行数:60,代码来源:downloading.aspx.cs

示例11: loadImage

    void loadImage(string name)
    {
        using (BinaryReader b = new BinaryReader(File.Open(name, FileMode.Open,FileAccess.Read,FileShare.Read)))
        {
            // 2.
            // Position and length variables.
            int i = 0;
            // Use BaseStream.
            int length = (int)b.BaseStream.Length;
            int w= b.ReadInt32(),h= b.ReadInt32(),format =  b.ReadInt32();

            texture = new Texture2D (w,h,TextureFormat.RFloat,false);

            byte[] data = b.ReadBytes(w*h*format*4);

            Debug.Log("Read Ima "+data.Length);
            texture.LoadRawTextureData(data);
            texture.Apply();
            Debug.Log ("Channels "+texture.format);
            ccc.callbackLoadImage(w,h);
        }

        GetComponent<Renderer> ().material.mainTexture = texture;
        // GetComponent<Renderer> ().material.SetTexture (2, texture);
        Debug.Log ("Channels "+texture.format);
    }
开发者ID:savashito,项目名称:bayesCraterModeling,代码行数:26,代码来源:ImageCrater.cs

示例12: btnUpload_Click

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            var filename = Path.GetFileName(fileUpload1.PostedFile.FileName);

            var getExts = Path.GetExtension(filename);

            var str = fileUpload1.PostedFile.InputStream;
            var br = new BinaryReader(str);
            var size = br.ReadBytes((int) str.Length);

            using (var obj = new ROPAEntities())
            {
                var upld = new UploadFile();
                upld.GUID = Guid.NewGuid().ToString();
                upld.AppVersion = (decimal) 2.30;

                upld.FIleFor = filename;
                upld.SurApp_Id = 47;
                upld.fileext = getExts;

                obj.AddToUploadFiles(upld);
                obj.SaveChanges();
            }
            BindGridviewData();
        }
        catch (Exception)
        {

        }
    }
开发者ID:vanisandeep,项目名称:yogyata,代码行数:32,代码来源:InsertFile.aspx.cs

示例13: btnGuardarNotificacion_Click

    protected void btnGuardarNotificacion_Click(object sender, EventArgs e)
    {
        String textoValidacion = validarNotificacion(false);
        if (textoValidacion.Equals(""))
        {
            Stream fs = upFileNotificacion.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);

            ARCHIVO archivo = new ARCHIVO();
            archivo = archivo.addArchivo(Path.GetFileName(upFileNotificacion.PostedFile.FileName),
                                         Path.GetExtension(upFileNotificacion.PostedFile.FileName).Substring(1), bytes);

            if (archivo.ARCHIVOID != 0)
            {
                NOTIFICACION notificacion = new NOTIFICACION();
                notificacion.addNotificacion(txtNombreNotificacion.Text, txtDescripcionNotificacion.Text, archivo.ARCHIVOID,
                                             Convert.ToInt32(lblInstitucionId.Text));
                cargarNotificaciones();
                lblSucess.Text = "Se creo Correctamente la Notificacion";
                pnlSucess.Visible = true;
            }
            else
            {
                lblError.Text = "El archivo es demasiado pesado";
                pnlError.Visible = true;
            }

        }
        else
        {
            lblError.Text = textoValidacion;
            pnlError.Visible = true;
        }
    }
开发者ID:fabianpsilvam,项目名称:instituciones,代码行数:35,代码来源:Notificacion.aspx.cs

示例14: loadSaveData

    public void loadSaveData(int id)
    {
        currentFlag.SetAll(false);

        //load file
        string filepath = string.Format("{0}/sav{1}", Application.persistentDataPath, id);
        Debug.Log(filepath);

        if (!File.Exists(filepath))
        {
            //show error
            return;
        }

        FileStream fs = File.Open(filepath, FileMode.Open);

        BinaryReader reader = new BinaryReader(fs);
        currentID = reader.ReadInt32();
        byte[] buf = reader.ReadBytes(10);
        currentFlag = new BitArray(buf);

        for (int i = (int)GameValueType.None; i < (int)GameValueType.Max; i++ )
        {
            values[(GameValueType)i] = reader.ReadInt32();
        }

        fs.Flush();
        fs.Close();

        startGame();
    }
开发者ID:ancongsheng,项目名称:vu_paradox,代码行数:31,代码来源:MainGame.cs

示例15: ExtractFile

	public static void ExtractFile(ListViewFileItem lvi, string exeName, string outName)
	{
		//extract file in ListViewFileItem
		FileStream fsIn = null;
		BinaryReader brIn = null;
		FileStream fsOut = null;
		BinaryWriter bwOut = null;
		try
		{
			fsIn = new FileStream(exeName, FileMode.Open);
			brIn = new BinaryReader(fsIn);
			fsOut = new FileStream(outName, FileMode.Create);
			bwOut = new BinaryWriter(fsOut);
			fsIn.Seek(lvi.Offset, SeekOrigin.Begin);
			bwOut.Write(brIn.ReadBytes(lvi.Size));
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
		}
		finally
		{
			if (brIn != null)
				brIn.Close();
			if (fsIn != null)
				fsIn.Close();
			if (bwOut != null)
				bwOut.Close();
			if (fsOut != null)
				fsOut.Close();
		}
	}
开发者ID:winch,项目名称:winch.pinkbile.com-c-sharp,代码行数:32,代码来源:proExe.cs


注:本文中的BinaryReader.ReadBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。