Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/urlconnection/ByteBufferInputStream.java

Issue 725683002: [Cronet] Initial implementation of HttpURLConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698