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 ofAbstractInputStreamContentthat 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 Modifier and Type Field Description private java.io.Filefile
-
Constructor Summary
Constructors Constructor Description FileContent(java.lang.String type, java.io.File file)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FilegetFile()Returns the file.java.io.InputStreamgetInputStream()Return an input stream for the specific implementation type ofAbstractInputStreamContent.longgetLength()Returns the content length or less than zero if not known.booleanretrySupported()Returns whether or not retry is supported on this content type.FileContentsetCloseInputStream(boolean closeInputStream)Sets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream).FileContentsetType(java.lang.String type)Sets the content type ornullfor none.-
Methods inherited from class com.google.api.client.http.AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
-
-
-
Method Detail
-
getLength
public long getLength()
Description copied from interface:HttpContentReturns the content length or less than zero if not known.
-
retrySupported
public boolean retrySupported()
Description copied from interface:HttpContentReturns whether or not retry is supported on this content type.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.FileNotFoundExceptionDescription copied from class:AbstractInputStreamContentReturn an input stream for the specific implementation type ofAbstractInputStreamContent. If the specific implementation will returntrueforHttpContent.retrySupported()this should be a factory function which will create a newInputStreamfrom the source data whenever invoked.- Specified by:
getInputStreamin classAbstractInputStreamContent- Throws:
java.io.FileNotFoundException
-
getFile
public java.io.File getFile()
Returns the file.- Since:
- 1.5
-
setType
public FileContent setType(java.lang.String type)
Description copied from class:AbstractInputStreamContentSets the content type ornullfor none. Subclasses should override by calling super.- Overrides:
setTypein classAbstractInputStreamContent
-
setCloseInputStream
public FileContent setCloseInputStream(boolean closeInputStream)
Description copied from class:AbstractInputStreamContentSets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(java.io.OutputStream). Default istrue. Subclasses should override by calling super.- Overrides:
setCloseInputStreamin classAbstractInputStreamContent
-
-