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 { | |
|
xunjieli
2014/11/13 19:02:38
Right now I just wrap around the bytebuffer return
| |
| 14 | |
| 15 private final ByteBuffer mBuf; | |
| 16 | |
| 17 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
| |
| 18 mBuf = buf; | |
| 19 } | |
| 20 | |
| 21 @Override | |
| 22 public int read() { | |
| 23 if (!mBuf.hasRemaining()) { | |
| 24 return -1; | |
| 25 } | |
| 26 return mBuf.get() & 0xFF; | |
| 27 } | |
| 28 | |
| 29 @Override | |
| 30 public int read(byte[] bytes, int off, int len) { | |
| 31 if (!mBuf.hasRemaining()) { | |
| 32 return -1; | |
| 33 } | |
| 34 | |
| 35 len = Math.min(len, mBuf.remaining()); | |
| 36 mBuf.get(bytes, off, len); | |
| 37 return len; | |
| 38 } | |
| 39 } | |
| OLD | NEW |