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 ...
随机推荐
- C++11新特性总结 (一)
1. 概述 最近在看C++ Primer5 刚好看到一半,总结一下C++11里面确实加了很多新东西,如果没有任何了解,别说自己写了,看别人写的代码估计都会有些吃力.C++ Primer5是学习C++1 ...
- 使用Nginx实现负载均衡
使用Nginx实现负载均衡 一.nginx简介 nginx是一个高性能的HTTP服务器和反向代理服务器.它起初是俄罗斯人Igor Sysoev开发的,至今支撑者俄罗斯的很多大型的网站. 二.nginx ...
- windows系统下的第一个console程序
窗口+r 键,输入cmd,打开一个命令行窗口 切换到你的目标目录 输入 dotnet new dotnet会自动帮你创建3个文件. NuGet.Config文件主要定义了NuGet获取nupkg包时的 ...
- TW2015技术雷达中文版发布
今天thoughtworks 2015新版技术雷达pdf发布了,你可以从这里下载http://engage.thoughtworks.com/HQ0000Q0QOf5pE70nbD00GP,在这里你可 ...
- Windows 安装 MongoDB 服务
第一步 以管理员权限打开命令提示符 按Windows+R键(Ctrl和Alt中间的那个,有微软Logo的键),输入cmd打开命令提示符 第二步 创建数据库目录. 使用mkdir命令,创建数据库的目录和 ...
- 为什么一定要杀掉病毒?---帮一位老师解决MyDocument.exe优盘文件夹图标病毒问题
最近一位大学老师给我抱怨了一个她遇到的烦恼,一直在纠结,生活都被打乱了,事情大概是这样的: 她的优盘里辛辛苦苦弄好备课文件,放在了优盘里,可是每次上课时,就是找不到文件.有时好多文件都被修改了,非常烦 ...
- NodeMCU初探
对于ESP8266模块,早就想知道如何用其脚本语言, 自己先用的这个模块测试的 首先是先下载需要用到的工具和固件 链接:http://pan.baidu.com/s/1dF5NZ3N 密码:bziq ...
- paip.java 架构师之路以及java高级技术
paip.java 架构师之路以及java高级技术 1. Annotation 设计模式... 概念满天飞.ORM,IOC,AOP. Validator lambda4j memcache. 对 ...
- Django的Model上都有些什么
Django的Model上都有些什么 modelinfo= ['DoesNotExist', 'MultipleObjectsReturned', '__class__', '__delattr__' ...
- Android Studio下载及使用教程(转载)
(一)下载及相关问题解决: Android Studio 下载地址,目前最新可下载地址,尽量使用下载工具. Android Studio正式发布,给Android开发者带来了不小的惊喜.但是下载地址却 ...