Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a30ab21147a9d2c545212fb38eac6580da8566e6 |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java |
| @@ -0,0 +1,42 @@ |
| +// 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.InputStream; |
| +import java.nio.ByteBuffer; |
| + |
| +/** |
| + * Wrapper class to construct an InputSteam based on a ByteBuffer. |
| + */ |
| +class ByteBufferInputStream extends InputStream { |
|
mmenke
2014/11/20 18:52:36
Suggest a more specific name, since this isn't rea
xunjieli
2014/11/20 20:31:59
Done.
|
| + private final MessageLoop mMessageLoop; |
| + // Indicates whether listener's onSucceeded or onFailed callback is invoked. |
| + private boolean mResponseDataCompleted; |
| + private ByteBuffer mBuffer; |
| + |
| + public ByteBufferInputStream(MessageLoop messageLoop) { |
| + mMessageLoop = messageLoop; |
| + } |
| + |
| + @Override |
| + public int read() { |
| + if (mBuffer == null |
| + || (!mBuffer.hasRemaining() && !mResponseDataCompleted)) { |
| + mMessageLoop.loop(); |
|
mmenke
2014/11/20 18:52:36
Rather than using the message loop directly, I thi
xunjieli
2014/11/20 20:31:59
Done.
|
| + } |
| + if (mBuffer.hasRemaining()) { |
| + return mBuffer.get() & 0xFF; |
| + } |
| + return -1; |
|
mmenke
2014/11/20 18:52:36
If there was a failure rather than a successful co
xunjieli
2014/11/20 20:31:59
Acknowledged. Right, I think I will handle failure
|
| + } |
| + |
| + public void setResponseDataCompleted() { |
| + mResponseDataCompleted = true; |
| + } |
| + |
| + public void setByteBuffer(ByteBuffer buffer) { |
| + mBuffer = buffer; |
| + } |
| +} |