org.apache.hc.client5.http.entity.mime

## Class FileBody

- java.lang.Object
- - org.apache.hc.client5.http.entity.mime.AbstractContentBody
  - - org.apache.hc.client5.http.entity.mime.FileBody

All Implemented Interfaces:
  ContentBody, ContentDescriptor

    public class FileBody
    extends AbstractContentBody

Binary body part backed by a file.

Since:
  4.0
See Also:
  `MultipartEntityBuilder`

### Constructor Summary

Constructors
Constructor and Description
`FileBody(File file)`
`FileBody(File file, org.apache.hc.core5.http.ContentType contentType)`
`FileBody(File file, org.apache.hc.core5.http.ContentType contentType, String filename)`

### Method Summary

Methods
`long` `getContentLength()` Returns the body descriptors content-length.
`File` `getFile()`
`String` `getFilename()`
`InputStream` `getInputStream()`
`String` `getTransferEncoding()` Returns the body descriptors transfer encoding.
`void` `writeTo(OutputStream out)`

### Methods inherited from class org.apache.hc.client5.http.entity.mime.AbstractContentBody

`getCharset, getContentType, getMediaType, getMimeType, getSubType`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FileBody

    public FileBody(File file)

#### FileBody

    public FileBody(File file,
            org.apache.hc.core5.http.ContentType contentType,
            String filename)

Since:
  4.3

#### FileBody

    public FileBody(File file,
            org.apache.hc.core5.http.ContentType contentType)

Since:
  4.3

### Method Detail

#### getInputStream

    public InputStream getInputStream()
                               throws IOException

Throws:
  `IOException`

#### writeTo

    public void writeTo(OutputStream out)
                 throws IOException

Throws:
  `IOException`

#### getTransferEncoding

    public String getTransferEncoding()

Description copied from interface: `ContentDescriptor`
Returns the body descriptors transfer encoding.

Returns:
  The transfer encoding. Must not be null, but "7bit", if no transfer-encoding was specified.

#### getContentLength

    public long getContentLength()

Description copied from interface: `ContentDescriptor`
Returns the body descriptors content-length.

Returns:
  Content length, if known, or -1, to indicate the absence of a content-length header.

#### getFilename

    public String getFilename()

#### getFile

    public File getFile()