public ReadAsync ( char buffer, int index, int count ) : Task |
||
buffer | char | |
index | int | |
count | int | |
return | Task |
public override Task <int> ReadAsync(char[] buffer, int index, int count) { lock (this) { return(reader.ReadAsync(buffer, index, count)); } }
// Unlike normal ReadLine, this returns the line content with new line characters. public static async Task<StreamResult> ReadLineAsync(TextReader reader, StringBuilder builder) { bool written = false; char[] chars = new char[1]; while (true) { int num = await reader.ReadAsync(chars, 0, chars.Length); if (num <= 0) { return written ? new StreamResult(builder.ToString(), hasMore:reader.Peek() != -1) : null; } if (chars[0] == '\r' || chars[0] == '\n') { builder.Append(chars[0]); if (chars[0] == '\r' && reader.Peek() == (int)'\n') { builder.Append((char)reader.Read()); } return new StreamResult(builder.ToString(), hasMore: reader.Peek() != -1); } written = true; builder.Append(chars[0]); // to anticipate last non-ending line if (reader.Peek() == -1) { return written ? new StreamResult(builder.ToString(), hasMore: reader.Peek() != -1) : null; } } }
public static async Task SkipUntilAsync(TextReader reader, string token) { if (reader == null) throw new ArgumentNullException("reader"); if (token == null) return; var charSet = token.ToCharArray(); var buffer = new char[charSet.Length]; var actual = await reader.ReadAsync(buffer, 0, charSet.Length); if (actual != charSet.Length) { return; } do { if (buffer.SequenceEqual(charSet)) { return; } Array.Copy(buffer, 1, buffer, 0, charSet.Length - 1); actual = await reader.ReadAsync(buffer, charSet.Length - 1, 1); } while (actual == 1); }