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.InputStream; | |
| 8 import java.nio.ByteBuffer; | |
| 9 | |
| 10 /** | |
| 11 * Wrapper class to construct an InputSteam based on a ByteBuffer. | |
| 12 */ | |
| 13 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.
| |
| 14 private final MessageLoop mMessageLoop; | |
| 15 // Indicates whether listener's onSucceeded or onFailed callback is invoked. | |
| 16 private boolean mResponseDataCompleted; | |
| 17 private ByteBuffer mBuffer; | |
| 18 | |
| 19 public ByteBufferInputStream(MessageLoop messageLoop) { | |
| 20 mMessageLoop = messageLoop; | |
| 21 } | |
| 22 | |
| 23 @Override | |
| 24 public int read() { | |
| 25 if (mBuffer == null | |
| 26 || (!mBuffer.hasRemaining() && !mResponseDataCompleted)) { | |
| 27 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.
| |
| 28 } | |
| 29 if (mBuffer.hasRemaining()) { | |
| 30 return mBuffer.get() & 0xFF; | |
| 31 } | |
| 32 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
| |
| 33 } | |
| 34 | |
| 35 public void setResponseDataCompleted() { | |
| 36 mResponseDataCompleted = true; | |
| 37 } | |
| 38 | |
| 39 public void setByteBuffer(ByteBuffer buffer) { | |
| 40 mBuffer = buffer; | |
| 41 } | |
| 42 } | |
| OLD | NEW |