| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.net; |
| 6 |
| 7 import java.io.IOException; |
| 8 import java.nio.ByteBuffer; |
| 9 |
| 10 /** |
| 11 * Interface allowing the embedder to provide an upload body to |
| 12 * {@link UrlRequest}. It supports both non-chunked (size known in advanced) and |
| 13 * chunked (size not known in advance) uploads. Be aware that not all servers |
| 14 * support chunked uploads. |
| 15 * |
| 16 * <p>An upload is either always chunked, across multiple uploads if the data |
| 17 * ends up being sent more than once, or never chunked. |
| 18 */ |
| 19 public interface UploadDataProvider { |
| 20 /** |
| 21 * @return if this is a non-chunked upload, returns the length of the |
| 22 * upload. Must always return -1 if this is a chunked upload. |
| 23 */ |
| 24 public long getLength(); |
| 25 |
| 26 /** |
| 27 * Reads upload data into {@code byteBuffer}. Upon completion, the buffer's |
| 28 * position is updated to the end of the bytes that were read. The buffer's |
| 29 * limit is not changed. Each call of this method must be followed be a |
| 30 * single call, either synchronous or asynchronous, to |
| 31 * {@code uploadDataSink}: {@link UploadDataSink#onReadSucceeded} on success |
| 32 * or {@link UploadDataSink#onReadError} on failure. Neither read nor rewind |
| 33 * will be called until one of those methods or the other is called. Even if |
| 34 * the associated {@link UrlRequest} is cancelled, one or the other must |
| 35 * still be called before resources can be safely freed. Throwing an |
| 36 * exception will also result in resources being freed and the request being |
| 37 * errored out. |
| 38 * |
| 39 * @param uploadDataSink The object to notify when the read has completed, |
| 40 * successfully or otherwise. |
| 41 * @param byteBuffer The buffer to copy the read bytes into. |
| 42 * @throws IOException if any IOException occurred during the process. |
| 43 */ |
| 44 public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) |
| 45 throws IOException; |
| 46 |
| 47 /** |
| 48 * Rewinds upload data. Each call must be followed be a single |
| 49 * call, either synchronous or asynchronous, to {@code uploadDataSink}: |
| 50 * {@link UploadDataSink#onRewindSucceeded} on success or |
| 51 * {@link UploadDataSink#onRewindError} on failure. Neither read nor rewind |
| 52 * will be called until one of those methods or the other is called. |
| 53 * Even if the associated {@link UrlRequest} is cancelled, one or the other |
| 54 * must still be called before resources can be safely freed. Throwing an |
| 55 * exception will also result in resources being freed and the request being |
| 56 * errored out. |
| 57 * |
| 58 * <p>If rewinding is not supported, this should call |
| 59 * {@link UploadDataSink#onRewindError}. Note that rewinding is required to |
| 60 * follow redirects that preserve the upload body, and for retrying when the |
| 61 * server times out stale sockets. |
| 62 * |
| 63 * @param uploadDataSink The object to notify when the rewind operation has |
| 64 * completed, successfully or otherwise. |
| 65 * @throws IOException if any IOException occurred during the process. |
| 66 */ |
| 67 public void rewind(UploadDataSink uploadDataSink) |
| 68 throws IOException; |
| 69 } |
| OLD | NEW |