Tag: bytearray

c#在FTP服务器中上传一个byte

我需要上传一些DATA和FTP服务器。 关于如何上传FILE内容和FTP一切正常的stackoverflowpost。 现在我正在努力改善我的上传。 而是收集DATA,将它们写入FILE然后在FTP中上传文件我想收集DATA并上传它们而不创建本地文件。 为此,我执行以下操作: string uri = “ftp://” + ftpServerIp + “/” + fileToUpload.Name; System.Net.FtpWebRequest reqFTP; // Create FtpWebRequest object from the Uri provided reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(“ftp://” + ftpServerIp + “/” + fileToUpload.Name)); // Provide the WebPermission Credintials reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); // By default KeepAlive is true, where the control connection […]

是否有一个函数在C#中为字节数组做圆形位移?

我似乎无法找到是否有内置的方法来执行字节数组的循环位移,C的ROL和ROR用于单个字节? 让我解释一下,比方说,我有一个数组(二进制): [0] = 11001110 [1] = 01000100 [2] = 10100001 然后如果我想做ROL_Array(1 bit)或向左移动1位,我会得到: [0] = 10011100 [1] = 10001001 [2] = 01000011 或者,如果我想做ROR_Array(2 bits)或向右移动2位,我会得到: [0] = 00110011 [1] = 01010001 [2] = 10101000

是否有更快的方式来循环数千个项目?

假设我有一个包含100,000个字节的字节数组。 我想将每个字节转换为其自身的文本表示。 例如: byte[] b = new byte[55000]; for(int i = 0; i < b.Length; i++) { Console.WriteLine(ConvertToString(b[i])); } 上面的代码需要大约35秒才能完成,有什么方法可以将其减少到大约5秒钟吗?

c#socket接收字节数组长度

我正在尝试学习在c#中使用套接字,我有一个疑问,我正在使用这样的代码: byte[] data = new byte[64]; int length = 0; length = sock.Receive(data); //more code… 因此, byte[]数据用回收数据填充,数组中的左边空格用0填充, byte[]是否完全分配到内存中(所有64字节)? 如果是这样,有没有办法使byte[]与实际发送的数据大小相同?

将非可序列化类转换为字节数组

