Class FileContent (1.41.8)

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.

Inheritance

java.lang.Object > AbstractInputStreamContent > FileContent

Constructors

FileContent(String type, File file)

public FileContent(String type, File file)
Parameters
NameDescription
typeString

Content type or null for none

fileFile

file

Methods

getFile()

public File getFile()

Returns the file.

Returns
TypeDescription
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.

Returns
TypeDescription
InputStream
Overrides Exceptions
TypeDescription
FileNotFoundException

getLength()

public long getLength()
Returns
TypeDescription
long

retrySupported()

public boolean retrySupported()
Returns
TypeDescription
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.

Parameter
NameDescription
closeInputStreamboolean
Returns
TypeDescription
FileContent
Overrides

setType(String type)

public FileContent setType(String type)

Sets the content type or null for none. Subclasses should override by calling super.

Parameter
NameDescription
typeString
Returns
TypeDescription
FileContent
Overrides