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.longReturns the content length or less than zero if not known.booleanReturns 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(OutputStream).Sets the content type ornullfor none.Methods inherited from class AbstractInputStreamContent
getCloseInputStream, getType, writeTo
-
Field Details
-
file
-
-
Constructor Details
-
FileContent
-
-
Method Details
-
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
Description 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:
FileNotFoundException
-
getFile
-
setType
Description copied from class:AbstractInputStreamContentSets the content type ornullfor none. Subclasses should override by calling super.- Overrides:
setTypein classAbstractInputStreamContent
-
setCloseInputStream
Description copied from class:AbstractInputStreamContentSets whether the input stream should be closed at the end ofAbstractInputStreamContent.writeTo(OutputStream). Default istrue. Subclasses should override by calling super.- Overrides:
setCloseInputStreamin classAbstractInputStreamContent
-