Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java

Issue 725683002: [Cronet] Initial implementation of HttpURLConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added throw clause Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
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 (mBuffer == null
33 || (!mBuffer.hasRemaining() && !mResponseDataCompleted)) {
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698