StreamHelper
public static MemoryStream CreateMemoryStreamFromBytes(byte[] inputData)
{
if (inputData == null || inputData.Length == 0)
{
return null;
}
MemoryStream result = new MemoryStream(inputData, false);
return result;
} /// <summary>
/// Read the data based on byte array from a specific file which path is from input.
/// </summary>
/// <param name="localFilePath">File path you want read.</param>
/// <returns>The file data based on byte array of input file. If input file path not exists, return null.</returns>
public static byte[] ReadBytesFromFile(string localFilePath)
{
if (StringHelper.IsNullOrEmpty(localFilePath)
|| !File.Exists(localFilePath))
{
return null;
}
FileStream fs = new FileStream(localFilePath,
FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] result = new byte[fs.Length];
int bufferSize = Convert.ToInt32((long)65536 > fs.Length ? fs.Length : (long)65536);
int offset = 0;
int readCount = 0;
using (fs as IDisposable)
{
while ((readCount = fs.Read(result, offset, bufferSize)) > 0)
{
offset += readCount;
bufferSize = bufferSize > result.Length - offset ?
result.Length - offset : bufferSize;
}
}
return result;
}
StreamHelper的更多相关文章
- Stream/Bytes[]/Image对象相互转化
Stream/Bytes[]/Image对象相互转化 Stream转Byte数组.Image转Byte数组.文件转Stream等 /// <summary> /// 将 Stream 转成 ...
- sream bytes[] img相互转换
/// <summary> /// 将 Stream 转成 byte[] /// </summary> /// <param name="stream" ...
- kindeditor修改图片上传路径-使用webapi上传图片到图片服务器
kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 在这里我着重介绍一些使用kindeditor修改图片上传路径并通过webapi上传图片到图片服务器的方案. 因为我使用的 ...
- kindeditor扩展粘贴图片功能&修改图片上传路径并通过webapi上传图片到图片服务器
前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...
- kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器
前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...
- IntraWeb XIV 类型速查表
tkClass ================== IWUserSessionBase.TIWUserSessionBase < TDataModule < TComponent < ...
- WPF ListView 简单的拖拽实现(转)
首先设置ListView的AllowDrop=True:SelectionMode=Extended;并且ListView视图为GridVIew. private void listView1_Mou ...
- .NET 2.0 参考源码索引
http://www.projky.com/dotnet/2.0/Microsoft/CSharp/csharpcodeprovider.cs.htmlhttp://www.projky.com/do ...
- springboot 快速开发的定制补充
增强 SpringBoot 快速开发工具 项目地址:https://gitee.com/sanri/web-ui 优点:这是一个 web 通用配置的组件,即插即用,可用于新项目或私活.是对 Sprin ...
随机推荐
- phpmyadmin Wrong permissions on configuration file, should not be world writable!
巴拉巴拉,实际场景是这样,因为有需要,所以想用django 做个rest服务给其他平台提供服务,发现以前正常的页面都无法运行,奇怪发现有一个页面提示连接不上mysql 难道mysql挂了,打开phpm ...
- 【TypeScript】如何在TypeScript中使用async/await,让你的代码更像C#。
[TypeScript]如何在TypeScript中使用async/await,让你的代码更像C#. async/await 提到这个东西,大家应该都很熟悉.最出名的可能就是C#中的,但也有其它语言也 ...
- 《你必须知道的.NET》读书笔记三:体验OO之美
此篇已收录至<你必须知道的.Net>读书笔记目录贴,点击访问该目录可以获取更多内容. 一.依赖也是哲学 (1)本质诠释:“不要调用我们,我们会调用你” (2)依赖和耦合: ①无依赖,无耦合 ...
- 冲刺阶段 day 14
项目进展 经过这几个星期的努力,我们已经完成了我们的软件工程项目,经过多次测试,项目已经可以准确无误地运行. 存在问题 测试期间,未发现问题. 心得体会 在这几个星期的努力下,我们终于完成了我们预期的 ...
- Programming Entity Framework CodeFirst -- 约定和属性配置
以下是EF中Data Annotation和 Fluenlt API的不同属性约定的对照. Length Data Annotation MinLength(nn) MaxLength(nn) ...
- angular中的MVVM模式
在开始介绍angular原理之前,我们有必要先了解下mvvm模式在angular中运用.虽然在angular社区一直将angular统称为前端MVC框架,同时angular团队也称它为MVW(What ...
- jeechart
个人网站地址:http://blog.niubua.com jeechart(1)——普通的分页查询 :http://blog.niubua.com/2014/09/18/jeechart(1)-普通 ...
- Atitit 理解Monad attilax总结
Atitit 理解Monad attilax总结 但函数式编程最大的一个问题是,函数是一个数学抽象,在现实世界中不存在,1 那既然这样就够用了,还要 Monad 干嘛?Monad 的作用在这里就体现出 ...
- Atitit 信用卡与会员卡(包括银行卡)的发展之路
Atitit 信用卡与会员卡(包括银行卡)的发展之路 实现跨机构卡片内金额的流动解决方案 1.1. 财务卡片本质上都是会员卡1 1.2. 卡片的发展阶段1 2. 实现跨机构卡片内金额的流动解决方案(加 ...
- 批处理集锦——(4)2>nul和1>nul是什么意思?
>nul 是屏蔽操作成功显示的信息,但是出错还是会显示(即1>nul) 2>nul 是屏蔽操作失败显示的信息,如果成功依旧显示. >nul 2>nul 就是正确的错误的一 ...