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