UploadDataProvider
Stay organized with collections
Save and categorize content based on your preferences.
Abstract class allowing the embedder to provide an upload body to UrlRequest
. It supports
both non-chunked (size known in advanced) and chunked (size not known in advance) uploads. Be
aware that not all servers support chunked uploads.
An upload is either always chunked, across multiple uploads if the data
ends up being sent more than once, or never chunked.
Public Constructor Summary
Public Method Summary
void
|
close()
Called when this UploadDataProvider is no longer needed by a request, so that resources (like
a file) can be explicitly released.
|
abstract
long
|
getLength()
If this is a non-chunked upload, returns the length of the upload.
|
abstract
void
|
read( UploadDataSink uploadDataSink, ByteBuffer byteBuffer)
Reads upload data into byteBuffer .
|
abstract
void
|
|
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
From interface
java.io.Closeable
From interface
java.lang.AutoCloseable
Public Constructors
public
UploadDataProvider
()
Public Methods
public
void
close
()
Called when this UploadDataProvider is no longer needed by a request, so that resources (like
a file) can be explicitly released.
Throws
IOException |
if any IOException occurred during the process. This will cause the
request
to fail if it is not yet complete; otherwise it will be logged.
|
public
abstract
long
getLength
()
If this is a non-chunked upload, returns the length of the upload. Must always return -1 if
this is a chunked upload.
Returns
- the length of the upload for non-chunked uploads, -1 otherwise.
Throws
IOException |
if any IOException occurred during the process.
|
public
abstract
void
read
(UploadDataSink uploadDataSink, ByteBuffer byteBuffer)
Reads upload data into byteBuffer
. Upon completion, the buffer's position is updated
to the end of the bytes that were read. The buffer's limit is not changed. Each call of this
method must be followed be a single call, either synchronous or asynchronous, to uploadDataSink
: UploadDataSink.onReadSucceeded(boolean)
on success or UploadDataSink.onReadError(Exception)
on failure. Neither read nor rewind will be called until one of
those methods or the other is called. Even if the associated UrlRequest
is canceled,
one or the other must still be called before resources can be safely freed. Throwing an
exception will also result in resources being freed and the request being errored out.
Parameters
uploadDataSink |
The object to notify when the read has completed, successfully or
otherwise. |
byteBuffer |
The buffer to copy the read bytes into. Do not change byteBuffer's limit. |
public
abstract
void
rewind
(UploadDataSink uploadDataSink)
Rewinds upload data. Each call must be followed be a single call, either synchronous or
asynchronous, to uploadDataSink
: UploadDataSink.onRewindSucceeded()
on success
or
UploadDataSink.onRewindError(Exception)
on failure. Neither read nor rewind will be called until
one of those methods or the other is called. Even if the associated UrlRequest
is
canceled, one or the other must still be called before resources can be safely freed.
Throwing an exception will also result in resources being freed and the request being errored
out.
If rewinding is not supported, this should call
UploadDataSink.onRewindError(Exception)
. Note that rewinding is required to follow redirects
that preserve the upload body, and for retrying when the server times out stale sockets.
Parameters
uploadDataSink |
The object to notify when the rewind operation has completed,
successfully or otherwise. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-10-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-26 UTC."],[],[],null,["# UploadDataProvider\n\npublic abstract class **UploadDataProvider** extends Object \nimplements Closeable \nAbstract class allowing the embedder to provide an upload body to [UrlRequest](../../../../reference/org/chromium/net/UrlRequest.html). It supports\nboth non-chunked (size known in advanced) and chunked (size not known in advance) uploads. Be\naware that not all servers support chunked uploads.\n\nAn upload is either always chunked, across multiple uploads if the data\nends up being sent more than once, or never chunked. \n\n### Public Constructor Summary\n\n|---|-------------------------------------------------------------------------------------------------------------|\n| | [UploadDataProvider](../../../../reference/org/chromium/net/UploadDataProvider.html#UploadDataProvider())() |\n\n### Public Method Summary\n\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [close](../../../../reference/org/chromium/net/UploadDataProvider.html#close())() Called when this UploadDataProvider is no longer needed by a request, so that resources (like a file) can be explicitly released. |\n| abstract long | [getLength](../../../../reference/org/chromium/net/UploadDataProvider.html#getLength())() If this is a non-chunked upload, returns the length of the upload. |\n| abstract void | [read](../../../../reference/org/chromium/net/UploadDataProvider.html#read(org.chromium.net.UploadDataSink,%20java.nio.ByteBuffer))([UploadDataSink](../../../../reference/org/chromium/net/UploadDataSink.html) uploadDataSink, ByteBuffer byteBuffer) Reads upload data into `byteBuffer`. |\n| abstract void | [rewind](../../../../reference/org/chromium/net/UploadDataProvider.html#rewind(org.chromium.net.UploadDataSink))([UploadDataSink](../../../../reference/org/chromium/net/UploadDataSink.html) uploadDataSink) Rewinds upload data. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| Object | clone() |\n| boolean | equals(Object arg0) |\n| void | finalize() |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.io.Closeable \n\n|---------------|---------|\n| abstract void | close() |\n\nFrom interface java.lang.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Constructors\n-------------------\n\n#### public\n**UploadDataProvider**\n()\n\n\u003cbr /\u003e\n\nPublic Methods\n--------------\n\n#### public void\n**close**\n()\n\nCalled when this UploadDataProvider is no longer needed by a request, so that resources (like\na file) can be explicitly released. \n\n##### Throws\n\n| IOException | if any IOException occurred during the process. This will cause the request to fail if it is not yet complete; otherwise it will be logged. |\n|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|\n\n#### public abstract long\n**getLength**\n()\n\nIf this is a non-chunked upload, returns the length of the upload. Must always return -1 if\nthis is a chunked upload. \n\n##### Returns\n\n- the length of the upload for non-chunked uploads, -1 otherwise. \n\n##### Throws\n\n| IOException | if any IOException occurred during the process. |\n|-------------|-------------------------------------------------|\n\n#### public abstract void\n**read**\n([UploadDataSink](../../../../reference/org/chromium/net/UploadDataSink.html) uploadDataSink, ByteBuffer byteBuffer)\n\nReads upload data into `byteBuffer`. Upon completion, the buffer's position is updated\nto the end of the bytes that were read. The buffer's limit is not changed. Each call of this\nmethod must be followed be a single call, either synchronous or asynchronous, to `uploadDataSink`: [UploadDataSink.onReadSucceeded(boolean)](../../../../reference/org/chromium/net/UploadDataSink.html#onReadSucceeded(boolean)) on success or [UploadDataSink.onReadError(Exception)](../../../../reference/org/chromium/net/UploadDataSink.html#onReadError(java.lang.Exception)) on failure. Neither read nor rewind will be called until one of\nthose methods or the other is called. Even if the associated [UrlRequest](../../../../reference/org/chromium/net/UrlRequest.html) is canceled,\none or the other must still be called before resources can be safely freed. Throwing an\nexception will also result in resources being freed and the request being errored out. \n\n##### Parameters\n\n| uploadDataSink | The object to notify when the read has completed, successfully or otherwise. |\n| byteBuffer | The buffer to copy the read bytes into. Do not change byteBuffer's limit. |\n|----------------|------------------------------------------------------------------------------|\n\n##### Throws\n\n| IOException | if any IOException occurred during the process. [UrlRequest.Callback.onFailed(UrlRequest, UrlResponseInfo, CronetException)](../../../../reference/org/chromium/net/UrlRequest.Callback.html#onFailed(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo,%20org.chromium.net.CronetException)) will be called with the thrown exception set as the cause of the [CallbackException](../../../../reference/org/chromium/net/CallbackException.html). |\n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n#### public abstract void\n**rewind**\n([UploadDataSink](../../../../reference/org/chromium/net/UploadDataSink.html) uploadDataSink)\n\nRewinds upload data. Each call must be followed be a single call, either synchronous or\nasynchronous, to `uploadDataSink`: [UploadDataSink.onRewindSucceeded()](../../../../reference/org/chromium/net/UploadDataSink.html#onRewindSucceeded()) on success\nor\n[UploadDataSink.onRewindError(Exception)](../../../../reference/org/chromium/net/UploadDataSink.html#onRewindError(java.lang.Exception)) on failure. Neither read nor rewind will be called until\none of those methods or the other is called. Even if the associated [UrlRequest](../../../../reference/org/chromium/net/UrlRequest.html) is\ncanceled, one or the other must still be called before resources can be safely freed.\nThrowing an exception will also result in resources being freed and the request being errored\nout.\n\nIf rewinding is not supported, this should call\n[UploadDataSink.onRewindError(Exception)](../../../../reference/org/chromium/net/UploadDataSink.html#onRewindError(java.lang.Exception)). Note that rewinding is required to follow redirects\nthat preserve the upload body, and for retrying when the server times out stale sockets. \n\n##### Parameters\n\n| uploadDataSink | The object to notify when the rewind operation has completed, successfully or otherwise. |\n|----------------|------------------------------------------------------------------------------------------|\n\n##### Throws\n\n| IOException | if any IOException occurred during the process. [UrlRequest.Callback.onFailed(UrlRequest, UrlResponseInfo, CronetException)](../../../../reference/org/chromium/net/UrlRequest.Callback.html#onFailed(org.chromium.net.UrlRequest,%20org.chromium.net.UrlResponseInfo,%20org.chromium.net.CronetException)) will be called with the thrown exception set as the cause of the [CallbackException](../../../../reference/org/chromium/net/CallbackException.html). |\n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]