| 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..feee74dec832a850e1a04480a87c35d2bc7c7a06
|
| --- /dev/null
|
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java
|
| @@ -0,0 +1,40 @@
|
| +// 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 {
|
| +
|
| + private final ByteBuffer mBuf;
|
| +
|
| + public ByteBufferInputStream(ByteBuffer buf) {
|
| + // Makes a read-only copy of the buffer passed in.
|
| + mBuf = buf.asReadOnlyBuffer();
|
| + }
|
| +
|
| + @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;
|
| + }
|
| +}
|
|
|