removed unneeded stream close

This commit is contained in:
Mariotaku Lee 2017-08-29 15:56:21 +08:00
parent c66597b085
commit e742703bc0
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 10 additions and 15 deletions

View File

@ -22,7 +22,6 @@ import android.support.annotation.NonNull;
import org.mariotaku.microblog.library.MicroBlogException;
import org.mariotaku.restfu.RestConverter;
import org.mariotaku.restfu.RestFuUtils;
import org.mariotaku.restfu.http.ContentType;
import org.mariotaku.restfu.http.HttpResponse;
import org.mariotaku.restfu.http.mime.Body;
@ -41,21 +40,17 @@ public class OAuthTokenResponseConverter implements RestConverter<HttpResponse,
@Override
public OAuthToken convert(@NonNull HttpResponse response) throws IOException, ConvertException {
final Body body = response.getBody();
final ContentType contentType = body.contentType();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
body.writeTo(os);
Charset charset = contentType != null ? contentType.getCharset() : null;
if (charset == null) {
charset = Charset.defaultCharset();
}
try {
final ContentType contentType = body.contentType();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
body.writeTo(os);
Charset charset = contentType != null ? contentType.getCharset() : null;
if (charset == null) {
charset = Charset.defaultCharset();
}
try {
return new OAuthToken(os.toString(charset.name()), charset);
} catch (ParseException e) {
throw new ConvertException(e);
}
} finally {
RestFuUtils.closeSilently(body);
return new OAuthToken(os.toString(charset.name()), charset);
} catch (ParseException e) {
throw new ConvertException(e);
}
}
}