{"action":"created","comment":{"url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/comments/23837016","id":23837016,"diff_hunk":"@@ -114,28 +117,106 @@ public void call(S resource) {\n      *            internal buffer size\n      * @return the Observable containing read byte arrays from the input\n      */\n-    public static Observable<byte[]> from(final InputStream i, final int size) {\n+    public static Observable<byte[]> from(final InputStream is, final int size) {\n         return Observable.create(new OnSubscribe<byte[]>() {\n             @Override\n-            public void call(Subscriber<? super byte[]> o) {\n+            public void call(Subscriber<? super byte[]> subscriber) {\n+               subscriber.setProducer(new InputStreamProducer(is, subscriber, size));\n+            }\n+        });\n+    }\n+    \n+    private static class InputStreamProducer implements Producer {\n+\n+        private final AtomicLong requested = new AtomicLong(0);\n+        private final InputStream is;\n+        private final Subscriber<? super byte[]> subscriber;\n+        private int size;\n+        \n+        InputStreamProducer(InputStream is, Subscriber<? super byte[]> subscriber, int size) {\n+            this.is = is;\n+            this.subscriber = subscriber;\n+            this.size = size;\n+        }\n+        \n+        @Override\n+        public void request(long n) {\n+            try {\n+                if (requested.get() == Long.MAX_VALUE)","path":"src/main/java/rx/observables/StringObservable.java","position":50,"original_position":50,"commit_id":"6515cfc1efba44b4274f8ef1306a83465573863e","original_commit_id":"6515cfc1efba44b4274f8ef1306a83465573863e","user":{"login":"akarnokd","id":1269832,"avatar_url":"https://avatars.githubusercontent.com/u/1269832?v=3","gravatar_id":"","url":"https://api.github.com/users/akarnokd","html_url":"https://github.com/akarnokd","followers_url":"https://api.github.com/users/akarnokd/followers","following_url":"https://api.github.com/users/akarnokd/following{/other_user}","gists_url":"https://api.github.com/users/akarnokd/gists{/gist_id}","starred_url":"https://api.github.com/users/akarnokd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akarnokd/subscriptions","organizations_url":"https://api.github.com/users/akarnokd/orgs","repos_url":"https://api.github.com/users/akarnokd/repos","events_url":"https://api.github.com/users/akarnokd/events{/privacy}","received_events_url":"https://api.github.com/users/akarnokd/received_events","type":"User","site_admin":false},"body":"I think RxJava's contract on request(n) isn't as strong as reactive-streams, therefore, request() should be thread-safe and non-racy. Here, if a concurrent request(1) and request(Long.MAX_VALUE); arrives, the one can start both cases and end up having negative request amount.","created_at":"2015-01-30T11:33:53Z","updated_at":"2015-01-30T11:33:53Z","html_url":"https://github.com/ReactiveX/RxJavaString/pull/9#discussion_r23837016","pull_request_url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/comments/23837016"},"html":{"href":"https://github.com/ReactiveX/RxJavaString/pull/9#discussion_r23837016"},"pull_request":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9","id":25566431,"html_url":"https://github.com/ReactiveX/RxJavaString/pull/9","diff_url":"https://github.com/ReactiveX/RxJavaString/pull/9.diff","patch_url":"https://github.com/ReactiveX/RxJavaString/pull/9.patch","issue_url":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/9","number":9,"state":"open","locked":false,"title":"Add backpressure support for StringObservable.from(InputStream)","user":{"login":"davidmoten","id":318187,"avatar_url":"https://avatars.githubusercontent.com/u/318187?v=3","gravatar_id":"","url":"https://api.github.com/users/davidmoten","html_url":"https://github.com/davidmoten","followers_url":"https://api.github.com/users/davidmoten/followers","following_url":"https://api.github.com/users/davidmoten/following{/other_user}","gists_url":"https://api.github.com/users/davidmoten/gists{/gist_id}","starred_url":"https://api.github.com/users/davidmoten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidmoten/subscriptions","organizations_url":"https://api.github.com/users/davidmoten/orgs","repos_url":"https://api.github.com/users/davidmoten/repos","events_url":"https://api.github.com/users/davidmoten/events{/privacy}","received_events_url":"https://api.github.com/users/davidmoten/received_events","type":"User","site_admin":false},"body":"backpressure support added for ```StringObservable.from(InputStream)``` including a few unit tests.\r\n\r\nOnce this PR makes it through can add a similar one for ```StringObservable.from(Reader)```.","created_at":"2014-12-05T12:08:33Z","updated_at":"2015-01-30T11:33:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75e6d5fa92b2ba1eb53ce9050e334e4c14e9a079","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9/commits","review_comments_url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9/comments","review_comment_url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/9/comments","statuses_url":"https://api.github.com/repos/ReactiveX/RxJavaString/statuses/6515cfc1efba44b4274f8ef1306a83465573863e","head":{"label":"davidmoten:backp","ref":"backp","sha":"6515cfc1efba44b4274f8ef1306a83465573863e","user":{"login":"davidmoten","id":318187,"avatar_url":"https://avatars.githubusercontent.com/u/318187?v=3","gravatar_id":"","url":"https://api.github.com/users/davidmoten","html_url":"https://github.com/davidmoten","followers_url":"https://api.github.com/users/davidmoten/followers","following_url":"https://api.github.com/users/davidmoten/following{/other_user}","gists_url":"https://api.github.com/users/davidmoten/gists{/gist_id}","starred_url":"https://api.github.com/users/davidmoten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidmoten/subscriptions","organizations_url":"https://api.github.com/users/davidmoten/orgs","repos_url":"https://api.github.com/users/davidmoten/repos","events_url":"https://api.github.com/users/davidmoten/events{/privacy}","received_events_url":"https://api.github.com/users/davidmoten/received_events","type":"User","site_admin":false},"repo":{"id":23658702,"name":"RxJavaString","full_name":"davidmoten/RxJavaString","owner":{"login":"davidmoten","id":318187,"avatar_url":"https://avatars.githubusercontent.com/u/318187?v=3","gravatar_id":"","url":"https://api.github.com/users/davidmoten","html_url":"https://github.com/davidmoten","followers_url":"https://api.github.com/users/davidmoten/followers","following_url":"https://api.github.com/users/davidmoten/following{/other_user}","gists_url":"https://api.github.com/users/davidmoten/gists{/gist_id}","starred_url":"https://api.github.com/users/davidmoten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidmoten/subscriptions","organizations_url":"https://api.github.com/users/davidmoten/orgs","repos_url":"https://api.github.com/users/davidmoten/repos","events_url":"https://api.github.com/users/davidmoten/events{/privacy}","received_events_url":"https://api.github.com/users/davidmoten/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidmoten/RxJavaString","description":"","fork":true,"url":"https://api.github.com/repos/davidmoten/RxJavaString","forks_url":"https://api.github.com/repos/davidmoten/RxJavaString/forks","keys_url":"https://api.github.com/repos/davidmoten/RxJavaString/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidmoten/RxJavaString/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidmoten/RxJavaString/teams","hooks_url":"https://api.github.com/repos/davidmoten/RxJavaString/hooks","issue_events_url":"https://api.github.com/repos/davidmoten/RxJavaString/issues/events{/number}","events_url":"https://api.github.com/repos/davidmoten/RxJavaString/events","assignees_url":"https://api.github.com/repos/davidmoten/RxJavaString/assignees{/user}","branches_url":"https://api.github.com/repos/davidmoten/RxJavaString/branches{/branch}","tags_url":"https://api.github.com/repos/davidmoten/RxJavaString/tags","blobs_url":"https://api.github.com/repos/davidmoten/RxJavaString/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidmoten/RxJavaString/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidmoten/RxJavaString/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidmoten/RxJavaString/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidmoten/RxJavaString/statuses/{sha}","languages_url":"https://api.github.com/repos/davidmoten/RxJavaString/languages","stargazers_url":"https://api.github.com/repos/davidmoten/RxJavaString/stargazers","contributors_url":"https://api.github.com/repos/davidmoten/RxJavaString/contributors","subscribers_url":"https://api.github.com/repos/davidmoten/RxJavaString/subscribers","subscription_url":"https://api.github.com/repos/davidmoten/RxJavaString/subscription","commits_url":"https://api.github.com/repos/davidmoten/RxJavaString/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidmoten/RxJavaString/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidmoten/RxJavaString/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidmoten/RxJavaString/issues/comments/{number}","contents_url":"https://api.github.com/repos/davidmoten/RxJavaString/contents/{+path}","compare_url":"https://api.github.com/repos/davidmoten/RxJavaString/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidmoten/RxJavaString/merges","archive_url":"https://api.github.com/repos/davidmoten/RxJavaString/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidmoten/RxJavaString/downloads","issues_url":"https://api.github.com/repos/davidmoten/RxJavaString/issues{/number}","pulls_url":"https://api.github.com/repos/davidmoten/RxJavaString/pulls{/number}","milestones_url":"https://api.github.com/repos/davidmoten/RxJavaString/milestones{/number}","notifications_url":"https://api.github.com/repos/davidmoten/RxJavaString/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidmoten/RxJavaString/labels{/name}","releases_url":"https://api.github.com/repos/davidmoten/RxJavaString/releases{/id}","created_at":"2014-09-04T10:50:00Z","updated_at":"2014-08-29T21:21:48Z","pushed_at":"2014-12-05T12:05:01Z","git_url":"git://github.com/davidmoten/RxJavaString.git","ssh_url":"git@github.com:davidmoten/RxJavaString.git","clone_url":"https://github.com/davidmoten/RxJavaString.git","svn_url":"https://github.com/davidmoten/RxJavaString","homepage":null,"size":251,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"0.x"}},"base":{"label":"ReactiveX:1.x","ref":"1.x","sha":"c14e5b69e68f0d528bca46d1400caf6a31d9c8c7","user":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"repo":{"id":23477919,"name":"RxJavaString","full_name":"ReactiveX/RxJavaString","owner":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ReactiveX/RxJavaString","description":"","fork":false,"url":"https://api.github.com/repos/ReactiveX/RxJavaString","forks_url":"https://api.github.com/repos/ReactiveX/RxJavaString/forks","keys_url":"https://api.github.com/repos/ReactiveX/RxJavaString/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReactiveX/RxJavaString/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReactiveX/RxJavaString/teams","hooks_url":"https://api.github.com/repos/ReactiveX/RxJavaString/hooks","issue_events_url":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/events{/number}","events_url":"https://api.github.com/repos/ReactiveX/RxJavaString/events","assignees_url":"https://api.github.com/repos/ReactiveX/RxJavaString/assignees{/user}","branches_url":"https://api.github.com/repos/ReactiveX/RxJavaString/branches{/branch}","tags_url":"https://api.github.com/repos/ReactiveX/RxJavaString/tags","blobs_url":"https://api.github.com/repos/ReactiveX/RxJavaString/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReactiveX/RxJavaString/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReactiveX/RxJavaString/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReactiveX/RxJavaString/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReactiveX/RxJavaString/statuses/{sha}","languages_url":"https://api.github.com/repos/ReactiveX/RxJavaString/languages","stargazers_url":"https://api.github.com/repos/ReactiveX/RxJavaString/stargazers","contributors_url":"https://api.github.com/repos/ReactiveX/RxJavaString/contributors","subscribers_url":"https://api.github.com/repos/ReactiveX/RxJavaString/subscribers","subscription_url":"https://api.github.com/repos/ReactiveX/RxJavaString/subscription","commits_url":"https://api.github.com/repos/ReactiveX/RxJavaString/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReactiveX/RxJavaString/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReactiveX/RxJavaString/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/comments/{number}","contents_url":"https://api.github.com/repos/ReactiveX/RxJavaString/contents/{+path}","compare_url":"https://api.github.com/repos/ReactiveX/RxJavaString/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReactiveX/RxJavaString/merges","archive_url":"https://api.github.com/repos/ReactiveX/RxJavaString/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReactiveX/RxJavaString/downloads","issues_url":"https://api.github.com/repos/ReactiveX/RxJavaString/issues{/number}","pulls_url":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls{/number}","milestones_url":"https://api.github.com/repos/ReactiveX/RxJavaString/milestones{/number}","notifications_url":"https://api.github.com/repos/ReactiveX/RxJavaString/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReactiveX/RxJavaString/labels{/name}","releases_url":"https://api.github.com/repos/ReactiveX/RxJavaString/releases{/id}","created_at":"2014-08-29T21:11:12Z","updated_at":"2015-01-30T11:21:20Z","pushed_at":"2015-01-30T11:21:20Z","git_url":"git://github.com/ReactiveX/RxJavaString.git","ssh_url":"git@github.com:ReactiveX/RxJavaString.git","clone_url":"https://github.com/ReactiveX/RxJavaString.git","svn_url":"https://github.com/ReactiveX/RxJavaString","homepage":null,"size":606,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":24,"default_branch":"1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9"},"html":{"href":"https://github.com/ReactiveX/RxJavaString/pull/9"},"issue":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/9"},"comments":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/ReactiveX/RxJavaString/statuses/6515cfc1efba44b4274f8ef1306a83465573863e"}}}}