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

## Class PathBody

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

All Implemented Interfaces:
  ContentBody, ContentDescriptor

    public class PathBody
    extends AbstractContentBody

Binary body part backed by an NIO `Path`.

Since:
  5.6
See Also:
  `MultipartEntityBuilder`

### Constructor Summary

Constructors
Constructor and Description
`PathBody(Path path)` Constructs a new instance for a given Path.
`PathBody(Path path, ContentType contentType)` Constructs a new instance for a given Path.
`PathBody(Path path, ContentType contentType, String fileName)` Constructs a new instance for a given Path.

### Method Summary

All Methods Instance Methods Concrete Methods
`long` `getContentLength()` Returns the body descriptors content-length.
`String` `getFilename()`
`InputStream` `getInputStream()` Gets a new input stream.
`Path` `getPath()` Gets the source Path.
`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

#### PathBody

    public PathBody(Path path)

Constructs a new instance for a given Path.

Parameters:
  `path` - the source Path.

#### PathBody

    public PathBody(Path path,
                    ContentType contentType)

Constructs a new instance for a given Path.

Parameters:
  `path` - the source Path.
  `contentType` - the content type.

#### PathBody

    public PathBody(Path path,
                    ContentType contentType,
                    String fileName)

Constructs a new instance for a given Path.

Parameters:
  `path` - the source Path.
  `contentType` - the content type.
  `fileName` - The file name to override the Path's file name.

### Method Detail

#### 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()

#### getInputStream

    public InputStream getInputStream()
                               throws IOException

Gets a new input stream.

Returns:
  a new input stream.
Throws:
  `IOException` - if an I/O error occurs

#### getPath

    public Path getPath()

Gets the source Path.

Returns:
  the source Path.

#### writeTo

    public void writeTo(OutputStream out)
                 throws IOException

Throws:
  `IOException`