[
  {
    "path": ".editorconfig",
    "content": "# EditorConfig helps developers define and maintain consistent\n# coding styles between different editors and IDEs\n# editorconfig.org\n\nroot = true\n\n[*]\n# Change these settings to your own preference\nindent_style = space\nindent_size = 4\n\n# We recommend you to keep these unchanged\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n\n[*.md]\ntrim_trailing_whitespace = false\nindent_style = space\n"
  },
  {
    "path": ".gitignore",
    "content": "# Compiled source #\n###################\n*.com\n*.class\n*.dll\n*.exe\n*.o\n*.so\n\n# Packages #\n############\n# it's better to unpack these files and commit the raw source\n# git has its own built in compression methods\n*.7z\n*.dmg\n*.gz\n*.iso\n*.jar\n*.rar\n*.tar\n*.zip\n\n# Logs and databases #\n######################\n*.log\n\n# OS generated files #\n######################\n.DS_Store*\nehthumbs.db\nIcon?\nThumbs.db\n\n# Editor Files #\n################\n*~\n*.swp\n\n# Gradle Files #\n################\n.gradle\n.gradletasknamecache\n.m2\n\n# Build output directies\ntarget/\nbuild/\n\n# IntelliJ specific files/directories\nout\n.idea\n*.ipr\n*.iws\n*.iml\natlassian-ide-plugin.xml\n\n# Eclipse specific files/directories\n.classpath\n.project\n.settings\n.metadata\nbin/\n\n# NetBeans specific files/directories\n.nbattrs\n/.nb-gradle/profiles/private/\n.nb-gradle-properties\n\n# Scala build\n*.cache\n/.nb-gradle/private/\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: java\njdk:\n- oraclejdk7\nsudo: false\n# as per http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/\n\n# script for build and release via Travis to Bintray\nscript: gradle/buildViaTravis.sh\n\n# Code coverage\nafter_success:\n  - bash <(curl -s https://codecov.io/bash)\n\n# cache between builds\ncache:\n  directories:\n  - $HOME/.m2\n  - $HOME/.gradle\n  \nenv:\n  global:\n  - secure: \"WP1xTcv1Ti9vozsZSZYTPxi2iW4KVW9MmlZaQgnHvrDZRo+Z/VvugG1Ww49TY9qv/xd3d+sw8SuRu/yBP/KOAeaQLJ6mjeVcWKUngIJv70/mfp5d4ErnU0D7ntzyi00K9Q0C7cKO3sxaPAynGHeVAFKopjaXxQT4171QFoUZNq0=\"\n  - secure: \"pNrV8dNdQMgZcH4EtrG15tPWwDM2kOTEdMumuU8c7xU20pXvQrYuoi4XEt3bdROz772uFuqGhxbxGjoXJiqg2DxIrYHVgbCJzTiifIiW/19poqplNNLfSPwmE7u4YXLgKXKPLs4SO1LsFmPkn5KoopCTChbqJYnGXLj2EtU7wcQ=\"\n  - secure: \"J38VYI7m7sIGJtM+xdkuSZ5YoROjrM8Be74JDLHs+MH22n6uqupoRRWUAkSP4gCMA/kp7WKNFJsv+6OBUCxSdMUVA2x7dFJ5ocV9zAZuPXTBaR9k/cWmOrKg7ih23LntQbp/6vBoGMv+qwJ0HuFZefh0lSRfBvbJ+BYROxgWJiI=\"\n  - secure: \"O7JOWfyyKOBoXCM/P7kHE/72rPcdlweW14f22G+CzD8+5WYaVch4XtQiXvLNvw6K/xNn5xFSGtTdBYPXXENrhxKZcRkNjfxAMCZO5HwtPeRwLdem1IxdoJkkU1iinJDqLRVy1KFU3pzSH+6SINtpLKZZe3Zc1bCZ8ECxlsaV4rg=\""
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing to RxJava\n\nIf you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request (on a branch other than `master` or `gh-pages`).\n\nWhen submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible.\n\n## License\n\nBy contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/ReactiveX/RxJava/blob/master/LICENSE\n\nAll files are released with the Apache 2.0 license.\n\nIf you are adding a new file it should have a header like this:\n\n```\n/**\n * Copyright 2014 Netflix, Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n ```\n"
  },
  {
    "path": "LICENSE",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright 2012 Netflix, Inc.\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# RxJava Reactive Streams\n\n<a href='https://travis-ci.org/ReactiveX/RxJavaReactiveStreams/builds'><img src='https://travis-ci.org/ReactiveX/RxJavaReactiveStreams.svg?branch=1.x'></a>\n[![codecov.io](http://codecov.io/github/ReactiveX/RxJavaReactiveStreams/coverage.svg?branch=1.x)](http://codecov.io/github/ReactiveX/RxJavaReactiveStreams?branch=1.x)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex/rxjava-reactive-streams/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex/rxjava-reactive-streams)\n\nThis library provides adapters between RxJava and [Reactive Streams](http://www.reactive-streams.org).\nThe Reactive Streams standard defines an API and runtime semantics for reactive data streams, that different tools can implement in order to interoperate with each other.\nThis library allows RxJava to interoperate with other implementors of the Reactive Streams API.\n\nIt provides the following API:\n\n```java\npackage rx;\n\nimport org.reactivestreams.Publisher;\n\npublic abstract class RxReactiveStreams {\n\n    public static <T> Publisher<T> toPublisher(Observable<T> observable) { … }\n\n    public static <T> Observable<T> toObservable(Publisher<T> publisher) { … }\n\n    public static <T> Publisher<T> toPublisher(Single<T> observable) { … }\n\n    public static <T> Single<T> toSingle(Publisher<T> publisher) { … }\n\n    public static <T> Publisher<T> toPublisher(Completable observable) { … }\n\n    public static Completable toCompletable(Publisher<?> publisher) { … }\n\n}\n```\n\nThese methods can be used to convert between the Reactive Streams `Publisher` type, and RxJava's `Observable` type.\n\nSome [examples of this library being used for interop](https://github.com/ReactiveX/RxJavaReactiveStreams/tree/0.x/examples) are available as part of this repository.\n\nSee the [Reactive Streams](http://www.reactive-streams.org) website for links to other libraries that implement the Reactive Streams API,\nand can therefore interoperate with RxJava via these methods.\n\nLearn more about RxJava on the <a href=\"https://github.com/ReactiveX/RxJava/wiki\">Wiki Home</a> and the <a href=\"http://techblog.netflix.com/2013/02/rxjava-netflix-api.html\">Netflix TechBlog post</a> where RxJava was introduced.\n\n## Communication\n\n- Google Group: [RxJava](http://groups.google.com/d/forum/rxjava)\n- Twitter: [@RxJava](http://twitter.com/RxJava)\n- [GitHub Issues](https://github.com/ReactiveX/RxJava/issues)\n\n## Binaries\n\nBinaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cio.reactivex.rxjava-reactive-streams).\n\nExample for Maven:\n\n```xml\n<dependency>\n    <groupId>io.reactivex</groupId>\n    <artifactId>rxjava-reactive-streams</artifactId>\n    <version>x.y.z</version>\n</dependency>\n```\nand for Ivy:\n\n```xml\n<dependency org=\"io.reactivex\" name=\"rxjava-reactive-streams\" rev=\"x.y.z\" />\n```\n\n## Build\n\nTo build:\n\n```\n$ git clone git@github.com:ReactiveX/RxJavaReactiveStreams.git\n$ cd RxJavaReactiveStreams/\n$ ./gradlew build\n```\n\n## Bugs and Feedback\n\nFor bugs, questions and discussions please use the [Github Issues](https://github.com/ReactiveX/RxJavaReactiveStreams/issues).\n\n## LICENSE\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n<http://www.apache.org/licenses/LICENSE-2.0>\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n"
  },
  {
    "path": "build.gradle",
    "content": "buildscript {\n    repositories { jcenter() }\n    dependencies { classpath 'com.netflix.nebula:gradle-rxjava-project-plugin:4.0.0' }\n}\n\nallprojects {\n    apply plugin: 'nebula.rxjava-project'\n}\n\nidea {\n    project {\n        jdkName = \"1.6\"\n    }\n}\n\n// support for snapshot/final releases with the various branches RxJava uses\nnebulaRelease {\n    addReleaseBranchPattern(/\\d+\\.\\d+\\.\\d+/)\n    addReleaseBranchPattern('HEAD')\n}\n\nif (project.hasProperty('release.useLastTag')) {\n    tasks.prepare.enabled = false\n}\n"
  },
  {
    "path": "examples/build.gradle",
    "content": "subprojects {\n    bintrayUpload.enabled = false\n    artifactoryPublish.skip = true\n}"
  },
  {
    "path": "examples/ratpack/build.gradle",
    "content": "plugins {\n    id \"org.gradle.java\"\n}\n\ndependencies {\n    testCompile project(\":rxjava-reactive-streams\")\n    testCompile \"io.ratpack:ratpack-test:0.9.10\"\n    testCompile 'org.java-websocket:Java-WebSocket:1.3.0'\n    testCompile 'junit:junit:4.11'\n}\n\nsourceCompatibility = \"1.8\"\ntargetCompatibility = \"1.8\"\n\n// The implementation builds with Java 1.6 - we need to use Java 8 for Ratpack\nidea {\n    module {\n        jdkName = \"1.8\"\n        iml.withXml { XmlProvider xml ->\n            node.component.find { it.'@name' == 'NewModuleRootManager' }.@LANGUAGE_LEVEL = \"JDK_1_8\"\n        }\n    }\n}\n\n"
  },
  {
    "path": "examples/ratpack/src/main/java/rx/reactivestreams/example/ratpack/Dummy.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams.example.ratpack;\n\n// Just here to appease the build\n// TODO LD: remove need for\npublic class Dummy {\n}\n"
  },
  {
    "path": "examples/ratpack/src/test/java/rx/reactivestreams/example/ratpack/RatpackExamples.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams.example.ratpack;\n\nimport com.google.common.collect.ContiguousSet;\nimport com.google.common.collect.DiscreteDomain;\nimport com.google.common.collect.Lists;\nimport com.google.common.collect.Range;\nimport org.junit.Assert;\nimport org.junit.Test;\nimport org.reactivestreams.Publisher;\nimport ratpack.http.ResponseChunks;\nimport ratpack.http.client.ReceivedResponse;\nimport ratpack.sse.ServerSentEvents;\nimport ratpack.stream.Streams;\nimport ratpack.test.embed.EmbeddedApp;\nimport ratpack.test.http.TestHttpClient;\nimport ratpack.websocket.WebSockets;\nimport rx.Observable;\nimport rx.RxReactiveStreams;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\nimport java.util.Arrays;\nimport java.util.List;\n\nimport static java.util.stream.Collectors.joining;\n\npublic class RatpackExamples {\n\n    private Iterable<Integer> createIntRange(int upper) {\n        return ContiguousSet.create(Range.closedOpen(0, upper), DiscreteDomain.integers());\n    }\n\n    /**\n     * Tests rendering an observable as a chunked response.\n     * <p/>\n     * Data flow:\n     * <p/>\n     * 1. Observable of ints\n     * 2. Convert to Publisher\n     * 3. Use Ratpack Publisher transform\n     * 4. Convert to Observable\n     * 5. Use Observable transform\n     * 6. Convert to Publisher\n     * 7. Render Publisher\n     * <p/>\n     * Back pressure is being applied but it's hard to test for, as it's being applied by the HTTP client ultimately.\n     */\n    @Test\n    public void testChunkStreaming() {\n        Iterable<Integer> ints = createIntRange(100);\n        EmbeddedApp.fromHandler(ctx -> {\n            // Create a  publisher\n            Observable<Integer> observable = Observable.from(ints);\n            Publisher<Integer> publisher = RxReactiveStreams.toPublisher(observable);\n\n            // Use one of Ratpack's transforms to convert them into strings\n            Publisher<String> strings = Streams.map(publisher, Object::toString);\n\n            // Convert back to an Rx Observable to do further transforms\n            Observable<String> lines = RxReactiveStreams.toObservable(strings).map(s -> s + \"\\n\");\n\n            // Now render the observable by going back to a publisher\n            Publisher<String> linesPublisher = RxReactiveStreams.toPublisher(lines);\n\n            ctx.render(ResponseChunks.stringChunks(linesPublisher));\n        }).test(httpClient -> {\n            String text = httpClient.getText().trim();\n            List<String> strings = Arrays.asList(text.split(\"\\n\"));\n\n            List<Integer> expectedInts = Lists.newArrayList(ints);\n            List<Integer> receivedInts = Lists.transform(strings, Integer::new);\n\n            Assert.assertEquals(expectedInts, receivedInts);\n        });\n    }\n\n    /**\n     * Test streaming Server Sent Events\n     */\n    @Test\n    public void testServerSentEvents() {\n        Iterable<Integer> ints = createIntRange(5);\n\n        EmbeddedApp.fromHandler(ctx -> {\n            Observable<Integer> observable = Observable.from(ints);\n            Publisher<Integer> publisher = RxReactiveStreams.toPublisher(observable);\n\n            ctx.render(\n                ServerSentEvents.serverSentEvents(publisher, e ->\n                        e.event(\"counter\").data(\"event \" + e.getItem())\n                )\n            );\n        }).test(httpClient -> {\n            ReceivedResponse response = httpClient.get();\n            Assert.assertEquals(\"text/event-stream;charset=UTF-8\", response.getHeaders().get(\"Content-Type\"));\n\n            String expectedOutput = Arrays.asList(0, 1, 2, 3, 4)\n                .stream()\n                .map(i -> \"event: counter\\ndata: event \" + i + \"\\n\")\n                .collect(joining(\"\\n\"))\n                + \"\\n\";\n\n            Assert.assertEquals(expectedOutput, response.getBody().getText());\n        });\n\n    }\n\n    /**\n     * Test streaming to a Websocket.\n     *\n     * Note: Ratpack doesn't yet support consuming the incoming data as a stream.\n     */\n    @Test\n    public void testWebsocket() {\n        Iterable<Integer> ints = createIntRange(3);\n\n        EmbeddedApp.fromHandler(ctx -> {\n            Observable<String> observable = Observable.from(ints).map(Object::toString);\n            WebSockets.websocketBroadcast(ctx, RxReactiveStreams.toPublisher(observable));\n        }).test(httpClient -> {\n            URI wsAddress = getWsAddress(httpClient);\n            RecordingWebSocketClient wsClient = new RecordingWebSocketClient(wsAddress);\n\n            try {\n                Assert.assertTrue(wsClient.connectBlocking());\n                Assert.assertEquals(\"0\", wsClient.next());\n                Assert.assertEquals(\"1\", wsClient.next());\n                Assert.assertEquals(\"2\", wsClient.next());\n                wsClient.waitForClose();\n            } catch (InterruptedException e) {\n                throw new RuntimeException(e);\n            }\n        });\n    }\n\n    private URI getWsAddress(TestHttpClient httpClient) {\n        URI httpAddress = httpClient.getApplicationUnderTest().getAddress();\n        URI wsAddress;\n        try {\n            wsAddress = new URI(\"ws\", null, httpAddress.getHost(), httpAddress.getPort(), httpAddress.getPath(), null, null);\n        } catch (URISyntaxException e) {\n            throw new RuntimeException(e);\n        }\n        return wsAddress;\n    }\n\n}\n"
  },
  {
    "path": "examples/ratpack/src/test/java/rx/reactivestreams/example/ratpack/RecordingWebSocketClient.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams.example.ratpack;\n\nimport org.java_websocket.client.WebSocketClient;\nimport org.java_websocket.handshake.ServerHandshake;\n\nimport java.net.URI;\nimport java.util.concurrent.BlockingQueue;\nimport java.util.concurrent.CountDownLatch;\nimport java.util.concurrent.LinkedBlockingQueue;\nimport java.util.concurrent.TimeUnit;\n\n/**\n * Fast and loose websocket client for testing purposes.\n */\npublic class RecordingWebSocketClient extends WebSocketClient {\n\n    final BlockingQueue<String> received = new LinkedBlockingQueue<>();\n\n    public Exception exception;\n    public int closeCode;\n    public String closeReason;\n    public boolean closeRemote;\n    public ServerHandshake serverHandshake;\n\n    private final CountDownLatch closeLatch = new CountDownLatch(1);\n\n    public RecordingWebSocketClient(URI serverURI) {\n        super(serverURI);\n    }\n\n    @Override\n    public void onOpen(ServerHandshake handshakedata) {\n        serverHandshake = handshakedata;\n    }\n\n    @Override\n    public void onMessage(String message) {\n        try {\n            received.put(message);\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    @Override\n    public void onClose(int code, String reason, boolean remote) {\n        this.closeCode = code;\n        this.closeReason = reason;\n        this.closeRemote = remote;\n        closeLatch.countDown();\n    }\n\n    void waitForClose() throws InterruptedException {\n        if (!closeLatch.await(5, TimeUnit.SECONDS)) {\n            throw new RuntimeException(\"Socket did not close in time\");\n        }\n    }\n\n    @Override\n    public void onError(Exception ex) {\n        this.exception = ex;\n    }\n\n    public String next() {\n        try {\n            return received.take();\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n}\n"
  },
  {
    "path": "gradle/buildViaTravis.sh",
    "content": "#!/bin/bash\n# This script will build the project.\n\nif [ \"$TRAVIS_PULL_REQUEST\" != \"false\" ]; then\n  echo -e \"Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]\"\n  ./gradlew -Prelease.useLastTag=true build\nelif [ \"$TRAVIS_PULL_REQUEST\" == \"false\" ] && [ \"$TRAVIS_TAG\" == \"\" ]; then\n  echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'\n  ./gradlew -Prelease.travisci=true -PbintrayUser=\"${bintrayUser}\" -PbintrayKey=\"${bintrayKey}\" -PsonatypeUsername=\"${sonatypeUsername}\" -PsonatypePassword=\"${sonatypePassword}\" build snapshot --stacktrace\nelif [ \"$TRAVIS_PULL_REQUEST\" == \"false\" ] && [ \"$TRAVIS_TAG\" != \"\" ]; then\n  echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH']  Tag ['$TRAVIS_TAG']'\n  ./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser=\"${bintrayUser}\" -PbintrayKey=\"${bintrayKey}\" -PsonatypeUsername=\"${sonatypeUsername}\" -PsonatypePassword=\"${sonatypePassword}\" final --stacktrace\nelse\n  echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH']  Tag ['$TRAVIS_TAG']  Pull Request ['$TRAVIS_PULL_REQUEST']'\n  ./gradlew -Prelease.useLastTag=true build\nfi\n"
  },
  {
    "path": "gradle/wrapper/.gitignore",
    "content": "!*.jar"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Thu Jun 30 22:23:34 CEST 2016\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-2.14-bin.zip\n"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >/dev/null\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >/dev/null\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\nnonstop=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\n  NONSTOP* )\n    nonstop=true\n    ;;\nesac\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" -a \"$nonstop\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n    JAVACMD=`cygpath --unix \"$JAVACMD\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem  Gradle startup script for Windows\n@rem\n@rem ##########################################################################\n\n@rem Set local scope for the variables with windows NT shell\nif \"%OS%\"==\"Windows_NT\" setlocal\n\nset DIRNAME=%~dp0\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\nset APP_BASE_NAME=%~n0\nset APP_HOME=%DIRNAME%\n\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nset DEFAULT_JVM_OPTS=\n\n@rem Find java.exe\nif defined JAVA_HOME goto findJavaFromJavaHome\n\nset JAVA_EXE=java.exe\n%JAVA_EXE% -version >NUL 2>&1\nif \"%ERRORLEVEL%\" == \"0\" goto init\n\necho.\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:findJavaFromJavaHome\nset JAVA_HOME=%JAVA_HOME:\"=%\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\n\nif exist \"%JAVA_EXE%\" goto init\n\necho.\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:init\n@rem Get command-line arguments, handling Windows variants\n\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\n\n:win9xME_args\n@rem Slurp the command line arguments.\nset CMD_LINE_ARGS=\nset _SKIP=2\n\n:win9xME_args_slurp\nif \"x%~1\" == \"x\" goto execute\n\nset CMD_LINE_ARGS=%*\ngoto execute\n\n:4NT_args\n@rem Get arguments from the 4NT Shell from JP Software\nset CMD_LINE_ARGS=%$\n\n:execute\n@rem Setup the command line\n\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\n\n@rem Execute Gradle\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\n\n:end\n@rem End local scope for the variables with windows NT shell\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\n\n:fail\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\nrem the _cmd.exe /c_ return code!\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\nexit /b 1\n\n:mainEnd\nif \"%OS%\"==\"Windows_NT\" endlocal\n\n:omega\n"
  },
  {
    "path": "rxjava-reactive-streams/build.gradle",
    "content": "description = \"Adapter between RxJava and ReactiveStreams\"\n\napply plugin: 'java'\napply plugin: 'jacoco'\n\ndependencies {\n    compile 'io.reactivex:rxjava:1.2.2'\n    compile 'org.reactivestreams:reactive-streams:1.0.0'\n    testCompile 'org.reactivestreams:reactive-streams-tck:1.0.0'\n    testCompile group: 'org.testng', name: 'testng', version: '6.9.10'\n}\n\ntest {\nuseTestNG()\n     testLogging  {\n        events=['passed', 'skipped', 'failed']\n        exceptionFormat=\"full\"\n\n        debug.events = ['passed', 'skipped', 'failed']\n        debug.exceptionFormat=\"full\"\n\n        info.events = ['passed', 'skipped', 'failed']\n        info.exceptionFormat=\"full\"\n        \n        warn.events = ['passed', 'skipped', 'failed']\n        warn.exceptionFormat=\"full\"\n     }\n }\n\n\njacoco {\n    toolVersion = '0.7.7.201606060606' // See http://www.eclemma.org/jacoco/.\n}\n\njacocoTestReport {\n    reports {\n        xml.enabled = true\n        html.enabled = true\n    }\n}\n\nbuild.dependsOn jacocoTestReport\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/RxReactiveStreams.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx;\n\nimport org.reactivestreams.Publisher;\n\nimport rx.internal.reactivestreams.*;\n\n/**\n * This type provides static factory methods for converting to and from RxJava types and Reactive Streams types.\n * <p/>\n * The <a href=\"http://www.reactive-streams.org\">Reactive Streams</a> API provides a common API for interoperability\n * between different reactive streaming libraries, of which RxJava is one.\n * Using the methods of this class, RxJava can collaborate with other such libraries that also implement the standard.\n */\npublic abstract class RxReactiveStreams {\n\n    private RxReactiveStreams() {\n    }\n\n    /**\n     * Convert a Rx {@link Observable} into a Reactive Streams {@link Publisher}.\n     * <p/>\n     * Use this method when you have an RxJava observable, that you want to be consumed by another library.\n     *\n     * @param <T> the value type\n     * @param observable the {@link Observable} to convert\n     * @return the converted {@link Publisher}\n     */\n    public static <T> Publisher<T> toPublisher(Observable<T> observable) {\n        return new PublisherAdapter<T>(observable);\n    }\n\n    /**\n     * Convert a Reactive Streams {@link Publisher} into a Rx {@link Observable}.\n     * <p/>\n     * Use this method when you have a stream from another library, that you want to be consume as an RxJava observable.\n     *\n     * @param <T> the value type\n     * @param publisher the {@link Publisher} to convert.\n     * @return the converted {@link Observable}\n     */\n    public static <T> Observable<T> toObservable(final Publisher<T> publisher) {\n        return Observable.create(new Observable.OnSubscribe<T>() {\n            @Override\n            public void call(final rx.Subscriber<? super T> rxSubscriber) {\n                publisher.subscribe(toSubscriber(rxSubscriber));\n            }\n        });\n    }\n\n    /**\n     * Convert an RxJava {@link rx.Subscriber} into a Reactive Streams {@link org.reactivestreams.Subscriber}.\n     *\n     * @param <T> the value type\n     * @param rxSubscriber an RxJava subscriber\n     * @return a Reactive Streams subscriber\n     */\n    public static <T> org.reactivestreams.Subscriber<T> toSubscriber(final rx.Subscriber<T> rxSubscriber) {\n        return new SubscriberAdapter<T>(rxSubscriber);\n    }\n\n    /**\n     * Converts an RxJava Completable into a Publisher that emits only onError or onComplete.\n     * @param <T> the target value type\n     * @param completable the Completable instance to convert\n     * @return the new Publisher instance\n     * @since 1.1\n     * @throws NullPointerException if completable is null\n     */\n    public static <T> Publisher<T> toPublisher(Completable completable) {\n        if (completable == null) {\n            throw new NullPointerException(\"completable\");\n        }\n        return new CompletableAsPublisher<T>(completable);\n    }\n    \n    /**\n     * Converst a Publisher into a Completable by ignoring all onNext values and emitting\n     * onError or onComplete only.\n     * @param publisher the Publisher instance to convert\n     * @return the Completable instance\n     * @since 1.1\n     * @throws NullPointerException if publisher is null\n     */\n    public static Completable toCompletable(Publisher<?> publisher) {\n        if (publisher == null) {\n            throw new NullPointerException(\"publisher\");\n        }\n        return Completable.create(new PublisherAsCompletable(publisher));\n    }\n    \n    /**\n     * Converts a Single into a Publisher which emits an onNext+onComplete if\n     * the source Single signals a non-null onSuccess; or onError if the source signals\n     * onError(NullPointerException) or a null value.\n     * @param <T> the value type\n     * @param single the Single instance to convert\n     * @return the Publisher instance\n     * @since 1.1\n     * @throws NullPointerException if single is null\n     */\n    public static <T> Publisher<T> toPublisher(Single<T> single) {\n        if (single == null) {\n            throw new NullPointerException(\"single\");\n        }\n        return new SingleAsPublisher<T>(single);\n    }\n    \n    /**\n     * Converts a Publisher into a Single which emits onSuccess if the\n     * Publisher signals an onNext+onComplete; or onError if the publisher signals an\n     * onError, the source Publisher is empty (NoSuchElementException) or the\n     * source Publisher signals more than one onNext (IndexOutOfBoundsException).\n     * @param <T> the value type\n     * @param publisher the Publisher instance to convert\n     * @return the Single instance\n     * @since 1.1\n     * @throws NullPointerException if publisher is null\n     */\n    public static <T> Single<T> toSingle(Publisher<T> publisher) {\n        if (publisher == null) {\n            throw new NullPointerException(\"publisher\");\n        }\n        return Single.create(new PublisherAsSingle<T>(publisher));\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/CompletableAsPublisher.java",
    "content": "/**\n * Copyright 2016 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.internal.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\n\nimport rx.*;\n\n/**\n * Wraps a Completable and exposes it as a Publisher.\n *\n * @param <T> the value type of the publisher\n */\npublic final class CompletableAsPublisher<T> implements Publisher<T> {\n    \n    final Completable completable;\n\n    public CompletableAsPublisher(Completable completable) {\n        this.completable = completable;\n    }\n    \n    @Override\n    public void subscribe(Subscriber<? super T> s) {\n        if (s == null) {\n            throw new NullPointerException();\n        }\n        completable.subscribe(new CompletableAsPublisherSubscriber<T>(s));\n    }\n    \n    static final class CompletableAsPublisherSubscriber<T>\n    implements CompletableSubscriber, Subscription {\n\n        final Subscriber<? super T> actual;\n\n        rx.Subscription d;\n        \n        public CompletableAsPublisherSubscriber(Subscriber<? super T> actual) {\n            this.actual = actual;\n        }\n        \n        @Override\n        public void onSubscribe(rx.Subscription d) {\n            this.d = d;\n            actual.onSubscribe(this);\n        }\n        \n        @Override\n        public void onError(Throwable e) {\n            actual.onError(e);\n        }\n        \n        @Override\n        public void onCompleted() {\n            actual.onComplete();\n        }\n        \n        @Override\n        public void request(long n) {\n            // No values will be emitted\n        }\n        \n        @Override\n        public void cancel() {\n            d.unsubscribe();\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/PublisherAdapter.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.internal.reactivestreams;\n\nimport java.util.concurrent.atomic.*;\n\nimport org.reactivestreams.*;\n\nimport rx.Observable;\nimport rx.internal.operators.BackpressureUtils;\n\npublic class PublisherAdapter<T> implements Publisher<T> {\n\n    private final Observable<T> observable;\n\n    public PublisherAdapter(final Observable<T> observable) {\n        this.observable = observable.serialize();\n    }\n\n    @Override\n    public void subscribe(final Subscriber<? super T> s) {\n        observable.subscribe(new rx.Subscriber<T>() {\n            private final AtomicBoolean done = new AtomicBoolean();\n            private final AtomicLong childRequested = new AtomicLong();\n            private void doRequest(long n) {\n                if (!done.get()) {\n                    BackpressureUtils.getAndAddRequest(childRequested, n);\n                    request(n);\n                }\n            }\n\n            @Override\n            public void onStart() {\n                final AtomicBoolean requested = new AtomicBoolean();\n                s.onSubscribe(new Subscription() {\n                    @Override\n                    public void request(long n) {\n                        if (n < 1) {\n                            unsubscribe();\n                            onError(new IllegalArgumentException(\"3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.\"));\n                            return;\n                        }\n\n                        requested.set(true);\n                        doRequest(n);\n                    }\n\n                    @Override\n                    public void cancel() {\n                        unsubscribe();\n                        fireDone();\n                    }\n                });\n\n                if (!requested.get()) {\n                    request(0);\n                }\n            }\n\n            boolean fireDone() {\n                return done.compareAndSet(false, true);\n            }\n\n            @Override\n            public void onCompleted() {\n                if (fireDone()) {\n                    s.onComplete();\n                }\n            }\n\n            @Override\n            public void onError(Throwable e) {\n                if (fireDone()) {\n                    s.onError(e);\n                }\n            }\n\n            @Override\n            public void onNext(T t) {\n                if (!done.get()) {\n                    if (childRequested.get() > 0) {\n                        s.onNext(t);\n                        childRequested.decrementAndGet();\n                    } else {\n                        try {\n                            onError(new IllegalStateException(\"1.1 source doesn't respect backpressure\"));\n                        } finally {\n                            unsubscribe();\n                        }\n                    }\n                }\n            }\n        });\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/PublisherAsCompletable.java",
    "content": "/**\n * Copyright 2016 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.internal.reactivestreams;\n\nimport org.reactivestreams.*;\n\nimport rx.CompletableSubscriber;\n\n/**\n * Wraps an arbitrary Publisher and exposes it as a Completable, ignoring any onNext events.\n */\npublic final class PublisherAsCompletable implements rx.Completable.OnSubscribe {\n\n    final Publisher<?> publisher;\n\n    public PublisherAsCompletable(Publisher<?> publisher) {\n        this.publisher = publisher;\n    }\n    \n    @Override\n    public void call(CompletableSubscriber t) {\n        publisher.subscribe(new PublisherAsCompletableSubscriber(t));\n    }\n    \n    static final class PublisherAsCompletableSubscriber implements Subscriber<Object>, rx.Subscription {\n        \n        final CompletableSubscriber actual;\n\n        Subscription s;\n        \n        volatile boolean unsubscribed;\n        \n        public PublisherAsCompletableSubscriber(CompletableSubscriber actual) {\n            this.actual = actual;\n        }\n        \n        @Override\n        public void onSubscribe(Subscription s) {\n            this.s = s;\n            actual.onSubscribe(this);\n            s.request(Long.MAX_VALUE);\n        }\n        \n        @Override\n        public void onNext(Object t) {\n            // values are ignored\n        }\n        \n        @Override\n        public void onError(Throwable t) {\n            actual.onError(t);\n        }\n        \n        @Override\n        public void onComplete() {\n            actual.onCompleted();\n        }\n        \n        @Override\n        public boolean isUnsubscribed() {\n            return unsubscribed;\n        }\n        \n        @Override\n        public void unsubscribe() {\n            if (!unsubscribed) {\n                unsubscribed = true;\n                s.cancel();\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/PublisherAsSingle.java",
    "content": "/**\n * Copyright 2016 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.internal.reactivestreams;\n\nimport java.util.NoSuchElementException;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\n\nimport rx.*;\n\n/**\n * Wraps a Publisher and exposes it as a Single, signalling NoSuchElementException\n * if the Publisher is empty or IndexOutOfBoundsExcepion if the Publisher produces\n * more than one element.\n * \n * @param <T> the value type\n */\npublic final class PublisherAsSingle<T> implements Single.OnSubscribe<T> {\n    \n    final Publisher<T> publisher;\n\n    public PublisherAsSingle(Publisher<T> publisher) {\n        this.publisher = publisher;\n    }\n    \n    @Override\n    public void call(SingleSubscriber<? super T> t) {\n        publisher.subscribe(new PublisherAsSingleSubscriber<T>(t));\n    }\n    \n    static final class PublisherAsSingleSubscriber<T> implements Subscriber<T>, rx.Subscription {\n        \n        final SingleSubscriber<? super T> actual;\n        \n        Subscription s;\n        \n        T value;\n        \n        boolean hasValue;\n        \n        boolean done;\n\n        public PublisherAsSingleSubscriber(SingleSubscriber<? super T> actual) {\n            this.actual = actual;\n        }\n        \n        @Override\n        public void onSubscribe(Subscription s) {\n            this.s = s;\n            \n            actual.add(this);\n            \n            s.request(Long.MAX_VALUE);\n        }\n        \n        @Override\n        public void onNext(T t) {\n            if (done) {\n                return;\n            }\n            if (hasValue) {\n                done = true;\n                s.cancel();\n                actual.onError(new IndexOutOfBoundsException(\"The source Publisher emitted multiple values\"));\n            } else {\n                value = t;\n                hasValue = true;\n            }\n        }\n        \n        @Override\n        public void onError(Throwable t) {\n            if (done) {\n                return;\n            }\n            actual.onError(t);\n        }\n        \n        @Override\n        public void onComplete() {\n            if (done) {\n                return;\n            }\n            if (hasValue) {\n                T v = value;\n                value = null;\n                actual.onSuccess(v);\n            } else {\n                actual.onError(new NoSuchElementException(\"The source Publisher was empty\"));\n            }\n        }\n        \n        @Override\n        public boolean isUnsubscribed() {\n            return actual.isUnsubscribed();\n        }\n        \n        @Override\n        public void unsubscribe() {\n            s.cancel();\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/RxJavaSynchronizedProducer.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.internal.reactivestreams;\n\nimport java.util.*;\n\nimport org.reactivestreams.Subscription;\n\npublic final class RxJavaSynchronizedProducer implements rx.Producer, rx.Subscription {\n    private final Subscription subscription;\n    private volatile boolean unsubscribed;\n    /** Guarded by this. */\n    private boolean emitting;\n    /** Guarded by this. */\n    private List<Long> requests;\n    \n    public RxJavaSynchronizedProducer(Subscription subscription) {\n        if (subscription == null) {\n            throw new NullPointerException(\"subscription\");\n        }\n        this.subscription = subscription;\n    }\n    @Override\n    public boolean isUnsubscribed() {\n        return unsubscribed;\n    }\n    @Override\n    public void request(long n) {\n        if (n > 0 && !unsubscribed) {\n            synchronized (this) {\n                if (unsubscribed) {\n                    return;\n                }\n                if (emitting) {\n                    if (requests == null) {\n                        requests = new ArrayList<Long>(4);\n                    }\n                    requests.add(n);\n                    return;\n                }\n                emitting = true;\n            }\n            boolean skipFinal = false;\n            try {\n                subscription.request(n);\n                for (;;) {\n                    List<Long> list;\n                    synchronized (this) {\n                        list = requests;\n                        requests = null;\n                        if (list == null) {\n                            emitting = false;\n                            skipFinal = true;\n                            return;\n                        }\n                    }\n                    for (Long v : list) {\n                        if (v.longValue() == 0L) {\n                            unsubscribed = true;\n                            subscription.cancel();\n                            skipFinal = true;\n                            return;\n                        } else {\n                            subscription.request(v);\n                        }\n                    }\n                }\n            } finally {\n                if (!skipFinal) {\n                    synchronized (this) {\n                        emitting = false;\n                    }\n                }\n            }\n        }\n    }\n    @Override\n    public void unsubscribe() {\n        if (!unsubscribed) {\n            synchronized (this) {\n                if (unsubscribed) {\n                    return;\n                }\n                if (emitting) {\n                    // replace all pending requests with this single cancel indicator\n                    requests = new ArrayList<Long>(4);\n                    requests.add(0L);\n                    return;\n                }\n                emitting = true;\n            }\n            unsubscribed = true;\n            subscription.cancel();\n            // no need to leave emitting as this is a terminal state\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/SingleAsPublisher.java",
    "content": "/**\n * Copyright 2016 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.internal.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\nimport rx.Single;\nimport rx.SingleSubscriber;\n\nimport java.util.concurrent.atomic.AtomicInteger;\n\n/**\n * Wraps a Single and exposes it as a Publisher.\n *\n * @param <T> the value type\n */\npublic final class SingleAsPublisher<T> implements Publisher<T> {\n\n    final Single<T> single;\n\n    public SingleAsPublisher(Single<T> single) {\n        this.single = single;\n    }\n\n    @Override\n    public void subscribe(Subscriber<? super T> s) {\n        SingleAsPublisherSubscriber<T> parent = new SingleAsPublisherSubscriber<T>(s);\n        s.onSubscribe(parent);\n\n        single.subscribe(parent);\n    }\n\n    static final class SingleAsPublisherSubscriber<T> extends SingleSubscriber<T>\n    implements Subscription {\n\n        final Subscriber<? super T> actual;\n\n        final AtomicInteger state;\n\n        T value;\n\n        volatile boolean cancelled;\n\n        static final int NO_REQUEST_NO_VALUE = 0;\n        static final int NO_REQUEST_HAS_VALUE = 1;\n        static final int HAS_REQUEST_NO_VALUE = 2;\n        static final int HAS_REQUEST_HAS_VALUE = 3;\n\n        public SingleAsPublisherSubscriber(Subscriber<? super T> actual) {\n            this.actual = actual;\n            this.state = new AtomicInteger();\n        }\n\n        @Override\n        public void onSuccess(T value) {\n            if (cancelled) {\n                return;\n            }\n            if (value == null) {\n                state.lazySet(HAS_REQUEST_HAS_VALUE);\n                actual.onError(new NullPointerException(\"value\"));\n                return;\n            }\n            for (;;) {\n                int s = state.get();\n\n                if (s == NO_REQUEST_HAS_VALUE || s == HAS_REQUEST_HAS_VALUE || cancelled) {\n                    break;\n                } else\n                if (s == HAS_REQUEST_NO_VALUE) {\n                    actual.onNext(value);\n                    if (!cancelled) {\n                        actual.onComplete();\n                    }\n                    return;\n                } else {\n                    this.value = value;\n                    if (state.compareAndSet(s, NO_REQUEST_HAS_VALUE)) {\n                        break;\n                    }\n                }\n            }\n        }\n\n        @Override\n        public void onError(Throwable error) {\n            if (cancelled) {\n                return;\n            }\n            state.lazySet(HAS_REQUEST_HAS_VALUE);\n            actual.onError(error);\n        }\n\n        @Override\n        public void request(long n) {\n            if (n > 0) {\n                for (;;) {\n                    int s = state.get();\n                    if (s == HAS_REQUEST_HAS_VALUE || s == HAS_REQUEST_NO_VALUE || cancelled) {\n                        break;\n                    }\n                    if (s == NO_REQUEST_HAS_VALUE) {\n                        if (state.compareAndSet(s, HAS_REQUEST_HAS_VALUE)) {\n                            T v = value;\n                            value = null;\n\n                            actual.onNext(v);\n                            if (!cancelled) {\n                                actual.onComplete();\n                            }\n                        }\n                        break;\n                    }\n                    if (state.compareAndSet(NO_REQUEST_NO_VALUE, HAS_REQUEST_NO_VALUE)) {\n                        break;\n                    }\n                }\n            }\n        }\n\n        @Override\n        public void cancel() {\n            if (!cancelled) {\n                cancelled = true;\n                if (state.getAndSet(HAS_REQUEST_HAS_VALUE) == NO_REQUEST_HAS_VALUE) {\n                    value = null;\n                }\n                unsubscribe();\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/SubscriberAdapter.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.internal.reactivestreams;\n\nimport java.util.concurrent.atomic.AtomicBoolean;\n\nimport org.reactivestreams.*;\n\npublic class SubscriberAdapter<T> implements Subscriber<T> {\n\n    private final rx.Subscriber<? super T> rxSubscriber;\n    private final AtomicBoolean started = new AtomicBoolean();\n\n    public SubscriberAdapter(rx.Subscriber<? super T> rxSubscriber) {\n        this.rxSubscriber = rxSubscriber;\n    }\n\n    @Override\n    public void onSubscribe(final Subscription rsSubscription) {\n        if (rsSubscription == null) {\n            throw new NullPointerException(\"onSubscribe(null)\");\n        }\n\n        if (started.compareAndSet(false, true)) {\n            RxJavaSynchronizedProducer sp = new RxJavaSynchronizedProducer(rsSubscription);\n            rxSubscriber.add(sp);\n            rxSubscriber.setProducer(sp);\n        } else {\n            rsSubscription.cancel();\n        }\n    }\n\n    @Override\n    public void onNext(T t) {\n        if (t == null) {\n            throw new NullPointerException(\"onNext(null)\");\n        }\n        rxSubscriber.onNext(t);\n    }\n\n    @Override\n    public void onError(Throwable t) {\n        if (t == null) {\n            throw new NullPointerException(\"onError(null)\");\n        }\n        rxSubscriber.onError(t);\n    }\n\n    @Override\n    public void onComplete() {\n        rxSubscriber.onCompleted();\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/NonTckTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams;\n\nimport static org.testng.Assert.*;\nimport static org.testng.AssertJUnit.assertEquals;\nimport static org.testng.AssertJUnit.assertNotNull;\nimport static rx.RxReactiveStreams.toObservable;\nimport static rx.RxReactiveStreams.toPublisher;\n\nimport java.util.Arrays;\nimport java.util.concurrent.TimeUnit;\n\nimport org.reactivestreams.Publisher;\nimport org.testng.annotations.Test;\n\nimport rx.Observable;\nimport rx.Subscriber;\nimport rx.reactivestreams.test.IterablePublisher;\nimport rx.reactivestreams.test.RsSubscriber;\nimport rx.reactivestreams.test.RxSubscriber;\nimport rx.subjects.PublishSubject;\n\npublic class NonTckTest {\n\n    private <T> RsSubscriber<T> subscribe(Observable<T> observable) {\n        return subscribe(toPublisher(observable));\n    }\n\n    private <T> RsSubscriber<T> subscribe(Publisher<T> publisher) {\n        RsSubscriber<T> subscriber = new RsSubscriber<T>();\n        publisher.subscribe(subscriber);\n        return subscriber;\n    }\n\n    @Test\n    public void canSubscribeToObservableAsPublisher() {\n        RsSubscriber<Integer> subscriber = subscribe(Observable.just(1, 2, 3));\n\n        assertEquals(\"no items sent\", 0, subscriber.received.size());\n        subscriber.subscription.request(1);\n        assertEquals(\"one item sent\", 1, subscriber.received.size());\n        subscriber.subscription.request(2);\n        assertEquals(\"two items sent\", 3, subscriber.received.size());\n        assertTrue(subscriber.complete);\n        assertNull(subscriber.error);\n    }\n\n    @Test\n    public void canSubscribeToPublisherAsObservable() {\n        Publisher<Integer> publisher = new IterablePublisher<Integer>(Arrays.asList(1, 2, 3));\n        Observable<Integer> observable = toObservable(publisher);\n        RxSubscriber<Integer> subscriber = new RxSubscriber<Integer>(0);\n        observable.subscribe(subscriber);\n\n        assertEquals(\"no items sent\", 0, subscriber.received.size());\n        subscriber.makeRequest(1);\n        assertEquals(\"one item sent\", 1, subscriber.received.size());\n        subscriber.makeRequest(2);\n        assertEquals(\"two items sent\", 3, subscriber.received.size());\n        assertTrue(subscriber.complete);\n        assertNull(subscriber.error);\n    }\n\n    @Test\n    public void rxSubscriberNotMakingInitialRequestConsumesPublisher() {\n        Publisher<Integer> publisher = new IterablePublisher<Integer>(Arrays.asList(1, 2, 3));\n        Observable<Integer> observable = toObservable(publisher);\n        RxSubscriber<Integer> subscriber = new RxSubscriber<Integer>(-1); // -1 means no initial request\n        observable.subscribe(subscriber);\n\n        assertEquals(\"all items sent\", 3, subscriber.received.size());\n        assertTrue(subscriber.complete);\n        assertNull(subscriber.error);\n    }\n\n    @Test\n    void errorStatePublisherSendsSingleErrorPostSubscribe() {\n        RsSubscriber<Integer> subscriber = subscribe(Observable.<Integer>error(new RuntimeException(\"!\")));\n\n        // An error state observable always allows subscription, but then immediately sends onError.\n        // The spec suggests not trying to subscribe but immediately firing onError without an onSubscribe.\n        // However, this isn't a spec violation.\n        assertNotNull(subscriber.subscription);\n\n        assertFalse(subscriber.complete);\n        assertEquals(subscriber.error.getClass(), RuntimeException.class);\n        assertEquals(subscriber.error.getMessage(), \"!\");\n    }\n\n    @Test\n    void rxFailingOnSubscribeSendsSingleErrorPostSubscribe() {\n        RsSubscriber<Integer> subscriber = subscribe(Observable.create(new Observable.OnSubscribe<Integer>() {\n            @Override\n            public void call(Subscriber<? super Integer> subscriber) {\n                throw new RuntimeException(\"!\");\n            }\n        }));\n\n        // An error state observable always allows subscription, but then immediately sends onError.\n        // The spec suggests not trying to subscribe but immediately firing onError without an onSubscribe.\n        // However, this isn't a spec violation.\n        assertNotNull(subscriber.subscription);\n\n        assertFalse(subscriber.complete);\n        assertEquals(subscriber.error.getClass(), RuntimeException.class);\n        assertEquals(subscriber.error.getMessage(), \"!\");\n    }\n\n    @Test(enabled = false) // failing\n    void subscribingToHotObservableWithNoBackpressureStrategy() throws InterruptedException {\n        RsSubscriber<Long> subscriber = subscribe(Observable.interval(1, TimeUnit.NANOSECONDS));\n\n        // Long enough for the observable to fire if it's going to\n        Thread.sleep(10);\n        assertEquals(subscriber.received.size(), 0); // fails, data is coming through before being requested\n    }\n\n    @Test\n    void subscribingToHotObservableWithBackpressureStrategy() throws InterruptedException {\n        Observable<Long> observable = Observable.interval(1, TimeUnit.NANOSECONDS).onBackpressureDrop();\n        RsSubscriber<Long> subscriber = subscribe(observable);\n\n        subscriber.subscription.request(1);\n        subscriber.waitForNumItems(1);\n        assertEquals(subscriber.received.size(), 1);\n        assertNull(subscriber.error);\n\n        subscriber.subscription.request(10);\n        subscriber.waitForNumItems(11);\n        assertEquals(subscriber.received.size(), 11);\n        assertNull(subscriber.error);\n\n        subscriber.subscription.cancel();\n    }\n\n    @Test\n    public void subscribeToPublishSubjectEmitsRuleViolationException() {\n        PublishSubject<Integer> source = PublishSubject.create();\n        RsSubscriber<Integer> rxs = subscribe(source);\n        \n        source.onNext(1);\n        \n        assertEquals(0, rxs.received.size());\n        assertNotNull(rxs.error);\n    }\n    @Test\n    public void subscribeToPublishSubjectEmitsRuleViolationExceptionAfterOneRequest() {\n        PublishSubject<Integer> source = PublishSubject.create();\n        RsSubscriber<Integer> rxs = subscribe(source);\n        \n        rxs.subscription.request(1);\n        source.onNext(1);\n\n        source.onNext(2);\n\n        assertEquals(1, rxs.received.size());\n        assertNotNull(rxs.error);\n    }\n}"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckAsynchronousPublisherTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.PublisherVerification;\nimport org.reactivestreams.tck.TestEnvironment;\nimport org.testng.annotations.Test;\nimport rx.Observable;\nimport rx.RxReactiveStreams;\nimport rx.reactivestreams.test.CountdownIterable;\nimport rx.schedulers.Schedulers;\n\n@Test\npublic class TckAsynchronousPublisherTest extends PublisherVerification<Long> {\n\n    public TckAsynchronousPublisherTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)).observeOn(Schedulers.computation()));\n    }\n\n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        // Null because we always successfully subscribe.\n        // If the observable is in error state, it will subscribe and then emit the error as the first item\n        // This is not an “error state” publisher as defined by RS\n        return null;\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckCompletableAsyncConversionTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport java.io.IOException;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.*;\nimport org.testng.annotations.Test;\n\nimport rx.*;\nimport rx.schedulers.Schedulers;\n\n@Test\npublic class TckCompletableAsyncConversionTest extends PublisherVerification<Long> {\n\n    public TckCompletableAsyncConversionTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Completable.complete().observeOn(Schedulers.computation()));\n    }\n\n    @Override\n    public long maxElementsFromPublisher() {\n        return 0L;\n    }\n    \n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        return RxReactiveStreams.toPublisher(Completable.error(new IOException()).observeOn(Schedulers.computation()));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckCompletableConversionTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport java.io.IOException;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.*;\nimport org.testng.annotations.Test;\n\nimport rx.*;\n\n@Test\npublic class TckCompletableConversionTest extends PublisherVerification<Long> {\n\n    public TckCompletableConversionTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Completable.complete());\n    }\n\n    @Override\n    public long maxElementsFromPublisher() {\n        return 0L;\n    }\n    \n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        return RxReactiveStreams.toPublisher(Completable.error(new IOException()));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSingleAsyncConversionTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport java.io.IOException;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.*;\nimport org.testng.annotations.Test;\n\nimport rx.*;\nimport rx.schedulers.Schedulers;\n\n@Test\npublic class TckSingleAsyncConversionTest extends PublisherVerification<Long> {\n\n    public TckSingleAsyncConversionTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Single.just(1L).observeOn(Schedulers.computation()));\n    }\n\n    @Override\n    public long maxElementsFromPublisher() {\n        return 1L;\n    }\n    \n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        return RxReactiveStreams.toPublisher(Single.<Long>error(new IOException()).observeOn(Schedulers.computation()));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSingleConversionTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport java.io.IOException;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.*;\nimport org.testng.annotations.Test;\n\nimport rx.*;\n\n@Test\npublic class TckSingleConversionTest extends PublisherVerification<Long> {\n\n    public TckSingleConversionTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Single.just(1L));\n    }\n\n    @Override\n    public long maxElementsFromPublisher() {\n        return 1L;\n    }\n    \n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        return RxReactiveStreams.toPublisher(Single.<Long>error(new IOException()));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSubscriberBlackboxTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.tck.SubscriberBlackboxVerification;\nimport org.reactivestreams.tck.TestEnvironment;\nimport org.testng.annotations.Test;\nimport rx.Observable;\nimport rx.RxReactiveStreams;\nimport rx.internal.reactivestreams.SubscriberAdapter;\nimport rx.reactivestreams.test.CountdownIterable;\n\n@Test\npublic class TckSubscriberBlackboxTest extends SubscriberBlackboxVerification<Long> {\n\n    public static final long DEFAULT_TIMEOUT_MILLIS = 300L;\n\n    public TckSubscriberBlackboxTest() {\n        super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS));\n    }\n\n    @Override\n    public Subscriber<Long> createSubscriber() {\n        rx.Subscriber<Long> rxSubscriber = new rx.Subscriber<Long>() {\n\n            @Override\n            public void onStart() {\n                super.request(1);\n            }\n\n            @Override\n            public void onCompleted() {\n\n            }\n\n            @Override\n            public void onError(Throwable e) {\n\n            }\n\n            @Override\n            public void onNext(Long aLong) {\n                request(1);\n            }\n        };\n        rxSubscriber.onStart(); // Observable.subscribe() calls this automatically\n        return new SubscriberAdapter<Long>(rxSubscriber);\n    }\n\n    @Override\n    public Long createElement(int element) {\n        return Long.valueOf(Integer.toString(element));\n    }\n\n    @Override\n    public Publisher<Long> createHelperPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSubscriberWhiteboxTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\nimport org.reactivestreams.tck.SubscriberWhiteboxVerification;\nimport org.reactivestreams.tck.TestEnvironment;\nimport org.testng.annotations.Test;\nimport rx.Observable;\nimport rx.RxReactiveStreams;\nimport rx.internal.reactivestreams.SubscriberAdapter;\nimport rx.reactivestreams.test.CountdownIterable;\n\nimport java.util.concurrent.atomic.AtomicBoolean;\n\n@Test\npublic class TckSubscriberWhiteboxTest extends SubscriberWhiteboxVerification<Long> {\n\n    public static final long DEFAULT_TIMEOUT_MILLIS = 300L;\n\n    public TckSubscriberWhiteboxTest() {\n        super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS));\n    }\n\n    private static class IgnoreSubscriber<T> extends rx.Subscriber<T> {\n        @Override\n        public void onCompleted() {\n\n        }\n\n        @Override\n        public void onError(Throwable e) {\n\n        }\n\n        @Override\n        public void onNext(T t) {\n\n        }\n    }\n\n    @Override\n    public Subscriber<Long> createSubscriber(final WhiteboxSubscriberProbe<Long> probe) {\n        return new SubscriberAdapter<Long>(new IgnoreSubscriber<Long>()) {\n            @Override\n            public void onSubscribe(final Subscription rsSubscription) {\n                final AtomicBoolean cancelled = new AtomicBoolean();\n                super.onSubscribe(new Subscription() {\n                    @Override\n                    public void request(long n) {\n                        rsSubscription.request(n);\n                    }\n\n                    @Override\n                    public void cancel() {\n                        cancelled.set(true);\n                        rsSubscription.cancel();\n                    }\n                });\n                if (!cancelled.get()) {\n                    probe.registerOnSubscribe(new SubscriberPuppet() {\n                        @Override\n                        public void triggerRequest(long elements) {\n                            rsSubscription.request(elements);\n                        }\n\n                        @Override\n                        public void signalCancel() {\n                            rsSubscription.cancel();\n                        }\n                    });\n                }\n            }\n\n            @Override\n            public void onNext(Long aLong) {\n                probe.registerOnNext(aLong);\n                super.onNext(aLong);\n            }\n\n            @Override\n            public void onError(Throwable t) {\n                probe.registerOnError(t);\n                super.onError(t);\n            }\n\n            @Override\n            public void onComplete() {\n                probe.registerOnComplete();\n                super.onComplete();\n            }\n        };\n    }\n\n    @Override\n    public Long createElement(int element) {\n        return Long.valueOf(Integer.toString(element));\n    }\n\n    @Override\n    public Publisher<Long> createHelperPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSynchronousPublisherTest.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage rx.reactivestreams;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.tck.PublisherVerification;\nimport org.reactivestreams.tck.TestEnvironment;\nimport org.testng.annotations.Test;\nimport rx.Observable;\nimport rx.RxReactiveStreams;\nimport rx.reactivestreams.test.CountdownIterable;\n\n@Test\npublic class TckSynchronousPublisherTest extends PublisherVerification<Long> {\n\n    public TckSynchronousPublisherTest() {\n        super(new TestEnvironment(300L));\n    }\n\n    @Override\n    public Publisher<Long> createPublisher(long elements) {\n        return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));\n    }\n\n    @Override\n    public Publisher<Long> createFailedPublisher() {\n        // Null because we always successfully subscribe.\n        // If the observable is in error state, it will subscribe and then emit the error as the first item\n        // This is not an “error state” publisher as defined by RS\n        return null;\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/CompletableAsPublisherTest.java",
    "content": "package rx.reactivestreams.test;\n\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\n\nimport rx.*;\nimport rx.subjects.PublishSubject;\n\nimport static rx.RxReactiveStreams.*;\n\npublic class CompletableAsPublisherTest {\n\n    @Test(expectedExceptions = { NullPointerException.class })\n    public void nullCheck() {\n        toPublisher((Completable)null);\n    }\n    \n    @Test\n    public void empty() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        toPublisher(Completable.complete()).subscribe(ts);\n        \n        Assert.assertTrue(ts.complete);\n        Assert.assertNull(ts.error);\n        Assert.assertTrue(ts.received.isEmpty());\n    }\n\n    @Test\n    public void error() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        toPublisher(Completable.error(new RuntimeException(\"Forced failure\"))).subscribe(ts);\n        \n        Assert.assertFalse(ts.complete);\n        Assert.assertNotNull(ts.error);\n        Assert.assertTrue(ts.error instanceof RuntimeException);\n        Assert.assertEquals(ts.error.getMessage(), \"Forced failure\");\n        Assert.assertTrue(ts.received.isEmpty());\n    }\n    \n    @Test\n    public void cancellation() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        PublishSubject<Object> ps = PublishSubject.create();\n        \n        toPublisher(ps.toCompletable()).subscribe(ts);\n\n        Assert.assertTrue(ps.hasObservers());\n\n        ts.subscription.cancel();\n        \n        Assert.assertFalse(ts.complete);\n        Assert.assertNull(ts.error);\n        Assert.assertTrue(ts.received.isEmpty());\n        \n        Assert.assertFalse(ps.hasObservers());\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/CountdownIterable.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams.test;\n\nimport java.util.Iterator;\n\npublic class CountdownIterable implements Iterable<Long> {\n\n    private final long from;\n\n    public CountdownIterable(final long from) {\n        if (from < 0) {\n            throw new IllegalArgumentException(\"from < 0\");\n        }\n        this.from = from;\n    }\n\n    @Override\n    public Iterator<Long> iterator() {\n        return new Iterator<Long>() {\n            private long i = from;\n\n            @Override\n            public boolean hasNext() {\n                return i > 0;\n            }\n\n            @Override\n            public Long next() {\n                return --i;\n            }\n\n            @Override\n            public void remove() {\n                throw new UnsupportedOperationException();\n            }\n        };\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/IterablePublisher.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams.test;\n\nimport org.reactivestreams.Publisher;\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\n\nimport java.util.Iterator;\n\npublic class IterablePublisher<T> implements Publisher<T> {\n\n    private final Iterable<T> iterable;\n\n    public IterablePublisher(Iterable<T> iterable) {\n        this.iterable = iterable;\n    }\n\n    @Override\n    public void subscribe(final Subscriber<? super T> subscriber) {\n        subscriber.onSubscribe(new Subscription() {\n\n            Iterator<T> iterator = iterable.iterator();\n\n            @Override\n            public void request(long n) {\n                for (int i = 0; i < n; ++i) {\n                    if (iterator.hasNext()) {\n                        T next;\n                        try {\n                            next = iterator.next();\n                        } catch (Exception e) {\n                            subscriber.onError(e);\n                            return;\n                        }\n                        subscriber.onNext(next);\n                    } else {\n                        break;\n                    }\n                }\n\n                if (!iterator.hasNext()) {\n                    subscriber.onComplete();\n                }\n            }\n\n            @Override\n            public void cancel() {\n\n            }\n        });\n\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/PublisherAsCompletableTest.java",
    "content": "package rx.reactivestreams.test;\n\nimport static rx.RxReactiveStreams.*;\n\nimport org.reactivestreams.*;\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\n\nimport rx.observers.TestSubscriber;\nimport rx.subjects.PublishSubject;\n\npublic class PublisherAsCompletableTest {\n\n    @Test(expectedExceptions = { NullPointerException.class })\n    public void nullCheck() {\n        toCompletable(null);\n    }\n    \n    @Test\n    public void empty() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n        \n        toCompletable(new PublisherEmpty()).subscribe(ts);\n\n        ts.assertNoValues();\n        ts.assertCompleted();\n        ts.assertNoErrors();\n    }\n\n    @Test\n    public void error() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n        \n        toCompletable(new PublisherFail()).subscribe(ts);\n        \n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertError(RuntimeException.class);\n        Assert.assertEquals(ts.getOnErrorEvents().get(0).getMessage(), \"Forced failure\");\n    }\n    \n    @Test\n    public void cancellation() {\n        PublishSubject<Object> ps = PublishSubject.create();\n\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n        \n        toCompletable(toPublisher(ps)).subscribe(ts);\n        \n        Assert.assertTrue(ps.hasObservers());\n\n        ts.unsubscribe();\n        \n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertNoErrors();\n        \n        Assert.assertFalse(ps.hasObservers());\n    }\n\n    static final class PublisherEmpty implements Publisher<Object> {\n        @Override\n        public void subscribe(Subscriber<? super Object> s) {\n            final boolean[] cancelled = { false };\n            s.onSubscribe(new Subscription() {\n                @Override\n                public void request(long n) {\n                    \n                }\n                \n                @Override\n                public void cancel() {\n                    cancelled[0] = true;\n                }\n            });\n            if (!cancelled[0]) {\n                s.onComplete();\n            }\n        }\n    }\n\n    static final class PublisherFail implements Publisher<Object> {\n        @Override\n        public void subscribe(Subscriber<? super Object> s) {\n            final boolean[] cancelled = { false };\n            s.onSubscribe(new Subscription() {\n                @Override\n                public void request(long n) {\n                    \n                }\n                \n                @Override\n                public void cancel() {\n                    cancelled[0] = true;\n                }\n            });\n            if (!cancelled[0]) {\n                s.onError(new RuntimeException(\"Forced failure\"));\n            }\n        }\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/PublisherAsSingleTest.java",
    "content": "package rx.reactivestreams.test;\n\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\nimport rx.Observable;\nimport rx.Single;\nimport rx.observers.TestSubscriber;\nimport rx.reactivestreams.test.PublisherAsCompletableTest.PublisherEmpty;\nimport rx.reactivestreams.test.PublisherAsCompletableTest.PublisherFail;\nimport rx.schedulers.Schedulers;\nimport rx.subjects.PublishSubject;\n\nimport java.util.NoSuchElementException;\nimport java.util.concurrent.TimeUnit;\n\nimport static rx.RxReactiveStreams.toPublisher;\nimport static rx.RxReactiveStreams.toSingle;\n\npublic class PublisherAsSingleTest {\n\n    @Test(expectedExceptions = { NullPointerException.class })\n    public void nullCheck() {\n        toPublisher((Single<Object>)null);\n    }\n\n    @Test\n    public void just() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(toPublisher(Observable.just(1))).subscribe(ts);\n\n        ts.assertValue(1);\n        ts.assertCompleted();\n        ts.assertNoErrors();\n    }\n\n    @Test\n    public void singleJust() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(toPublisher(Single.just(1))).subscribeOn(Schedulers.computation()).subscribe(ts);\n\n        ts.awaitTerminalEvent(3, TimeUnit.SECONDS);\n\n        ts.assertValue(1);\n        ts.assertCompleted();\n        ts.assertNoErrors();\n    }\n\n    @Test\n    public void empty() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(new PublisherEmpty()).subscribe(ts);\n\n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertError(NoSuchElementException.class);\n    }\n\n    @Test\n    public void range() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(toPublisher(Observable.range(1, 2))).subscribe(ts);\n\n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertError(IndexOutOfBoundsException.class);\n    }\n\n    @Test\n    public void error() {\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(new PublisherFail()).subscribe(ts);\n\n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertError(RuntimeException.class);\n        Assert.assertEquals(ts.getOnErrorEvents().get(0).getMessage(), \"Forced failure\");\n    }\n\n    @Test\n    public void cancellation() {\n        PublishSubject<Object> ps = PublishSubject.create();\n\n        TestSubscriber<Object> ts = new TestSubscriber<Object>();\n\n        toSingle(toPublisher(ps)).subscribe(ts);\n\n        Assert.assertTrue(ps.hasObservers());\n\n        ts.unsubscribe();\n\n        ts.assertNoValues();\n        ts.assertNotCompleted();\n        ts.assertNoErrors();\n\n        Assert.assertFalse(ps.hasObservers());\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/RsSubscriber.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams.test;\n\nimport org.reactivestreams.Subscriber;\nimport org.reactivestreams.Subscription;\n\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.concurrent.ConcurrentLinkedQueue;\nimport java.util.concurrent.CopyOnWriteArrayList;\nimport java.util.concurrent.CountDownLatch;\n\npublic class RsSubscriber<T> implements Subscriber<T> {\n\n    public final Queue<T> received = new ConcurrentLinkedQueue<T>();\n    public volatile Subscription subscription;\n    public volatile Throwable error;\n    public volatile boolean complete;\n\n    private static class Wait {\n        private final long count;\n        private final CountDownLatch latch;\n\n        public Wait(long count, CountDownLatch latch) {\n            this.count = count;\n            this.latch = latch;\n        }\n    }\n\n    private final List<Wait> waits = new CopyOnWriteArrayList<Wait>();\n\n    @Override\n    public void onSubscribe(Subscription s) {\n        if (s == null) {\n            throw new NullPointerException(\"onSubscribe(null)\");\n        }\n\n        subscription = s;\n    }\n\n    @Override\n    public void onNext(T t) {\n        if (t == null) {\n            throw new NullPointerException(\"onNext(null)\");\n        }\n        received.add(t);\n        for (Wait wait : waits) {\n            if (received.size() >= wait.count) {\n                wait.latch.countDown();\n            }\n        }\n    }\n\n    @Override\n    public void onError(Throwable t) {\n        if (t == null) {\n            throw new NullPointerException(\"onError(null)\");\n        }\n        error = t;\n        unwaitAll();\n    }\n\n    @Override\n    public void onComplete() {\n        complete = true;\n        unwaitAll();\n    }\n\n    public void waitForNumItems(long n) throws InterruptedException {\n        if (complete || error != null) {\n            return;\n        }\n\n        CountDownLatch latch = new CountDownLatch(1);\n        waits.add(new Wait(n, latch));\n\n        if (complete || error != null) {\n            unwaitAll();\n        }\n\n        if (received.size() >= n) {\n            latch.countDown();\n        }\n\n        latch.await();\n    }\n\n    private void unwaitAll() {\n        while (!waits.isEmpty()) {\n            waits.remove(0).latch.countDown();\n        }\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/RxSubscriber.java",
    "content": "/**\n * Copyright 2014 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams.test;\n\nimport rx.Subscriber;\n\nimport java.util.LinkedList;\nimport java.util.List;\n\npublic class RxSubscriber<T> extends Subscriber<T> {\n\n    public final List<T> received = new LinkedList<T>();\n    private final long initialRequest;\n    public Throwable error;\n    public boolean complete;\n\n    public RxSubscriber(long initialRequest) {\n        this.initialRequest = initialRequest;\n    }\n\n    @Override\n    public void onStart() {\n        if (initialRequest >= 0) {\n            request(initialRequest);\n        }\n    }\n\n    @Override\n    public void onCompleted() {\n        complete = true;\n    }\n\n    @Override\n    public void onError(Throwable e) {\n        error = e;\n    }\n\n    @Override\n    public void onNext(T t) {\n        received.add(t);\n    }\n\n    public void makeRequest(long n) {\n        request(n);\n    }\n\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/SingleAsPublisherTest.java",
    "content": "package rx.reactivestreams.test;\n\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\n\nimport rx.*;\nimport rx.subjects.PublishSubject;\n\nimport static rx.RxReactiveStreams.*;\n\npublic class SingleAsPublisherTest {\n\n    @Test(expectedExceptions = { NullPointerException.class })\n    public void nullCheck() {\n        toPublisher((Single<Object>)null);\n    }\n    \n    @Test\n    public void just() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        toPublisher(Single.just(1)).subscribe(ts);\n\n        Assert.assertFalse(ts.complete);\n        Assert.assertNull(ts.error);\n        Assert.assertTrue(ts.received.isEmpty());\n\n        ts.subscription.request(1);\n        \n        Assert.assertTrue(ts.complete);\n        Assert.assertNull(ts.error);\n        Assert.assertEquals(ts.received.size(), 1);\n        Assert.assertEquals(ts.received.poll(), 1);\n    }\n\n    @Test\n    public void justNull() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        toPublisher(Single.just(null)).subscribe(ts);\n        \n        Assert.assertFalse(ts.complete);\n        Assert.assertNotNull(ts.error);\n        Assert.assertTrue(ts.error instanceof NullPointerException);\n        Assert.assertTrue(ts.received.isEmpty());\n    }\n\n    @Test\n    public void error() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        toPublisher(Single.error(new RuntimeException(\"Forced failure\"))).subscribe(ts);\n        \n        Assert.assertFalse(ts.complete);\n        Assert.assertNotNull(ts.error);\n        Assert.assertTrue(ts.error instanceof RuntimeException);\n        Assert.assertEquals(ts.error.getMessage(), \"Forced failure\");\n        Assert.assertTrue(ts.received.isEmpty());\n    }\n    \n    @Test\n    public void cancellation() {\n        RsSubscriber<Object> ts = new RsSubscriber<Object>();\n        \n        PublishSubject<Object> ps = PublishSubject.create();\n        \n        toPublisher(ps.toSingle()).subscribe(ts);\n\n        Assert.assertTrue(ps.hasObservers());\n\n        ts.subscription.cancel();\n        \n        Assert.assertFalse(ts.complete);\n        Assert.assertNull(ts.error);\n        Assert.assertTrue(ts.received.isEmpty());\n        \n        Assert.assertFalse(ps.hasObservers());\n    }\n}\n"
  },
  {
    "path": "rxjava-reactive-streams/src/test/java/rx/reactivestreams/test/WrapUnwrap.java",
    "content": "/**\n * Copyright 2016 Netflix, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage rx.reactivestreams.test;\n\nimport org.reactivestreams.Publisher;\nimport org.testng.annotations.Test;\n\nimport rx.*;\nimport rx.functions.Func1;\n\npublic class WrapUnwrap {\n\n    @Test\n    public void wrapUnwrap() {\n        \n        Observable<Integer> o = Observable.range(1, 350);\n\n        Observable<Publisher<Integer>> p = Observable.just(\n                RxReactiveStreams.toPublisher(o)).asObservable();\n\n        for (int u : p.flatMap(new Func1<Publisher<Integer>, Observable<Integer>>() {\n            @Override\n            public Observable<Integer> call(Publisher<Integer> v) {\n                return RxReactiveStreams.toObservable(v);\n            }\n        })\n                .toBlocking()\n                .toIterable()) {\n            System.out.println(u);\n        }\n    \n    }\n}\n"
  },
  {
    "path": "settings.gradle",
    "content": "rootProject.name = 'rxjava-reactive-streams'\n\ninclude \"rxjava-reactive-streams\"\n\nif (JavaVersion.current().java8Compatible) {\n    include \"examples:ratpack\"\n}\n"
  }
]