Created
August 13, 2020 05:32
-
-
Save raghunandankavi2010/29da86022839a625842d4de0d5a8b306 to your computer and use it in GitHub Desktop.
InputStreamRequestBody https://github.com/square/okhttp/issues/3585
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InputStreamRequestBody extends RequestBody { | |
private final MediaType contentType; | |
private final ContentResolver contentResolver; | |
private final Uri uri; | |
public InputStreamRequestBody(MediaType contentType, ContentResolver contentResolver, Uri uri) { | |
if (uri == null) throw new NullPointerException("uri == null"); | |
this.contentType = contentType; | |
this.contentResolver = contentResolver; | |
this.uri = uri; | |
} | |
@Nullable | |
@Override | |
public MediaType contentType() { | |
return contentType; | |
} | |
@Override | |
public long contentLength() throws IOException { | |
return -1; | |
} | |
@Override | |
public void writeTo(@NonNull BufferedSink sink) throws IOException { | |
try (Source source = Okio.source(contentResolver.openInputStream(uri))) { | |
sink.writeAll(source); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment