Back to project page android-rest-client.
The source code is released under:
Apache License
If you think the Android project android-rest-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dg.libs.rest.requests; //ww w .j a va 2 s.c o m import com.squareup.okhttp.MediaType; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.internal.Util; import java.io.IOException; import java.io.InputStream; import okio.BufferedSink; import okio.Okio; import okio.Source; public class RequestBodyUtils { public static RequestBody create(final MediaType mediaType, final InputStream inputStream) { return new RequestBody() { @Override public MediaType contentType() { return mediaType; } @Override public long contentLength() { try { return inputStream.available(); } catch (IOException e) { return 0; } } @Override public void writeTo(BufferedSink sink) throws IOException { Source source = null; try { source = Okio.source(inputStream); sink.writeAll(source); } finally { Util.closeQuietly(source); } } }; } }