本文整理汇总了C#中Stream.ReadAllBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadAllBytes方法的具体用法?C# Stream.ReadAllBytes怎么用?C# Stream.ReadAllBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.ReadAllBytes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static NameValueCollection Parse(Stream stream)
{
Dictionary<string, string[]> form = new Dictionary<string, string[]>();
UTF8Encoding encoding = new UTF8Encoding(false);
return HttpUtility.ParseQueryString(encoding.GetString(stream.ReadAllBytes()),encoding);
}
示例2: Load
/// <summary>
///
/// </summary>
/// <param name="game"></param>
/// <param name="stream"></param>
/// <param name="requestedType"></param>
/// <param name="assetPath"></param>
/// <returns></returns>
public override object Load( Game game, Stream stream, Type requestedType, string assetPath )
{
var bytes = stream.ReadAllBytes();
if (assetPath.ToLowerInvariant().Contains("|default")) {
return Encoding.Default.GetString( bytes );
}
if (assetPath.ToLowerInvariant().Contains("|utf8")) {
return Encoding.UTF8.GetString( bytes );
}
if (assetPath.ToLowerInvariant().Contains("|utf7")) {
return Encoding.UTF7.GetString( bytes );
}
if (assetPath.ToLowerInvariant().Contains("|utf32")) {
return Encoding.UTF32.GetString( bytes );
}
if (assetPath.ToLowerInvariant().Contains("|ascii")) {
return Encoding.ASCII.GetString( bytes );
}
return Encoding.Default.GetString( bytes );
}
示例3: CreatePackage
public void CreatePackage(string apiKey, Stream packageStream, IObserver<int> progressObserver, IPackageMetadata metadata = null)
{
var state = new PublishState {
PublishKey = apiKey,
PackageMetadata = metadata,
ProgressObserver = progressObserver
};
var url = new Uri(String.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}/nupkg", _baseGalleryServerUrl, CreatePackageService, apiKey));
WebClient client = new WebClient();
client.Proxy = _cachedProxy;
client.Headers[HttpRequestHeader.ContentType] = "application/octet-stream";
client.Headers[HttpRequestHeader.UserAgent] = _userAgent;
client.UploadProgressChanged += OnUploadProgressChanged;
client.UploadDataCompleted += OnCreatePackageCompleted;
client.UploadDataAsync(url, "POST", packageStream.ReadAllBytes(), state);
}
示例4: Writefile
public void Writefile(string filePath, Stream data)
{
File.WriteAllBytes(filePath, data.ReadAllBytes());
}
示例5: GetExistingPersistentCertificate
/// <summary>
/// Reads an X509 certificate from the given stream
/// </summary>
/// <returns>The retrieved certificate</returns>
/// <param name="stream">The stream that contains the X509 certificate data.</param>
/// <param name="password">The password to use to open the certificate.</param>
public static X509Certificate2 GetExistingPersistentCertificate(Stream stream, string password)
{
return new X509Certificate2(stream.ReadAllBytes(), password);
}
示例6: SetDocument
/// <summary>
/// Initializes the document metadata with bytes fed from the supplied stream
/// </summary>
/// <param name="document"></param>
public void SetDocument(Stream document)
{
SetDocument(document.ReadAllBytes());
}
示例7: Load
public override object Load ( ContentManager content, Stream stream, Type requestedType, string assetPath )
{
return stream.ReadAllBytes();
}
示例8: CalculateDerivedData
protected virtual void CalculateDerivedData(IPackage sourcePackage, LucenePackage package, string path, Stream stream)
{
byte[] fileBytes;
using (stream)
{
fileBytes = stream.ReadAllBytes();
}
package.PackageSize = fileBytes.Length;
package.PackageHash = System.Convert.ToBase64String(HashProvider.CalculateHash(fileBytes));
package.PackageHashAlgorithm = HashAlgorithm;
package.LastUpdated = FileSystem.GetLastModified(path);
package.Published = package.LastUpdated;
package.Created = GetZipArchiveCreateDate(new MemoryStream(fileBytes));
package.Path = path;
package.SupportedFrameworks = sourcePackage.GetSupportedFrameworks().Select(VersionUtility.GetShortFrameworkName);
var localPackage = sourcePackage as LocalPackage;
if (localPackage != null)
{
package.Files = localPackage.GetFiles().Select(f => f.Path);
}
}
示例9: CalculateDerivedDataSlowlyConsumingLotsOfMemory
private void CalculateDerivedDataSlowlyConsumingLotsOfMemory(LucenePackage package, Stream stream)
{
byte[] fileBytes;
using (stream)
{
fileBytes = stream.ReadAllBytes();
}
package.PackageSize = fileBytes.Length;
package.PackageHash = System.Convert.ToBase64String(HashProvider.CalculateHash(fileBytes));
package.Created = GetZipArchiveCreateDate(new MemoryStream(fileBytes));
}
示例10: DeserializeFeatureGen
private static object DeserializeFeatureGen(Stream inputStream) {
return inputStream.ReadAllBytes();
}
示例11: SpriteFont
/// <summary>
/// Constrcutor
/// </summary>
/// <param name="device"></param>
/// <param name="fileName"></param>
public SpriteFont ( GraphicsDevice rs, Stream stream )
{
this.rs = rs;
using (var br = new BinaryReader(stream)) {
var xml = br.ReadString();
FontFile input = FontLoader.LoadFromString( xml );
int numGlyphs = input.Chars.Max( ch => ch.ID );
// create charInfo and kernings :
fontInfo.kernings = new Dictionary<Tuple<char,char>, float>();
fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs+1];
// check one-page bitmap fonts :
if (input.Pages.Count!=1) {
throw new GraphicsException("Only one page of font image is supported");
}
// create path for font-image :
string fontImagePath = input.Pages[0].File;
// skip two bytes :
var texData = stream.ReadAllBytes();
fontTexture = new UserTexture( rs.Game.RenderSystem, texData, false );
// Fill structure :
fontInfo.fontFace = input.Info.Face;
fontInfo.baseLine = input.Common.Base;
fontInfo.lineHeight = input.Common.LineHeight;
fontInfo.scaleWidth = input.Common.ScaleW;
fontInfo.scaleHeight = input.Common.ScaleH;
float scaleWidth = fontInfo.scaleWidth;
float scaleHeight = fontInfo.scaleHeight;
// process character info :
for ( int i=0; i<input.Chars.Count; i++) {
FontChar ch = input.Chars[i];
int id = ch.ID;
if (id<0) continue;
int x = ch.X;
int y = ch.Y;
int xoffs = ch.XOffset;
int yoffs = ch.YOffset;
int w = ch.Width;
int h = ch.Height;
fontInfo.charInfo[ ch.ID ].validChar = true;
fontInfo.charInfo[ ch.ID ].xAdvance = ch.XAdvance;
fontInfo.charInfo[ ch.ID ].srcRect = new RectangleF(x, y, w, h);
fontInfo.charInfo[ ch.ID ].dstRect = new RectangleF(xoffs, yoffs, w, h);
}
var letterHeights = input.Chars
.Where( ch1 => char.IsUpper( (char)(ch1.ID) ) )
.Select( ch2 => ch2.Height )
.OrderBy( h => h )
.ToList();
CapHeight = letterHeights[ letterHeights.Count/2 ];
// process kerning info :
for ( int i=0; i<input.Kernings.Count; i++) {
var pair = new Tuple<char,char>( (char)input.Kernings[i].First, (char)input.Kernings[i].Second);
int kerning = input.Kernings[i].Amount;
fontInfo.kernings.Add( pair, kerning );
}
SpaceWidth = MeasureString(" ").Width;
LineHeight = MeasureString(" ").Height;
}
}