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 NIOPath.- Since:
- 5.6
- See Also:
MultipartEntityBuilder
-
-
Constructor Summary
Constructors Constructor Description PathBody(java.nio.file.Path path)Constructs a new instance for a given Path.PathBody(java.nio.file.Path path, org.apache.hc.core5.http.ContentType contentType)Constructs a new instance for a given Path.PathBody(java.nio.file.Path path, org.apache.hc.core5.http.ContentType contentType, java.lang.String fileName)Constructs a new instance for a given Path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetContentLength()Returns the body descriptors content-length.java.lang.StringgetFilename()private static java.lang.StringgetFileName(java.nio.file.Path path)java.io.InputStreamgetInputStream()Gets a new input stream.java.nio.file.PathgetPath()Gets the source Path.voidwriteTo(java.io.OutputStream out)-
Methods inherited from class org.apache.hc.client5.http.entity.mime.AbstractContentBody
getCharset, getContentType, getMediaType, getMimeType, getSubType
-
-
-
-
Constructor Detail
-
PathBody
public PathBody(java.nio.file.Path path)
Constructs a new instance for a given Path.- Parameters:
path- the source Path.
-
PathBody
public PathBody(java.nio.file.Path path, org.apache.hc.core5.http.ContentType contentType)Constructs a new instance for a given Path.- Parameters:
path- the source Path.contentType- the content type.
-
PathBody
public PathBody(java.nio.file.Path path, org.apache.hc.core5.http.ContentType contentType, java.lang.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
-
getFileName
private static java.lang.String getFileName(java.nio.file.Path path)
-
getContentLength
public long getContentLength()
Description copied from interface:ContentDescriptorReturns the body descriptors content-length.- Returns:
- Content length, if known, or -1, to indicate the absence of a content-length header.
-
getFilename
public java.lang.String getFilename()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionGets a new input stream.- Returns:
- a new input stream.
- Throws:
java.io.IOException- if an I/O error occurs
-
getPath
public java.nio.file.Path getPath()
Gets the source Path.- Returns:
- the source Path.
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
-