-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipe for tee #186
Comments
I rearranged to instead use the original BufferedSource to create the
|
You can use What you want is to write the stream to another sink while the application pulls bytes off the wire. OkHttp's cache behaves like this, and you should copy what it does. I can grab a pointer in the source if you can't find it when I get home. |
Yeah definitely don't want to copy. A pointer would be appreciated. |
|
thanks! I won't tell you how many times I read Cache.java today trying to figure it out |
After 2 tweets and 2 issue comments I finally got it. Thanks @JakeWharton & @swankjesse in case anyone else needs a working example here's the relevant parts. |
By the way you can use |
Reopening in preparation of pr. Going to add @nonnull |
Wasn't sure if that was a placeholder term first time you suggested it.
|
bump Hi! Is a recipe now documented somewhere for this (i.e.: single producer, multiple consumer)? |
No recipe. The closest we have is this: |
https://twitter.com/jessewilson/status/692326663061966848
Original issue:
I'm struggling with reading from a BufferedSource twice. What I'm trying to do is take an okhttp response body and stream it to both a parser and a file. First I created 2
Buffer
instances from sameBufferedSource
next I wrap aBuffer
in anInputStreamReader
and gracefully (or so I thought) pass it to gson. What I get isMalformedJsonException
If I however simply do
body.source().readUtf8Line()
I get the full raw json.full example:
It seems like Buffers are perfectly suited for taking a single source and streaming in multiple direction, would love to finally bring it all together. Thank you for your help.
The text was updated successfully, but these errors were encountered: