java 和 C# 响应输出的相似度

时间:2021-08-23 03:10:32

java servlet response:

bf.append("Shipment No, STT No, WIN Event, DateTime, WOU Envent, DateTime");
sbf.append('\n');

for(int i=0;i<list.size();i++)
{
PrintStatisticsForm psrform = list.get(i);
sbf.append(getCsvCommaString(psrform.getHawb()));
sbf.append(getCsvCommaString(psrform.getStt()));
sbf.append(getCsvCommaString(new HSSFRichTextString(psrform.getWinevent())));
sbf.append(getCsvCommaString(new HSSFRichTextString(psrform.getWindatetime())));
sbf.append(getCsvCommaString(new HSSFRichTextString(psrform.getWouevent())));
sbf.append(getCsvCommaString(new HSSFRichTextString(psrform.getWoudatetime())));
sbf.append('\n');
}
sbf.append('\n');
sbf.append('\n');
sbf.append('\n');
	byte[] csvData = sbf.toString().getBytes();
response.setHeader("Content-Disposition", "attachment;filename=Shipment Inventory Report.csv");
response.setContentLength(sbf.length());
response.setContentType("application/csv");
response.setCharacterEncoding("UTF-8");
response.getOutputStream().write(csvData);
response.getOutputStream().flush();
response.getOutputStream().close();

 

C# response

foreach (var totalCell in totalCellList)
{
totalContent.AppendFormat("\t{0},", totalCell.Value);
}

totalContent.AppendFormat("\t{0},", cellCountList.Values.Sum());
totalContent.AppendFormat("\t{0},", priceEvianBooCountList.Values.Sum());//依云及波多金额总计
totalContent.AppendFormat("\t{0},", pricefuWekoCountList.Values.Sum());//富维克金额总计
totalContent.AppendFormat("\t{0},", priceCountList.Values.Sum());//订单金额总计
sbContent.Append(totalContent.ToString());
//---------------------汇总行end------------------------//

sb.Append(sbContent.ToString());

var fileName = string.Format("{0}{1:yyyyMMddHHmmss}", (exporttype == 0 ? "日常报表_" : "详细报表_"), DateTime.Now);
userLogService.LogSuccessOperation(string.Format("导出报表[{0}.csv]!", fileName));

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = false;
byte[] data = Encoding.Default.GetBytes(sb.ToString());
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".csv");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.BinaryWrite(data);
HttpContext.Current.Response.Flush();

 

//------------------------------------------

if (Request.Content.IsMimeMultipartContent())
{
var path = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(path);
var task = Request.Content.ReadAsMultipartAsync(provider);
task.ContinueWith(t =>
{
if (t.IsFaulted || t.IsCanceled)
throw new HttpResponseException(HttpStatusCode.InternalServerError);
});
}
else
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
}