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

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: Fixed comments in the code 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 {
14
mmenke 2014/11/18 15:53:52 nit: Remove blank line, to be consistent with oth
xunjieli 2014/11/18 18:13:35 Done.
15 private final ByteBuffer mBuf;
mmenke 2014/11/18 15:53:51 optional nit: Suggest just writing out buffer for
xunjieli 2014/11/18 18:13:35 Done.
16
17 public ByteBufferInputStream(ByteBuffer buf) {
18 // Makes a read-only copy of the buffer passed in.
mmenke 2014/11/18 15:53:51 This is not actually a copy, but a read only refer
xunjieli 2014/11/18 18:13:35 The java docs says it is a new instance http://dev
mmenke 2014/11/18 18:40:59 It's a new Java object, but it shares the buffer.
19 mBuf = buf.asReadOnlyBuffer();
20 }
21
22 @Override
23 public int read() {
24 if (!mBuf.hasRemaining()) {
25 return -1;
26 }
27 return mBuf.get() & 0xFF;
28 }
29
30 @Override
31 public int read(byte[] bytes, int off, int len) {
32 if (!mBuf.hasRemaining()) {
33 return -1;
34 }
35
36 len = Math.min(len, mBuf.remaining());
37 mBuf.get(bytes, off, len);
38 return len;
39 }
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698