Package com.google.api.client.http
Class FileContent
java.lang.Object
com.google.api.client.http.AbstractInputStreamContent
com.google.api.client.http.FileContent
- All Implemented Interfaces:
HttpContent
,StreamingContent
Concrete implementation of
AbstractInputStreamContent
that generates repeatable input
streams based on the contents of a file.
Sample use:
private static void setRequestJpegContent(HttpRequest request, File jpegFile) {
request.setContent(new FileContent("image/jpeg", jpegFile));
}
Implementation is not thread-safe.
- Since:
- 1.4
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetFile()
Returns the file.Return an input stream for the specific implementation type ofAbstractInputStreamContent
.long
Returns the content length or less than zero if not known.boolean
Returns whether or not retry is supported on this content type.setCloseInputStream
(boolean closeInputStream) Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream)
.Sets the content type ornull
for none.Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
Field Details
-
file
-
-
Constructor Details
-
FileContent
- Parameters:
type
- Content type ornull
for nonefile
- file- Since:
- 1.5
-
-
Method Details
-
getLength
public long getLength()Description copied from interface:HttpContent
Returns the content length or less than zero if not known. -
retrySupported
public boolean retrySupported()Description copied from interface:HttpContent
Returns whether or not retry is supported on this content type. -
getInputStream
Description copied from class:AbstractInputStreamContent
Return an input stream for the specific implementation type ofAbstractInputStreamContent
. If the specific implementation will returntrue
forHttpContent.retrySupported()
this should be a factory function which will create a newInputStream
from the source data whenever invoked.- Specified by:
getInputStream
in classAbstractInputStreamContent
- Throws:
FileNotFoundException
-
getFile
Returns the file.- Since:
- 1.5
-
setType
Description copied from class:AbstractInputStreamContent
Sets the content type ornull
for none. Subclasses should override by calling super.- Overrides:
setType
in classAbstractInputStreamContent
-
setCloseInputStream
Description copied from class:AbstractInputStreamContent
Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream)
. Default istrue
. Subclasses should override by calling super.- Overrides:
setCloseInputStream
in classAbstractInputStreamContent
-