{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/29943504","id":29943504,"diff_hunk":"@@ -0,0 +1,280 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System;\n+using System.IO;\n+using System.Text;\n+using System.Threading.Tasks;\n+using Microsoft.Framework.Internal;\n+\n+namespace Microsoft.AspNet.Mvc\n+{\n+    /// <summary>\n+    /// Writes to the <see cref=\"Stream\"/> using the supplied <see cref=\"Encoding\"/>.\n+    /// It does not write the BOM and also does not close the stream.\n+    /// </summary>\n+    public class HttpResponseStreamWriter : TextWriter\n+    {\n+        private const int DefaultBufferSize = 1024;\n+        private readonly Stream _stream;\n+        private Encoder _encoder;\n+        private byte[] _byteBuffer;\n+        private char[] _charBuffer;\n+        private int _charBufferSize;\n+        private int _charBufferCount;\n+\n+        public HttpResponseStreamWriter(Stream stream, Encoding encoding)\n+            : this(stream, encoding, DefaultBufferSize)\n+        {\n+        }\n+\n+        public HttpResponseStreamWriter([NotNull] Stream stream, [NotNull] Encoding encoding, int bufferSize)\n+        {\n+            this._stream = stream;\n+            Encoding = encoding;\n+            _encoder = encoding.GetEncoder();\n+            _charBufferSize = bufferSize;\n+            _charBuffer = new char[bufferSize];\n+            _byteBuffer = new byte[encoding.GetMaxByteCount(bufferSize)];\n+        }\n+\n+        public override Encoding Encoding { get; }\n+\n+        public override void Write(char value)\n+        {\n+            if (_charBufferCount == _charBufferSize)\n+            {\n+                Flush();\n+            }\n+\n+            _charBuffer[_charBufferCount] = value;\n+            _charBufferCount++;\n+        }\n+\n+        public override void Write(char[] values)\n+        {\n+            if (values == null)\n+            {\n+                return;\n+            }\n+\n+            Write(values, 0, values.Length);\n+        }\n+\n+        public override void Write(char[] buffer, int index, int count)\n+        {\n+            if (buffer == null)\n+            {\n+                return;\n+            }\n+\n+            while (count > 0)\n+            {\n+                if (_charBufferCount == _charBufferSize)\n+                {\n+                    Flush();\n+                }\n+\n+                int remaining = _charBufferSize - _charBufferCount;","path":"src/Microsoft.AspNet.Mvc.Core/HttpResponseStreamWriter.cs","position":78,"original_position":78,"commit_id":"6f71370af68d4ed4b0feba6a6a2dcda71ca3084c","original_commit_id":"6f71370af68d4ed4b0feba6a6a2dcda71ca3084c","user":{"login":"pranavkm","id":174281,"avatar_url":"https://avatars.githubusercontent.com/u/174281?v=3","gravatar_id":"","url":"https://api.github.com/users/pranavkm","html_url":"https://github.com/pranavkm","followers_url":"https://api.github.com/users/pranavkm/followers","following_url":"https://api.github.com/users/pranavkm/following{/other_user}","gists_url":"https://api.github.com/users/pranavkm/gists{/gist_id}","starred_url":"https://api.github.com/users/pranavkm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pranavkm/subscriptions","organizations_url":"https://api.github.com/users/pranavkm/orgs","repos_url":"https://api.github.com/users/pranavkm/repos","events_url":"https://api.github.com/users/pranavkm/events{/privacy}","received_events_url":"https://api.github.com/users/pranavkm/received_events","type":"User","site_admin":false},"body":"var remaining = `Math.Min(_charBufferSize - _charBufferCount, count);`","created_at":"2015-05-08T14:24:49Z","updated_at":"2015-05-08T14:24:49Z","html_url":"https://github.com/aspnet/Mvc/pull/2518#discussion_r29943504","pull_request_url":"https://api.github.com/repos/aspnet/Mvc/pulls/2518","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments/29943504"},"html":{"href":"https://github.com/aspnet/Mvc/pull/2518#discussion_r29943504"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/2518"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Mvc/pulls/2518","id":34961189,"html_url":"https://github.com/aspnet/Mvc/pull/2518","diff_url":"https://github.com/aspnet/Mvc/pull/2518.diff","patch_url":"https://github.com/aspnet/Mvc/pull/2518.patch","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/2518","number":2518,"state":"open","locked":false,"title":"Custom stream writer which avoids writing BOM and does not close the stream","user":{"login":"kichalla","id":6559784,"avatar_url":"https://avatars.githubusercontent.com/u/6559784?v=3","gravatar_id":"","url":"https://api.github.com/users/kichalla","html_url":"https://github.com/kichalla","followers_url":"https://api.github.com/users/kichalla/followers","following_url":"https://api.github.com/users/kichalla/following{/other_user}","gists_url":"https://api.github.com/users/kichalla/gists{/gist_id}","starred_url":"https://api.github.com/users/kichalla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kichalla/subscriptions","organizations_url":"https://api.github.com/users/kichalla/orgs","repos_url":"https://api.github.com/users/kichalla/repos","events_url":"https://api.github.com/users/kichalla/events{/privacy}","received_events_url":"https://api.github.com/users/kichalla/received_events","type":"User","site_admin":false},"body":"@pranavkm @rynowak @Tratcher \r\n\r\nThis stream writer does the following:\r\n- Does not write the BOM even if the encoding requires it\r\n- Does not close the provided stream as the response stream is not owned by us\r\n- Does not flush on close/dispose as this can cause chunked encoding.","created_at":"2015-05-07T21:39:01Z","updated_at":"2015-05-08T14:24:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22330566fd330529a07f17e5828af7083d87f171","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Mvc/pulls/2518/commits","review_comments_url":"https://api.github.com/repos/aspnet/Mvc/pulls/2518/comments","review_comment_url":"https://api.github.com/repos/aspnet/Mvc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/2518/comments","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/6f71370af68d4ed4b0feba6a6a2dcda71ca3084c","head":{"label":"aspnet:kiran/custom-writer","ref":"kiran/custom-writer","sha":"6f71370af68d4ed4b0feba6a6a2dcda71ca3084c","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":15126429,"name":"Mvc","full_name":"aspnet/Mvc","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Mvc","description":"Model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor.","fork":false,"url":"https://api.github.com/repos/aspnet/Mvc","forks_url":"https://api.github.com/repos/aspnet/Mvc/forks","keys_url":"https://api.github.com/repos/aspnet/Mvc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Mvc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Mvc/teams","hooks_url":"https://api.github.com/repos/aspnet/Mvc/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Mvc/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Mvc/events","assignees_url":"https://api.github.com/repos/aspnet/Mvc/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Mvc/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Mvc/tags","blobs_url":"https://api.github.com/repos/aspnet/Mvc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Mvc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Mvc/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Mvc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Mvc/languages","stargazers_url":"https://api.github.com/repos/aspnet/Mvc/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Mvc/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Mvc/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Mvc/subscription","commits_url":"https://api.github.com/repos/aspnet/Mvc/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Mvc/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Mvc/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Mvc/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Mvc/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Mvc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Mvc/merges","archive_url":"https://api.github.com/repos/aspnet/Mvc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Mvc/downloads","issues_url":"https://api.github.com/repos/aspnet/Mvc/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Mvc/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Mvc/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Mvc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Mvc/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Mvc/releases{/id}","created_at":"2013-12-12T03:54:00Z","updated_at":"2015-05-08T12:32:07Z","pushed_at":"2015-05-08T14:22:33Z","git_url":"git://github.com/aspnet/Mvc.git","ssh_url":"git@github.com:aspnet/Mvc.git","clone_url":"https://github.com/aspnet/Mvc.git","svn_url":"https://github.com/aspnet/Mvc","homepage":"","size":119942,"stargazers_count":1694,"watchers_count":1694,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":560,"mirror_url":null,"open_issues_count":223,"forks":560,"open_issues":223,"watchers":1694,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"bd03142daba3854ac976906588bcaa1dc98accd0","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":15126429,"name":"Mvc","full_name":"aspnet/Mvc","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Mvc","description":"Model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor.","fork":false,"url":"https://api.github.com/repos/aspnet/Mvc","forks_url":"https://api.github.com/repos/aspnet/Mvc/forks","keys_url":"https://api.github.com/repos/aspnet/Mvc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Mvc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Mvc/teams","hooks_url":"https://api.github.com/repos/aspnet/Mvc/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Mvc/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Mvc/events","assignees_url":"https://api.github.com/repos/aspnet/Mvc/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Mvc/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Mvc/tags","blobs_url":"https://api.github.com/repos/aspnet/Mvc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Mvc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Mvc/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Mvc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Mvc/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Mvc/languages","stargazers_url":"https://api.github.com/repos/aspnet/Mvc/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Mvc/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Mvc/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Mvc/subscription","commits_url":"https://api.github.com/repos/aspnet/Mvc/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Mvc/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Mvc/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Mvc/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Mvc/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Mvc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Mvc/merges","archive_url":"https://api.github.com/repos/aspnet/Mvc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Mvc/downloads","issues_url":"https://api.github.com/repos/aspnet/Mvc/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Mvc/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Mvc/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Mvc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Mvc/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Mvc/releases{/id}","created_at":"2013-12-12T03:54:00Z","updated_at":"2015-05-08T12:32:07Z","pushed_at":"2015-05-08T14:22:33Z","git_url":"git://github.com/aspnet/Mvc.git","ssh_url":"git@github.com:aspnet/Mvc.git","clone_url":"https://github.com/aspnet/Mvc.git","svn_url":"https://github.com/aspnet/Mvc","homepage":"","size":119942,"stargazers_count":1694,"watchers_count":1694,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":560,"mirror_url":null,"open_issues_count":223,"forks":560,"open_issues":223,"watchers":1694,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/2518"},"html":{"href":"https://github.com/aspnet/Mvc/pull/2518"},"issue":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/2518"},"comments":{"href":"https://api.github.com/repos/aspnet/Mvc/issues/2518/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/2518/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Mvc/pulls/2518/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Mvc/statuses/6f71370af68d4ed4b0feba6a6a2dcda71ca3084c"}}}}