Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java |
| index 345fa26c7d54c0e4fd9ea924552602f18a963a9d..872adccaec9df2554f2cdb1740bf39e210cd35c6 100644 |
| --- a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java |
| @@ -17,6 +17,7 @@ class CronetInputStream extends InputStream { |
| // Indicates whether listener's onSucceeded or onFailed callback is invoked. |
| private boolean mResponseDataCompleted; |
| private ByteBuffer mBuffer; |
| + private IOException mException; |
| private static final int READ_BUFFER_SIZE = 32 * 1024; |
| @@ -58,15 +59,24 @@ class CronetInputStream extends InputStream { |
| /** |
| * Called by {@link CronetHttpURLConnection} to notify that the entire |
| * response body has been read. |
| + * @param exception if not null, it is the exception to throw when caller |
|
pauljensen
2015/11/10 15:55:21
here and elsewhere:
null->{@code null}
xunjieli
2015/11/10 16:16:59
Done.
|
| + * tries to read more data than what is buffered. |
| */ |
| - void setResponseDataCompleted() { |
| + void setResponseDataCompleted(IOException exception) { |
| + mException = exception; |
| mResponseDataCompleted = true; |
| // Nothing else to read, so can free the buffer. |
| mBuffer = null; |
| } |
| private void getMoreDataIfNeeded() throws IOException { |
| - if (!mResponseDataCompleted && !hasUnreadData()) { |
| + if (mResponseDataCompleted) { |
| + if (mException != null) { |
| + throw mException; |
| + } |
| + return; |
| + } |
| + if (!hasUnreadData()) { |
| // Allocate read buffer if needed. |
| if (mBuffer == null) { |
| mBuffer = ByteBuffer.allocateDirect(READ_BUFFER_SIZE); |
| @@ -75,6 +85,9 @@ class CronetInputStream extends InputStream { |
| // Requests more data from CronetHttpURLConnection. |
| mHttpURLConnection.getMoreData(mBuffer); |
| + if (mException != null) { |
| + throw mException; |
| + } |
| if (mBuffer != null) { |
| mBuffer.flip(); |
| } |