Chromium Code Reviews| 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.IOException; | |
| 8 import java.io.InputStream; | |
| 9 import java.nio.ByteBuffer; | |
| 10 | |
| 11 /** | |
| 12 * An InputStream that is used by {@link CronetHttpURLConnection} to request | |
| 13 * data from the network stack as needed. | |
| 14 */ | |
| 15 class CronetInputStream extends InputStream { | |
|
mef
2014/12/04 20:37:56
nit: Given that CronetUrlRequestListener is a priv
xunjieli
2014/12/04 20:55:53
I don't think there's any use case for it to be us
| |
| 16 private final CronetHttpURLConnection mHttpURLConnection; | |
| 17 // Indicates whether listener's onSucceeded or onFailed callback is invoked. | |
| 18 private boolean mResponseDataCompleted; | |
| 19 private ByteBuffer mBuffer; | |
| 20 | |
| 21 /** | |
| 22 * Constructs a CronetInputStream. | |
| 23 * @param httpURLConnection the CronetHttpURLConnection that is associated | |
| 24 * with this InputStream. | |
| 25 */ | |
| 26 public CronetInputStream(CronetHttpURLConnection httpURLConnection) { | |
| 27 mHttpURLConnection = httpURLConnection; | |
| 28 } | |
| 29 | |
| 30 @Override | |
| 31 public int read() throws IOException { | |
| 32 if (!mResponseDataCompleted | |
| 33 && (mBuffer == null || !mBuffer.hasRemaining())) { | |
| 34 // Requests more data from CronetHttpURLConnection. | |
| 35 mBuffer = mHttpURLConnection.getMoreData(); | |
| 36 } | |
| 37 if (mBuffer != null && mBuffer.hasRemaining()) { | |
| 38 return mBuffer.get() & 0xFF; | |
| 39 } | |
| 40 return -1; | |
| 41 } | |
| 42 | |
| 43 void setResponseDataCompleted() { | |
| 44 mResponseDataCompleted = true; | |
| 45 } | |
| 46 } | |
| OLD | NEW |