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..4be6b996d5c5504de48327245468964645b4d878 |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java |
| @@ -0,0 +1,39 @@ |
| +// 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 { |
|
xunjieli
2014/11/13 19:02:38
Right now I just wrap around the bytebuffer return
|
| + |
| + private final ByteBuffer mBuf; |
| + |
| + public ByteBufferInputStream(ByteBuffer buf) { |
|
mef
2014/11/13 19:16:17
I don't think you can hold on to mBuf as it is onl
|
| + mBuf = buf; |
| + } |
| + |
| + @Override |
| + public int read() { |
| + if (!mBuf.hasRemaining()) { |
| + return -1; |
| + } |
| + return mBuf.get() & 0xFF; |
| + } |
| + |
| + @Override |
| + public int read(byte[] bytes, int off, int len) { |
| + if (!mBuf.hasRemaining()) { |
| + return -1; |
| + } |
| + |
| + len = Math.min(len, mBuf.remaining()); |
| + mBuf.get(bytes, off, len); |
| + return len; |
| + } |
| +} |