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

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

Issue 1363723002: [Cronet] Create Builders, rename UrlRequestContext to CronetEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Ben's tests Created 5 years, 2 months 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net.urlconnection; 5 package org.chromium.net.urlconnection;
6 6
7 import org.chromium.net.UploadDataProvider; 7 import org.chromium.net.UploadDataProvider;
8 import org.chromium.net.UploadDataSink; 8 import org.chromium.net.UploadDataSink;
9 9
10 import java.io.IOException; 10 import java.io.IOException;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 private class UploadDataProviderImpl extends UploadDataProvider { 140 private class UploadDataProviderImpl extends UploadDataProvider {
141 @Override 141 @Override
142 public long getLength() { 142 public long getLength() {
143 // This method is supposed to be called just before starting the req uest. 143 // This method is supposed to be called just before starting the req uest.
144 // If content length is not initially passed in, the number of bytes 144 // If content length is not initially passed in, the number of bytes
145 // written will be used as the content length. 145 // written will be used as the content length.
146 // TODO(xunjieli): Think of a less fragile way, since getLength() ca n be 146 // TODO(xunjieli): Think of a less fragile way, since getLength() ca n be
147 // potentially called in other places in the future. 147 // potentially called in other places in the future.
148 if (mInitialContentLength == -1) { 148 if (mInitialContentLength == -1) {
149 return mBuffer.position(); 149 // Account for the fact that setConnected() flip()s mBuffer.
150 return mConnected ? mBuffer.limit() : mBuffer.position();
150 } 151 }
151 return mInitialContentLength; 152 return mInitialContentLength;
152 } 153 }
153 154
154 @Override 155 @Override
155 public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) { 156 public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) {
156 final int availableSpace = byteBuffer.remaining(); 157 final int availableSpace = byteBuffer.remaining();
157 if (availableSpace < mBuffer.remaining()) { 158 if (availableSpace < mBuffer.remaining()) {
158 byteBuffer.put(mBuffer.array(), mBuffer.position(), availableSpa ce); 159 byteBuffer.put(mBuffer.array(), mBuffer.position(), availableSpa ce);
159 mBuffer.position(mBuffer.position() + availableSpace); 160 mBuffer.position(mBuffer.position() + availableSpace);
160 } else { 161 } else {
161 byteBuffer.put(mBuffer); 162 byteBuffer.put(mBuffer);
162 } 163 }
163 uploadDataSink.onReadSucceeded(false); 164 uploadDataSink.onReadSucceeded(false);
164 } 165 }
165 166
166 @Override 167 @Override
167 public void rewind(UploadDataSink uploadDataSink) { 168 public void rewind(UploadDataSink uploadDataSink) {
168 mBuffer.position(0); 169 mBuffer.position(0);
169 uploadDataSink.onRewindSucceeded(); 170 uploadDataSink.onRewindSucceeded();
170 } 171 }
171 } 172 }
172 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698