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


C# System.IO.MemoryStream.Read方法代码示例

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


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

示例1: CreateZipByteArray

        /// <summary>
        /// Creates a zip archive from a byte array
        /// </summary>
        /// <param name="buffer">The file in byte[] format</param>
        /// <param name="fileName">The name of the file you want to add to the archive</param>
        /// <returns></returns>
        public static byte[] CreateZipByteArray(byte[] buffer, string fileName)
        {
            ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();

            using (System.IO.MemoryStream zipMemoryStream = new System.IO.MemoryStream())
            {
                ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipOutputStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(zipMemoryStream);

                zipOutputStream.SetLevel(6);

                ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(fileName);
                zipEntry.DateTime = DateTime.Now;
                zipEntry.Size = buffer.Length;

                crc.Reset();
                crc.Update(buffer);
                zipEntry.Crc = crc.Value;
                zipOutputStream.PutNextEntry(zipEntry);
                zipOutputStream.Write(buffer, 0, buffer.Length);

                zipOutputStream.Finish();

                byte[] zipByteArray = new byte[zipMemoryStream.Length];
                zipMemoryStream.Position = 0;
                zipMemoryStream.Read(zipByteArray, 0, (int)zipMemoryStream.Length);

                zipOutputStream.Close();

                return zipByteArray;
            }
        }
开发者ID:rsdgjb,项目名称:GRP,代码行数:37,代码来源:CommonExcelExport.cs

示例2: TestExtractArchiveTarGzCreateContainer

        public void TestExtractArchiveTarGzCreateContainer()
        {
            CloudFilesProvider provider = (CloudFilesProvider)Bootstrapper.CreateObjectStorageProvider();
            string containerName = TestContainerPrefix + Path.GetRandomFileName();
            string sourceFileName = "DarkKnightRises.jpg";
            byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (GZipOutputStream gzoStream = new GZipOutputStream(outputStream))
                {
                    gzoStream.IsStreamOwner = false;
                    gzoStream.SetLevel(9);
                    using (TarOutputStream tarOutputStream = new TarOutputStream(gzoStream))
                    {
                        tarOutputStream.IsStreamOwner = false;
                        TarEntry entry = TarEntry.CreateTarEntry(containerName + '/' + sourceFileName);
                        entry.Size = content.Length;
                        tarOutputStream.PutNextEntry(entry);
                        tarOutputStream.Write(content, 0, content.Length);
                        tarOutputStream.CloseEntry();
                        tarOutputStream.Close();
                    }
                }

                outputStream.Flush();
                outputStream.Position = 0;
                ExtractArchiveResponse response = provider.ExtractArchive(outputStream, "", ArchiveFormat.TarGz);
                Assert.IsNotNull(response);
                Assert.AreEqual(1, response.CreatedFiles);
                Assert.IsNotNull(response.Errors);
                Assert.AreEqual(0, response.Errors.Count);
            }

            using (MemoryStream downloadStream = new MemoryStream())
            {
                provider.GetObject(containerName, sourceFileName, downloadStream, verifyEtag: true);
                Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));

                downloadStream.Position = 0;
                byte[] actualData = new byte[downloadStream.Length];
                downloadStream.Read(actualData, 0, actualData.Length);
                Assert.AreEqual(content.Length, actualData.Length);
                using (MD5 md5 = MD5.Create())
                {
                    byte[] contentMd5 = md5.ComputeHash(content);
                    byte[] actualMd5 = md5.ComputeHash(actualData);
                    Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
                }
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
开发者ID:alanquillin,项目名称:openstack.net,代码行数:54,代码来源:UserObjectStorageTests.cs

示例3: Zip

 /********************************************************
 * CLASS METHODS
 *********************************************************/
 /// <summary>
 /// 
 /// </summary>
 /// <param name="zipPath"></param>
 /// <param name="filenamesAndData"></param>
 /// <returns></returns>
 public static bool Zip(string zipPath, System.Collections.Generic.Dictionary<string, string> filenamesAndData)
 {
     var success = true;
     var buffer = new byte[4096];
     try
     {
         using (var stream = new ZipOutputStream(System.IO.File.Create(zipPath)))
         {
             foreach (var filename in filenamesAndData.Keys)
             {
                 var file = filenamesAndData[filename].GetBytes();
                 var entry = stream.PutNextEntry(filename);
                 using (var ms = new System.IO.MemoryStream(file))
                 {
                     int sourceBytes;
                     do
                     {
                         sourceBytes = ms.Read(buffer, 0, buffer.Length);
                         stream.Write(buffer, 0, sourceBytes);
                     }
                     while (sourceBytes > 0);
                 }
             }
             stream.Flush();
             stream.Close();
         }
     }
     catch (System.Exception err)
     {
         System.Console.WriteLine("Compression.ZipData(): " + err.Message);
         success = false;
     }
     return success;
 }
开发者ID:rchien,项目名称:ToolBox,代码行数:43,代码来源:Compression.cs

