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

Unified 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: make loop failed in all exceptions 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..fc72ab11b6c23360b846cca35160d633fce4667f
--- /dev/null
+++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetInputStream.java
@@ -0,0 +1,46 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.net.urlconnection;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * An InputStream that is used by {@link CronetHttpURLConnection} to request
+ * data from the network stack as needed.
+ */
+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
+ private final CronetHttpURLConnection mHttpURLConnection;
+ // Indicates whether listener's onSucceeded or onFailed callback is invoked.
+ private boolean mResponseDataCompleted;
+ private ByteBuffer mBuffer;
+
+ /**
+ * Constructs a CronetInputStream.
+ * @param httpURLConnection the CronetHttpURLConnection that is associated
+ * with this InputStream.
+ */
+ public CronetInputStream(CronetHttpURLConnection httpURLConnection) {
+ mHttpURLConnection = httpURLConnection;
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (!mResponseDataCompleted
+ && (mBuffer == null || !mBuffer.hasRemaining())) {
+ // Requests more data from CronetHttpURLConnection.
+ mBuffer = mHttpURLConnection.getMoreData();
+ }
+ if (mBuffer != null && mBuffer.hasRemaining()) {
+ return mBuffer.get() & 0xFF;
+ }
+ return -1;
+ }
+
+ void setResponseDataCompleted() {
+ mResponseDataCompleted = true;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698