|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果需要重新编写代码,几乎任何一门计算机语言都可以跨平台了,还用得着Java嘛,而且像PHP/C#等语言不需要修改代码都可以跨Windows/Linux。asp.net|上传 在项目中常常要用到了年夜文件上传,要上传的文件有100多m,因而研讨如今国际利用的年夜文件上传的组件发明用的对照多的有两个控件AspnetUpload2.0和Lion.Web.UpLoadModule,两个控件的办法是:使用隐含的HttpWorkerRequest,用它的GetPreloadedEntityBody和ReadEntityBody办法从IIS为ASP.NET创建的pipe里分块读取数据。ChrisHynes为我们供应了如许的一个计划(用HttpModule),该计划除同意你上传年夜文件外,还能及时显现上传进度。
Lion.Web.UpLoadModule和AspnetUpload两个.NET组件都是使用的这个计划。
当上传单文件时,两个软件的办法是一样的,承继HttpModule
HttpApplicationapplication1=senderasHttpApplication;
HttpWorkerRequestrequest1=(HttpWorkerRequest)((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest));
try
{
if(application1.Context.Request.ContentType.IndexOf("multipart/form-data")<=-1)
{
return;
}
//CheckTheHasEntityBody
if(!request1.HasEntityBody())
{
return;
}
intnum1=0;
TimeSpanspan1=DateTime.Now.Subtract(this.beginTime);
stringtext1=application1.Context.Request.ContentType.ToLower();
byte[]buffer1=Encoding.ASCII.GetBytes(("
--"+text1.Substring(text1.IndexOf("boundary=")+9)).ToCharArray());
intnum2=Convert.ToInt32(request1.GetKnownRequestHeader(11));
Progressprogress1=newProgress();
application1.Context.Items.Add("FileList",newHashtable());
byte[]buffer2=request1.GetPreloadedEntityBody();
num1+=buffer2.Length;
stringtext2=this.AnalysePreloadedEntityBody(buffer2,"UploadGUID");
if(text2!=string.Empty)
{
application1.Context.Items.Add("LionSky_UpLoadModule_UploadGUID",text2);
}
boolflag1=true;
if((num2>this.UpLoadFileLength())&&((0>span1.TotalHours)||(span1.TotalHours>3)))
{
flag1=false;
}
if((0>span1.TotalHours)||(span1.TotalHours>3))
{
flag1=false;
}
stringtext3=this.AnalysePreloadedEntityBody(buffer2,"UploadFolder");
ArrayListlist1=newArrayList();
RequestStreamstream1=newRequestStream(buffer2,buffer1,null,RequestStream.FileStatus.Close,RequestStream.ReadStatus.NoRead,text3,flag1,application1.Context,string.Empty);
list1.AddRange(stream1.ReadBody);
if(text2!=string.Empty)
{
progress1.FileLength=num2;
progress1.ReceivedLength=num1;
progress1.FileName=stream1.OriginalFileName;
progress1.FileCount=((Hashtable)application1.Context.Items["FileList"]).Count;
application1.Application["_UploadGUID_"+text2]=progress1;
}
if(!request1.IsEntireEntityBodyIsPreloaded())
{
byte[]buffer4;
ArrayListlist2;
intnum3=204800;
byte[]buffer3=newbyte[num3];
while((num2-num1)>=num3)
{
if(!application1.Context.Response.IsClientConnected)
{
this.ClearApplication(application1);
}
num3=request1.ReadEntityBody(buffer3,buffer3.Length);
num1+=num3;
list2=stream1.ContentBody;
if(list2.Count>0)
{
buffer4=newbyte[list2.Count+buffer3.Length];
list2.CopyTo(buffer4,0);
buffer3.CopyTo(buffer4,list2.Count);
stream1=newRequestStream(buffer4,buffer1,stream1.FileStream,stream1.FStatus,stream1.RStatus,text3,flag1,application1.Context,stream1.OriginalFileName);
}
else
{
stream1=newRequestStream(buffer3,buffer1,stream1.FileStream,stream1.FStatus,stream1.RStatus,text3,flag1,application1.Context,stream1.OriginalFileName);
}
list1.AddRange(stream1.ReadBody);
if(text2!=string.Empty)
{
progress1.ReceivedLength=num1;
progress1.FileName=stream1.OriginalFileName;
progress1.FileCount=((Hashtable)application1.Context.Items["FileList"]).Count;
application1.Application["_UploadGUID_"+text2]=progress1;
}
}
buffer3=newbyte[num2-num1];
if(!application1.Context.Response.IsClientConnected&&(stream1.FStatus== RequestStream.FileStatus.Open))
{
this.ClearApplication(application1);
}
num3=request1.ReadEntityBody(buffer3,buffer3.Length);
list2=stream1.ContentBody;
if(list2.Count>0)
{
buffer4=newbyte[list2.Count+buffer3.Length];
list2.CopyTo(buffer4,0);
buffer3.CopyTo(buffer4,list2.Count);
stream1=newRequestStream(buffer4,buffer1,stream1.FileStream,stream1.FStatus,stream1.RStatus,text3,flag1,application1.Context,stream1.OriginalFileName);
}
else
{
stream1=newRequestStream(buffer3,buffer1,stream1.FileStream,stream1.FStatus,stream1.RStatus,text3,flag1,application1.Context,stream1.OriginalFileName);
}
list1.AddRange(stream1.ReadBody);
if(text2!=string.Empty)
{
progress1.ReceivedLength=num1+buffer3.Length;
progress1.FileName=stream1.OriginalFileName;
progress1.FileCount=((Hashtable)application1.Context.Items["FileList"]).Count;
if(flag1)
{
progress1.UploadStatus=Progress.UploadStatusEnum.Uploaded;
}
else
{
application1.Application.Remove("_UploadGUID_"+text2);
}
}
}
byte[]buffer5=newbyte[list1.Count];
list1.CopyTo(buffer5);
this.PopulateRequestData(request1,buffer5);
}
catch(Exceptionexception1)
{
this.ClearApplication(application1);
throwexception1;
}实不相瞒,Java是我见过的执行效率最低的程序设计语言,前不久在CSDN论坛上有个评测,计算9999的阶乘,同样的循环算法,Java的耗时是.NET的5倍。 |
|