示例4: ImageToByteArr

 /// <summary>
 /// 将图片转换成字节流
 /// </summary>
 /// <param name="img"></param>
 /// <returns></returns>
 private byte[] ImageToByteArr(Image img)
 {
     using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
     {
         img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
         ms.Position = 0;
         byte[] imageBytes = new byte[ms.Length];
         ms.Read(imageBytes, 0, imageBytes.Length);
         return imageBytes;
     }
 }
开发者ID:gofixiao,项目名称:HYPDM_Pro,代码行数:16,代码来源:DocQuery.cs

示例5: SerializeColumnInfo

 private static string SerializeColumnInfo(List<ColumnInfo> arr)
 {
     using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
     {
         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf =
             new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         bf.Serialize(stream, arr);
         stream.Position = 0;
         byte[] buffer = new byte[(int)stream.Length];
         stream.Read(buffer, 0, buffer.Length);
         return Convert.ToBase64String(buffer);
     }
 }
开发者ID:roxocode,项目名称:wether_diary,代码行数:13,代码来源:Serializer.cs

示例6: Save

 public void Save(Beetle.BufferWriter writer)
 {
     writer.Write(Message.GetType().FullName);
     byte[] data;
     using (System.IO.Stream stream = new System.IO.MemoryStream())
     {
         ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, Message);
         data = new byte[stream.Length];
         stream.Position = 0;
         stream.Read(data, 0, data.Length);
     }
     writer.Write(data);
 }
开发者ID:secondage,项目名称:projectxserver,代码行数:13,代码来源:ProtobufAdapter.cs

示例7: BitmapToBitMapImage

        public System.Windows.Media.Imaging.BitmapImage BitmapToBitMapImage(Bitmap bitmap)
        {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
            stream.Position = 0;
            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, Convert.ToInt32(stream.Length));
            BitmapImage bmapImage = new BitmapImage();
            bmapImage.BeginInit();
            bmapImage.StreamSource = stream;
            bmapImage.EndInit();

            return bmapImage;
        }
开发者ID:Ryanb58,项目名称:kMeansProject,代码行数:14,代码来源:ImageManipulation.cs

示例8: GZip

 public static byte[] GZip(this byte[] bytes)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     GZipStream gs = new GZipStream(ms, CompressionMode.Compress, true);
     gs.Write(bytes, 0, bytes.Length);
     gs.Close();
     gs.Dispose();
     ms.Position = 0;
     bytes = new byte[ms.Length];
     ms.Read(bytes, 0, (int)ms.Length);
     ms.Close();
     ms.Dispose();
     return bytes;
 }
开发者ID:EricKilla,项目名称:mcforge,代码行数:14,代码来源:Extensions.cs

示例9: GenerateCheckSum

        /// <summary>
        /// Generates a check sum from the serializable object.
        /// </summary>
        /// <param name="any">Any object that can be serialized.</param>
        /// <returns>A check sum.</returns>
        public static UInt16 GenerateCheckSum(object any)
        {
            System.Xml.Serialization.XmlSerializer xser = new System.Xml.Serialization.XmlSerializer(any.GetType());
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            xser.Serialize(ms, any);
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            byte[] streambytes = new byte[ms.Length];
            ms.Read(streambytes, 0, streambytes.Length);
            UInt16[] ckarray = OrcaLogic.Collections.ArrayConverter.ToUInt16(streambytes);
            ms.Close();

            ms = null;
            return OrcaLogic.Math.CheckSum.Generate(ckarray, ckarray.Length);
        }
开发者ID:snitsars,项目名称:pMISMOtraining,代码行数:21,代码来源:SerializationHelper.cs

示例10: GenerateCheckSum

        /// <summary>
        /// Generates a check sum from the serializable object.
        /// </summary>
        /// <param name="any">Any object that can be serialized.</param>
        /// <returns>A check sum.</returns>
        public static UInt16 GenerateCheckSum(object any)
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            bf.Serialize(ms, any);
            ms.Seek(0,System.IO.SeekOrigin.Begin);

            byte[] streambytes = new byte[ms.Length];
            ms.Read(streambytes, 0, streambytes.Length);
            UInt16[] ckarray = OrcaLogic.Collections.ArrayConverter.ToUInt16(streambytes);
            ms.Close();

            ms = null;
            bf = null;
            return OrcaLogic.Math.CheckSum.Generate(ckarray, ckarray.Length);
        }
开发者ID:snitsars,项目名称:pMISMOtraining,代码行数:22,代码来源:SerializationHelper.cs

