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:
  • Field Details

    • fileName

      private final String fileName
    • path

      private final Path path
  • Constructor Details

    • PathBody

      public PathBody(Path path)
      Constructs a new instance for a given Path.
      Parameters:
      path - the source Path.
    • PathBody

      public PathBody(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(Path path, org.apache.hc.core5.http.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 Details

    • getFileName

      private static String getFileName(Path path)
    • 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