| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.net.urlconnection; |
| 6 |
| 7 import java.io.InputStream; |
| 8 import java.nio.ByteBuffer; |
| 9 |
| 10 /** |
| 11 * An InputStream that is used by {@link CronetHttpURLConnection} to request |
| 12 * data from the network stack as needed. |
| 13 */ |
| 14 class CronetInputStream extends InputStream { |
| 15 private final CronetHttpURLConnection mHttpURLConnection; |
| 16 // Indicates whether listener's onSucceeded or onFailed callback is invoked. |
| 17 private boolean mResponseDataCompleted; |
| 18 private ByteBuffer mBuffer; |
| 19 |
| 20 /** |
| 21 * Constructs a CronetInputStream. |
| 22 * @param httpURLConnection the CronetHttpURLConnection that is associated |
| 23 * with this InputStream. |
| 24 */ |
| 25 public CronetInputStream(CronetHttpURLConnection httpURLConnection) { |
| 26 mHttpURLConnection = httpURLConnection; |
| 27 } |
| 28 |
| 29 @Override |
| 30 public int read() { |
| 31 if (mBuffer == null |
| 32 || (!mBuffer.hasRemaining() && !mResponseDataCompleted)) { |
| 33 // Requests more data from CronetHttpURLConnection. |
| 34 mBuffer = mHttpURLConnection.requestData(); |
| 35 } |
| 36 if (mBuffer.hasRemaining()) { |
| 37 return mBuffer.get() & 0xFF; |
| 38 } |
| 39 return -1; |
| 40 } |
| 41 |
| 42 void setResponseDataCompleted() { |
| 43 mResponseDataCompleted = true; |
| 44 } |
| 45 } |
| OLD | NEW |