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

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

Issue 2131323002: [Cronet] Check whether request is done before spinning up message loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 5 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 mConnection = connection; 66 mConnection = connection;
67 mInitialContentLength = -1; 67 mInitialContentLength = -1;
68 // Buffering without knowing content-length. 68 // Buffering without knowing content-length.
69 mBuffer = ByteBuffer.allocate(INITIAL_BUFFER_SIZE); 69 mBuffer = ByteBuffer.allocate(INITIAL_BUFFER_SIZE);
70 } 70 }
71 71
72 @Override 72 @Override
73 public void write(int oneByte) throws IOException { 73 public void write(int oneByte) throws IOException {
74 super.write(oneByte);
mef 2016/07/08 17:39:10 Maybe just explicitly call checkNotClosed() here a
xunjieli 2016/07/08 17:56:26 Done.
74 ensureCanWrite(1); 75 ensureCanWrite(1);
75 mBuffer.put((byte) oneByte); 76 mBuffer.put((byte) oneByte);
76 } 77 }
77 78
78 @Override 79 @Override
79 public void write(byte[] buffer, int offset, int count) throws IOException { 80 public void write(byte[] buffer, int offset, int count) throws IOException {
81 super.write(buffer, offset, count);
80 ensureCanWrite(count); 82 ensureCanWrite(count);
81 mBuffer.put(buffer, offset, count); 83 mBuffer.put(buffer, offset, count);
82 } 84 }
83 85
84 // TODO(xunjieli): implement close().
85
86 /** 86 /**
87 * Ensures that {@code count} bytes can be written to the internal buffer. 87 * Ensures that {@code count} bytes can be written to the internal buffer.
88 */ 88 */
89 private void ensureCanWrite(int count) throws IOException { 89 private void ensureCanWrite(int count) throws IOException {
90 if (mInitialContentLength != -1 90 if (mInitialContentLength != -1
91 && mBuffer.position() + count > mInitialContentLength) { 91 && mBuffer.position() + count > mInitialContentLength) {
92 // Error message is to match that of the default implementation. 92 // Error message is to match that of the default implementation.
93 throw new ProtocolException("exceeded content-length limit of " 93 throw new ProtocolException("exceeded content-length limit of "
94 + mInitialContentLength + " bytes"); 94 + mInitialContentLength + " bytes");
95 } 95 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 uploadDataSink.onReadSucceeded(false); 164 uploadDataSink.onReadSucceeded(false);
165 } 165 }
166 166
167 @Override 167 @Override
168 public void rewind(UploadDataSink uploadDataSink) { 168 public void rewind(UploadDataSink uploadDataSink) {
169 mBuffer.position(0); 169 mBuffer.position(0);
170 uploadDataSink.onRewindSucceeded(); 170 uploadDataSink.onRewindSucceeded();
171 } 171 }
172 } 172 }
173 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698