System.Web.Compilation.AspGenerator.ReadFileContents C# (CSharp) Method

ReadFileContents() private method

private ReadFileContents ( Stream inputStream, string filename ) : string
inputStream Stream
filename string
return string
		string ReadFileContents (Stream inputStream, string filename)
		{
			string ret = null;
			
			if (inputStream != null) {
				if (inputStream.CanSeek) {
					long curPos = inputStream.Position;
					inputStream.Seek (0, SeekOrigin.Begin);

					Encoding enc = WebEncoding.FileEncoding;
					StringBuilder sb = new StringBuilder ();
					byte[] buffer = new byte [READ_BUFFER_SIZE];
					int nbytes;
					
					while ((nbytes = inputStream.Read (buffer, 0, READ_BUFFER_SIZE)) > 0)
						sb.Append (enc.GetString (buffer, 0, nbytes));
					inputStream.Seek (curPos, SeekOrigin.Begin);
					
					ret = sb.ToString ();
					sb.Length = 0;
					sb.Capacity = 0;
				} else {
					FileStream fs = inputStream as FileStream;
					if (fs != null) {
						string fname = fs.Name;
						try {
							if (File.Exists (fname))
								ret = File.ReadAllText (fname);
						} catch {
							// ignore
						}
					}
				}
			}

			if (ret == null && !String.IsNullOrEmpty (filename) && String.Compare (filename, "@@inner_string@@", StringComparison.Ordinal) != 0) {
				try {
					if (File.Exists (filename))
						ret = File.ReadAllText (filename);
				} catch {
					// ignore
				}
			}

			return ret;
		}