Class FileContent (1.43.2)

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
Name Description
type String

Content type or null for none

file File

file

Methods

getFile()

public File getFile()

Returns the file.

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

Returns
Type Description
InputStream
Overrides
Exceptions
Type Description
FileNotFoundException

getLength()

public long getLength()
Returns
Type Description
long

retrySupported()

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

Parameter
Name Description
closeInputStream boolean
Returns
Type Description
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
Name Description
type String
Returns
Type Description
FileContent
Overrides