| 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.base.VisibleForTesting; | 7 import org.chromium.base.VisibleForTesting; |
| 8 import org.chromium.net.UploadDataProvider; | 8 import org.chromium.net.UploadDataProvider; |
| 9 import org.chromium.net.UploadDataSink; | 9 import org.chromium.net.UploadDataSink; |
| 10 | 10 |
| 11 import java.io.IOException; | 11 import java.io.IOException; |
| 12 import java.net.HttpRetryException; | 12 import java.net.HttpRetryException; |
| 13 import java.net.ProtocolException; | 13 import java.net.ProtocolException; |
| 14 import java.nio.ByteBuffer; | 14 import java.nio.ByteBuffer; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * An implementation of {@link java.io.OutputStream} to send data to a server, | 17 * An implementation of {@link java.io.OutputStream} to send data to a server, |
| 18 * when {@link CronetHttpURLConnection#setFixedLengthStreamingMode} is used. | 18 * when {@link CronetHttpURLConnection#setFixedLengthStreamingMode} is used. |
| 19 * This implementation does not buffer the entire request body in memory. | 19 * This implementation does not buffer the entire request body in memory. |
| 20 * It does not support rewind. Note that {@link #write} should only be called | 20 * It does not support rewind. Note that {@link #write} should only be called |
| 21 * from the thread on which the {@link #mConnection} is created. | 21 * from the thread on which the {@link #mConnection} is created. |
| 22 */ | 22 */ |
| 23 final class CronetFixedModeOutputStream extends CronetOutputStream { | 23 final class CronetFixedModeOutputStream extends CronetOutputStream { |
| 24 // CronetFixedModeOutputStream buffers up to this value and wait for UploadD
ataStream | 24 // CronetFixedModeOutputStream buffers up to this value and wait for UploadD
ataStream |
| 25 // to consume the data. This field is non-final, so it can be changed for te
sts. | 25 // to consume the data. This field is non-final, so it can be changed for te
sts. |
| 26 // Using 2048 bytes is because the internal read buffer is 14520 for QUIC, | 26 // Using 16384 bytes is because the internal read buffer is 14520 for QUIC, |
| 27 // 2852 for SPDY, and 16384 for normal stream. If a large value is used | 27 // 16384 for SPDY, and 16384 for normal HTTP/1.1 stream. |
| 28 // here, the buffer might not fit the internal buffer and compacting the buf
fer | |
| 29 // will be costly, see #read method below. | |
| 30 @VisibleForTesting | 28 @VisibleForTesting |
| 31 private static int sDefaultBufferLength = 2048; | 29 private static int sDefaultBufferLength = 16384; |
| 32 private final CronetHttpURLConnection mConnection; | 30 private final CronetHttpURLConnection mConnection; |
| 33 private final MessageLoop mMessageLoop; | 31 private final MessageLoop mMessageLoop; |
| 34 private final long mContentLength; | 32 private final long mContentLength; |
| 35 private final ByteBuffer mBuffer; | 33 private final ByteBuffer mBuffer; |
| 36 private final UploadDataProvider mUploadDataProvider = new UploadDataProvide
rImpl(); | 34 private final UploadDataProvider mUploadDataProvider = new UploadDataProvide
rImpl(); |
| 37 private long mBytesWritten; | 35 private long mBytesWritten; |
| 38 | 36 |
| 39 /** | 37 /** |
| 40 * Package protected constructor. | 38 * Package protected constructor. |
| 41 * @param connection The CronetHttpURLConnection object. | 39 * @param connection The CronetHttpURLConnection object. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 170 } |
| 173 | 171 |
| 174 /** | 172 /** |
| 175 * Sets the default buffer length for use in tests. | 173 * Sets the default buffer length for use in tests. |
| 176 */ | 174 */ |
| 177 @VisibleForTesting | 175 @VisibleForTesting |
| 178 static void setDefaultBufferLengthForTesting(int length) { | 176 static void setDefaultBufferLengthForTesting(int length) { |
| 179 sDefaultBufferLength = length; | 177 sDefaultBufferLength = length; |
| 180 } | 178 } |
| 181 } | 179 } |
| OLD | NEW |