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
public final class FileContent extends AbstractInputStreamContent
Concrete implementation ofAbstractInputStreamContent
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
- Author:
- moshenko@google.com (Jacob Moshenko)
-
-
Constructor Summary
Constructors Constructor Description FileContent(String type, File file)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
getFile()
Returns the file.InputStream
getInputStream()
Return an input stream for the specific implementation type ofAbstractInputStreamContent
.long
getLength()
Returns the content length or less than zero if not known.boolean
retrySupported()
Returns whether or not retry is supported on this content type.FileContent
setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream)
.FileContent
setType(String type)
Sets the content type ornull
for none.-
Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
-
-
-
Method Detail
-
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
public InputStream getInputStream() throws FileNotFoundException
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
public File getFile()
Returns the file.- Since:
- 1.5
-
setType
public FileContent setType(String type)
Description copied from class:AbstractInputStreamContent
Sets the content type ornull
for none. Subclasses should override by calling super.- Overrides:
setType
in classAbstractInputStreamContent
-
setCloseInputStream
public FileContent setCloseInputStream(boolean closeInputStream)
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
-
-