示例11: ProcessRequest

        //***************************************************************************
        // Public Methods
        // 
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest req = context.Request;

            string
                qsImgUrl = req.QueryString["src"],
                qsAct = req.QueryString["a"];

            bool buttonActive = (string.IsNullOrEmpty(qsAct) || qsAct == "1");
            string srcUrl = WebUtil.MapPath(WebUtil.UrlDecode(qsImgUrl));

            System.IO.FileInfo fiImg = new System.IO.FileInfo(srcUrl);
            if (!fiImg.Exists)
            { context.Response.StatusCode = 404; }
            else
            {
                byte[] imgData = null;
                string contentType = string.Format("image/{0}", fiImg.Extension.TrimStart('.'));
                using (System.IO.FileStream fs = fiImg.OpenRead())
                {
                    if (buttonActive)
                    {
                        // If the button is active, just load the image directly.
                        imgData = new byte[fs.Length];
                        fs.Read(imgData, 0, imgData.Length);
                    }
                    else
                    {
                        // If the button is disabled, load the image into a Bitmap object, then run it through the grayscale filter.
                        using (System.Drawing.Bitmap img = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(fs))
                        using (System.Drawing.Bitmap imgGs = RainstormStudios.Drawing.BitmapFilter.GrayScale(img))
                        using(System.IO.MemoryStream imgGsStrm = new System.IO.MemoryStream())
                        {
                            imgGs.Save(imgGsStrm, img.RawFormat);
                            imgData = new byte[imgGsStrm.Length];
                            imgGsStrm.Read(imgData, 0, imgData.Length);
                        }
                    }
                }

                context.Response.StatusCode = 200;
                context.Response.ContentType = contentType;
                context.Response.OutputStream.Write(imgData, 0, imgData.Length);

            }
        }
开发者ID:tenshino,项目名称:RainstormStudios,代码行数:49,代码来源:ToolbarImageHandler.cs

示例12: SerializeObjectToBytes

        /// <summary>
        /// 
        /// </summary>
        /// <param name="objectNeedSerialized"></param>
        /// <param name="formatType"></param>
        /// <returns></returns>
        public static byte[] SerializeObjectToBytes(object objectNeedSerialized,SeralizeFormatType formatType)
        {
            System.Runtime.Serialization.IFormatter oFormatter = null;

            if (formatType == SeralizeFormatType.BinaryFormat)
                oFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            else if (formatType == SeralizeFormatType.XmlFortmat)
                oFormatter = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();

            System.IO.MemoryStream oStream = new System.IO.MemoryStream();

            oFormatter.Serialize(oStream, objectNeedSerialized);

            byte[] oBuffer = new byte[oStream.Length];
            oStream.Position = 0;
            oStream.Read(oBuffer, 0, oBuffer.Length);

            return oBuffer;
        }
开发者ID:uwitec,项目名称:gvms,代码行数:25,代码来源:ObjectSerialize.cs

示例13: Index

        //
        // GET: /QR/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="qrUrl"></param>
        /// <returns></returns>
        public ImageResult Index(string qrUrl)
        {
            using (var bitmap = EncodeUrl(qrUrl))
            {
                const string contentType = "image/jpg";

                byte[] data;
                using (var stream = new System.IO.MemoryStream())
                {
                    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    stream.Position = 0;
                    data = new byte[stream.Length];
                    stream.Read(data, 0, (int)stream.Length);
                    stream.Close();
                }

                return this.Image(data, contentType);

            }
        }
开发者ID:andrewolobo,项目名称:overtly-clutz3,代码行数:27,代码来源:QrController.cs

示例14: decriptUrl

        public static string decriptUrl(string Valor)
        {
            string Chave = "#[email protected]!s#";

            Valor = Valor.Replace("MAIS", "+");
            TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
            des.IV = new byte[8];
            PasswordDeriveBytes pdb = new PasswordDeriveBytes(Chave, new byte[-1 + 1]);
            des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
            byte[] encryptedBytes = Convert.FromBase64String(Valor);
            System.IO.MemoryStream MS = new System.IO.MemoryStream(Valor.Length);
            CryptoStream decStreAM = new CryptoStream(MS, des.CreateDecryptor(), CryptoStreamMode.Write);
            decStreAM.Write(encryptedBytes, 0, encryptedBytes.Length);
            decStreAM.FlushFinalBlock();
            byte[] plainBytes = new byte[Convert.ToInt32(MS.Length - 1) + 1];
            MS.Position = 0;
            MS.Read(plainBytes, 0, Convert.ToInt32(MS.Length));
            decStreAM.Close();
            return System.Text.Encoding.UTF8.GetString(plainBytes);
        }
开发者ID:willianleal,项目名称:AgenciaNoticiaN,代码行数:20,代码来源:Util.cs

示例15: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            response.Clear();
            response.ContentType = MimiType;
            response.AddHeader("content-disposition", String.Format("attachment;filename={0}.{1}", ReportName, FileExt));

            byte[] buf = new byte[32768];
            using (var spreadsheet = new System.IO.MemoryStream(RenderBytes))
            {
                while (true)
                {
                    int read = spreadsheet.Read(buf, 0, buf.Length);
                    if (read <= 0)
                        break;
                    response.OutputStream.Write(buf, 0, read);
                }
            }

            response.Flush();
        }
开发者ID:hash2000,项目名称:WorkTime,代码行数:21,代码来源:ReportResult.cs


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