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的更多相关文章

  1. Stream/Bytes[]/Image对象相互转化

    Stream/Bytes[]/Image对象相互转化 Stream转Byte数组.Image转Byte数组.文件转Stream等 /// <summary> /// 将 Stream 转成 ...

  2. sream bytes[] img相互转换

    /// <summary> /// 将 Stream 转成 byte[] /// </summary> /// <param name="stream" ...

  3. kindeditor修改图片上传路径-使用webapi上传图片到图片服务器

    kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 在这里我着重介绍一些使用kindeditor修改图片上传路径并通过webapi上传图片到图片服务器的方案. 因为我使用的 ...

  4. kindeditor扩展粘贴图片功能&修改图片上传路径并通过webapi上传图片到图片服务器

    前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...

  5. kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器

    前言 kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 而kindeditor却对图片的处理不够理想. 本篇博文需要解决的问题有两个: kindeditor扩展粘贴图片功 ...

  6. IntraWeb XIV 类型速查表

    tkClass ================== IWUserSessionBase.TIWUserSessionBase < TDataModule < TComponent < ...

  7. WPF ListView 简单的拖拽实现(转)

    首先设置ListView的AllowDrop=True:SelectionMode=Extended;并且ListView视图为GridVIew. private void listView1_Mou ...

  8. .NET 2.0 参考源码索引

    http://www.projky.com/dotnet/2.0/Microsoft/CSharp/csharpcodeprovider.cs.htmlhttp://www.projky.com/do ...

  9. springboot 快速开发的定制补充

    增强 SpringBoot 快速开发工具 项目地址:https://gitee.com/sanri/web-ui 优点:这是一个 web 通用配置的组件,即插即用,可用于新项目或私活.是对 Sprin ...

随机推荐

  1. Linux + Mono 目前已经支持Entity Framework 6.1

    在上个随笔 CentOS上 Mono3.2.8运行ASP.NET MVC4经验中,步骤2中要求卸载EF 5.0,这样才能在Linux + Mono的环境中运行ASP.NET MVC4的Web应用.今天 ...

  2. IM系统中聊天记录模块的设计与实现

    看到很多开发IM系统的朋友都想实现聊天记录存储和查询这一不可或缺的功能,这里我就把自己前段时间为傲瑞通(OrayTalk)开发聊天记录模块的经验分享出来,供需要的朋友参考下. 一.总体设计 1.存储位 ...

  3. FTP文件管理

    因为网站有下载文件需要和网站分离,使用到了FTP管理文件,这里做一个简单的整理. 1.安装FTP 和安装iis一样.全部勾选. 设置站点名称和路径. 设置ip. 身份授权选择所有用户,可以读写. 完成 ...

  4. Python2.6下基于rsa的加密解密

    生成公钥的私钥: # -*- coding: UTF-8 -*- import rsa import base64 (public_key, private_key) = rsa.newkeys(10 ...

  5. Java提高篇(二八)------TreeSet

    与HashSet是基于HashMap实现一样,TreeSet同样是基于TreeMap实现的.在<Java提高篇(二七)-----TreeMap>中LZ详细讲解了TreeMap实现机制,如果 ...

  6. OpenSSL密码算法库: MD5示例小程序

    OpenSSL http://www.openssl.org/ OpenSSL整个软件包大概可以分成三个主要的功能部分:密码算法库.SSL协议库以及应用程序.OpenSSL 的密码算法库包含多种加密算 ...

  7. 一个用微软官方的OpenXml读写Excel 目前网上不太普及的方法。

    新版本的xlsx是使用新的存储格式,貌似是处理过的XML. 传统的excel处理方法,我真的感觉像屎.用Oldeb不方便,用com组件要实际调用excel打开关闭,很容易出现死. 对于OpenXML我 ...

  8. js 把url参数转对象

    //注意url中要含? function getParameterByName(name, url) {            if (!url) {                url = win ...

  9. UIImage NSData 相互转化

    //UIImage 转为 NSData NSData *imageData = UIImagePNGRepresentation(aImage); //NSData 转为 UIImage UIImag ...

  10. Fedora Static Configure

    Background Currenlty! I am work on fedora system, but the static-ip has required, but the fedora hav ...