OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net.urlconnection; | 5 package org.chromium.net.urlconnection; |
6 | 6 |
7 import java.io.IOException; | 7 import java.io.IOException; |
8 import java.io.InputStream; | 8 import java.io.InputStream; |
9 import java.nio.ByteBuffer; | 9 import java.nio.ByteBuffer; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 && (mBuffer == null || !mBuffer.hasRemaining())) { | 33 && (mBuffer == null || !mBuffer.hasRemaining())) { |
34 // Requests more data from CronetHttpURLConnection. | 34 // Requests more data from CronetHttpURLConnection. |
35 mBuffer = mHttpURLConnection.getMoreData(); | 35 mBuffer = mHttpURLConnection.getMoreData(); |
36 } | 36 } |
37 if (mBuffer != null && mBuffer.hasRemaining()) { | 37 if (mBuffer != null && mBuffer.hasRemaining()) { |
38 return mBuffer.get() & 0xFF; | 38 return mBuffer.get() & 0xFF; |
39 } | 39 } |
40 return -1; | 40 return -1; |
41 } | 41 } |
42 | 42 |
43 @Override | |
44 public int read(byte[] buffer, int byteOffset, int byteCount) throws IOExcep tion { | |
mmenke
2015/03/05 19:24:46
Should our argument names match the official spec?
mmenke
2015/03/05 19:24:46
Maybe:
if (byteCount == 0)
return 0;
xunjieli
2015/03/05 20:55:13
Done.
xunjieli
2015/03/05 20:55:13
I am following the Android specs at http://develop
| |
45 if (!mResponseDataCompleted && (mBuffer == null || !mBuffer.hasRemaining ())) { | |
46 // Requests more data from CronetHttpURLConnection. | |
47 mBuffer = mHttpURLConnection.getMoreData(); | |
48 } | |
mmenke
2015/03/05 19:24:46
Suggest turning this block into a private method,
xunjieli
2015/03/05 20:55:13
Done.
| |
49 if (mBuffer != null && mBuffer.hasRemaining()) { | |
50 int oldPosition = mBuffer.position(); | |
51 mBuffer.get( | |
52 buffer, byteOffset, Math.min(mBuffer.limit() - mBuffer.posit ion(), byteCount)); | |
53 return mBuffer.position() - oldPosition; | |
mmenke
2015/03/05 19:24:46
Is there any case where this is different from the
xunjieli
2015/03/05 20:55:13
Done. Thanks!
| |
54 } | |
55 return -1; | |
56 } | |
57 | |
43 void setResponseDataCompleted() { | 58 void setResponseDataCompleted() { |
44 mResponseDataCompleted = true; | 59 mResponseDataCompleted = true; |
45 } | 60 } |
46 } | 61 } |
OLD | NEW |