public final class FileContent extends AbstractInputStreamContent
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.
| Constructor and Description |
|---|
FileContent(java.lang.String type,
java.io.File file) |
| Modifier and Type | Method and Description |
|---|---|
java.io.File |
getFile()
Returns the file.
|
java.io.InputStream |
getInputStream()
Return an input stream for the specific implementation type of
AbstractInputStreamContent. |
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 of
AbstractInputStreamContent.writeTo(java.io.OutputStream). |
FileContent |
setType(java.lang.String type)
Sets the content type or
null for none. |
getCloseInputStream, getType, writeTopublic FileContent(java.lang.String type,
java.io.File file)
type - Content type or null for nonefile - filepublic long getLength()
HttpContentpublic boolean retrySupported()
HttpContentpublic java.io.InputStream getInputStream()
throws java.io.FileNotFoundException
AbstractInputStreamContentAbstractInputStreamContent. If the specific implementation will return true for
HttpContent.retrySupported() this should be a factory function which will create a new
InputStream from the source data whenever invoked.getInputStream in class AbstractInputStreamContentjava.io.FileNotFoundExceptionpublic java.io.File getFile()
public FileContent setType(java.lang.String type)
AbstractInputStreamContentnull for none. Subclasses should override by calling super.setType in class AbstractInputStreamContentpublic FileContent setCloseInputStream(boolean closeInputStream)
AbstractInputStreamContentAbstractInputStreamContent.writeTo(java.io.OutputStream). Default is
true. Subclasses should override by calling super.setCloseInputStream in class AbstractInputStreamContentCopyright © 2011-2018 Google. All Rights Reserved.