OLD | NEW |
---|---|
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 Loading... | |
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 return mConnected ? mBuffer.limit() : mBuffer.position(); |
mef
2015/09/25 21:32:19
Um, can you elaborate on this? Seems a bit magical
pauljensen
2015/09/28 14:18:12
Done.
| |
150 } | 150 } |
151 return mInitialContentLength; | 151 return mInitialContentLength; |
152 } | 152 } |
153 | 153 |
154 @Override | 154 @Override |
155 public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) { | 155 public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) { |
156 final int availableSpace = byteBuffer.remaining(); | 156 final int availableSpace = byteBuffer.remaining(); |
157 if (availableSpace < mBuffer.remaining()) { | 157 if (availableSpace < mBuffer.remaining()) { |
158 byteBuffer.put(mBuffer.array(), mBuffer.position(), availableSpa ce); | 158 byteBuffer.put(mBuffer.array(), mBuffer.position(), availableSpa ce); |
159 mBuffer.position(mBuffer.position() + availableSpace); | 159 mBuffer.position(mBuffer.position() + availableSpace); |
160 } else { | 160 } else { |
161 byteBuffer.put(mBuffer); | 161 byteBuffer.put(mBuffer); |
162 } | 162 } |
163 uploadDataSink.onReadSucceeded(false); | 163 uploadDataSink.onReadSucceeded(false); |
164 } | 164 } |
165 | 165 |
166 @Override | 166 @Override |
167 public void rewind(UploadDataSink uploadDataSink) { | 167 public void rewind(UploadDataSink uploadDataSink) { |
168 mBuffer.position(0); | 168 mBuffer.position(0); |
169 uploadDataSink.onRewindSucceeded(); | 169 uploadDataSink.onRewindSucceeded(); |
170 } | 170 } |
171 } | 171 } |
172 } | 172 } |
OLD | NEW |