我有一个场景,我在多个非常不同的系统之间同步数据。 (数据本身很相似,但不同系统上的表格格式完全不同。)为了协助这种同步,我有一个数据库表,它存储来自每个系统的对象哈希值以及项目键和其他相关信息。 当来自任一系统的对象的散列改变时,我更新另一个。 我的数据库表看起来像这样。 CREATE TABLE [dbo].[SyncHashes]( [SyncHashId] [int] IDENTITY(1,1) NOT NULL, [ObjectName] [nvarchar](50) NULL, [MappingTypeValue] [nvarchar](25) NULL, [MappingDirectionValue] [nvarchar](25) NULL, [SourceSystem] [nvarchar](50) NULL, [SourceKey] [nvarchar](200) NULL, [SourceHash] [nvarchar](50) NULL, [TargetSystem] [nvarchar](50) NULL, [TargetKey] [nvarchar](200) NULL, [TargetHash] [nvarchar](50) NULL, [UpdateNeededValue] [nvarchar](max) NULL, [CreatedOn] [datetime] NULL, [ModifiedOn] [datetime] NULL, [Version] [timestamp] NOT NULL, [IsActive] [bit] NOT […]

如何使用SqlDataReader重新填充字节数组?

这是参考: byte []并通过引用有效传递 并且在这篇文章中找到了SqlDataReader : 使用SqlDataReader获取二进制数据 在循环中,我正在调用数据库并返回一个大对象( varbinary[max] )。 目前,我OutOfMemoryexception,所以我试图减少大对象堆(LOH)中的占用空间。 所以,我正在为我下载的最大文件创建一个字节数组,并添加一些填充以防万一。 例如: byte[] currentFile = new byte[largestFileSize * 1.1]; 然后我传递这个currentFile数据库方法。 目前,我们使用EnterpriseLibrary来访问数据库: DbCommand storedProcedure = MedicareDatabase.Db.GetStoredProcCommand(spName); storedProcedure.CommandTimeout = 5000; if (parameters != null) { foreach (Param parameter in parameters) { if (parameter != null) { MedicareDatabase.Db.AddInParameter(storedProcedure, parameter.ParameterName, parameter.DbType, parameter.Value); } } } try { BinaryWriter bw; […]

将多个图像文件发送到mySQL

如何使用C#将多个jpg文件(如字节数组)发送到mySQL数据库? 我已经阅读并理解了如何将图像文件转换为字节数组,但我只能弄清楚如何将单个图像的方法作为一个blob用于mySQL。 我的应用程序要求用户上传至少2个图像文件,并允许最多10个,同时从多个textBox发送信息。 我尝试创建一个字节数组数组,但这不起作用。 当我在mySQL的INSERT字符串期间在特定索引处引用该数组时,它似乎只存储一个字节数组并引用该字节数组的索引而不是应该存储在该索引中的整个字节数组。 下面是一些显示我的尝试的代码: ///uploading the image and converting it to a byte array private void uploadButtonClick(object sender, RoutedEventArgs e) { chosenFileTextBox.Text = “No file chosen”; try { FileStream fs = new FileStream(imageFileNameArray[i], FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); imageFileArray = br.ReadBytes((int)fs.Length); ///Array of byte arrays imageArray[i] = imageFileArray; uploadedFilesTextBox.Text += imageFileSafeNameArray[i].ToString() […]

BitmapFactory.DecodeByteArray导致Grow Heap(frag case)

我正在开发Xamarin的Android应用程序。 我在从字节流生成图像时遇到问题。 BitmapFactory(这似乎是最流行的解决方案)正在造成巨大的分配问题 – Grow Heap。 ConnectToDb connect = new ConnectToDb (); byte[] arr = connect.SelectImgByte(3,”Thea”); BitmapFactory.Options options=new BitmapFactory.Options(); options.InJustDecodeBounds = true; bmp = BitmapFactory.DecodeByteArray (arr, 0, arr.Length/*,options*/); _imageView.SetImageBitmap (bmp); 以上是调用BitmapFactory.DecodeByteArray的方法。 它工作正常,显示图像。 但它很慢并导致这些“警告”。 Thread started: #6 [dalvikvm-heap] Grow heap (frag case) to 22.596MB for 1997584-byte allocation [Choreographer] Skipped 129 frames! The application may be doing […]

从servermap路径上的字节数组中保存文件

我想从字节数组中保存PDF文件,并希望将该文件保存在我的服务器地图路径位置。 下面是我的代码片段。 它没有给出错误也没有保存文件。 如果它是错误的,欢迎您更正我的语法,或者通过引用其他代码片段来帮助我。 byte[] data = (byte[])listDataset.Tables[0].Rows[0][0]; System.IO.FileStream file = System.IO.File.Create(Server.MapPath(“.\\TmpImages\\”+hfFileName+”.pdf “)); file.Write(data, 0, data.Length); file.Close();

有效地转换音频字节 – byte 到short

我正在尝试使用XNA麦克风捕获音频并将其传递给我分析数据用于显示目的的API。 但是,API需要16位整数数组中的音频数据。 所以我的问题相当直截了当; 什么是将字节数组转换为短数组的最有效方法? private void _microphone_BufferReady(object sender, System.EventArgs e) { _microphone.GetData(_buffer); short[] shorts; //Convert and pass the 16 bit samples ProcessData(shorts); } 干杯,戴夫 编辑 :这是我提出的,似乎工作,但它可以更快地完成吗? private short[] ConvertBytesToShorts(byte[] bytesBuffer) { //Shorts array should be half the size of the bytes buffer, as each short represents 2 bytes (16bits) short[] shorts = new short[bytesBuffer.Length / […]