{"action":"opened","issue":{"url":"https://api.github.com/repos/square/okio/issues/255","repository_url":"https://api.github.com/repos/square/okio","labels_url":"https://api.github.com/repos/square/okio/issues/255/labels{/name}","comments_url":"https://api.github.com/repos/square/okio/issues/255/comments","events_url":"https://api.github.com/repos/square/okio/issues/255/events","html_url":"https://github.com/square/okio/issues/255","id":172167228,"number":255,"title":"Writing a Source to multiple Okhttp request. ","user":{"login":"RoryKelly","id":1162214,"avatar_url":"https://avatars.githubusercontent.com/u/1162214?v=3","gravatar_id":"","url":"https://api.github.com/users/RoryKelly","html_url":"https://github.com/RoryKelly","followers_url":"https://api.github.com/users/RoryKelly/followers","following_url":"https://api.github.com/users/RoryKelly/following{/other_user}","gists_url":"https://api.github.com/users/RoryKelly/gists{/gist_id}","starred_url":"https://api.github.com/users/RoryKelly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoryKelly/subscriptions","organizations_url":"https://api.github.com/users/RoryKelly/orgs","repos_url":"https://api.github.com/users/RoryKelly/repos","events_url":"https://api.github.com/users/RoryKelly/events{/privacy}","received_events_url":"https://api.github.com/users/RoryKelly/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-19T16:15:00Z","updated_at":"2016-08-19T16:15:00Z","closed_at":null,"body":"Im aware this is a strange requirement but hear me out.\r\n\r\n\r\nLets imagine I'm reading binary data from a hardware sensor, like a microphone. Then I'm sending this data across the wire via Okhttp.\r\n\r\n```\r\nSource source = AudioSource.getSource();\r\nserver.sendData(source);\r\n```\r\n\r\nBecause we want to stream the data when the web request starts. we use the Recipe for streaming from Okhttp.\r\n\r\n```\r\nvoid sendData(Source source){\r\n   RequestBody requestBody = new RequestBody() {\r\n               @Override public MediaType contentType() {\r\n                    return MediaType.parse(\"application/octet-stream\");\r\n                }\r\n\r\n                @Override public void writeTo(final BufferedSink sink) throws IOException {\r\n                    sink.write(source);\r\n                }\r\n    };\r\n\r\n    Request request = new Request.Builder()\r\n        .url(\"https://api.github.com/markdown/raw\")\r\n        .post(requestBody)\r\n        .build();\r\n\r\n    Response response = client.newCall(request).execute();\r\n    if (!response.isSuccessful()) throw new IOException(\"Unexpected code \" + response);\r\n...\r\n}\r\n```"}}
{"actor":{"display_login":"RoryKelly"}}