public final class FileContent extends AbstractInputStreamContent
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.
Constructors
FileContent(String type, File file)
public FileContent(String type, File file)
Name | Description |
type | String Content type or |
file | File file |
Methods
getFile()
public File getFile()
Returns the file.
Type | Description |
File |
getInputStream()
public InputStream getInputStream()
Return an input stream for the specific implementation type of AbstractInputStreamContent. If the specific implementation will return true
for #retrySupported() this should be a factory function which will create a new InputStream from the source data whenever invoked.
Type | Description |
InputStream |
Type | Description |
FileNotFoundException |
getLength()
public long getLength()
Type | Description |
long |
retrySupported()
public boolean retrySupported()
Type | Description |
boolean |
setCloseInputStream(boolean closeInputStream)
public FileContent setCloseInputStream(boolean closeInputStream)
Sets whether the input stream should be closed at the end of #writeTo. Default is
true
. Subclasses should override by calling super.
Name | Description |
closeInputStream | boolean |
Type | Description |
FileContent |
setType(String type)
public FileContent setType(String type)
Sets the content type or null
for none. Subclasses should override by calling super.
Name | Description |
type | String |
Type | Description |
FileContent |