Skip to content

Commit

Permalink
Merge pull request square#1282 from square/jw/sources-and-sinks
Browse files Browse the repository at this point in the history
Use Sources and Sinks for all IO.
  • Loading branch information
JakeWharton committed Jan 4, 2015
2 parents 7000edd + f6c3ab9 commit 607fb15
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import okio.Buffer;
import okio.Okio;
import okio.Source;

/** A scripted response to be replayed by the mock web server. */
public final class MockResponse implements Cloneable {
Expand Down Expand Up @@ -133,13 +135,8 @@ public Buffer getBody() {
return body != null ? body.clone() : null; // Defensive copy.
}

/** Returns an input stream containing the raw HTTP payload. */
InputStream getBodyStream() {
if (bodyStream != null) {
return bodyStream;
}
Buffer body = getBody();
return body != null ? body.inputStream() : null;
Source getBodySource() {
return bodyStream != null ? Okio.source(bodyStream) : getBody();
}

public MockResponse setBody(byte[] body) {
Expand Down
Loading

0 comments on commit 607fb15

Please sign in to comment.