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); }
/// <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 ); }
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); }
public void Writefile(string filePath, Stream data) { File.WriteAllBytes(filePath, data.ReadAllBytes()); }
/// <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); }
/// <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()); }
public override object Load ( ContentManager content, Stream stream, Type requestedType, string assetPath ) { return stream.ReadAllBytes(); }
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); } }
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)); }
private static object DeserializeFeatureGen(Stream inputStream) { return inputStream.ReadAllBytes(); }
/// <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; } }