Class PartValue

java.lang.Object
com.shri.restinpeace.multipart.PartValue

public final class PartValue extends Object
Wraps a File, byte[], or InputStream with an explicit file name, for use as a @PartMap entry's value when the default file name (the entry's key) isn't the one to send. A plain (unwrapped) String/File/byte[]/ InputStream value is still handled directly - wrapping is opt-in, only needed to override the file name.
 Map<String, Object> parts = new LinkedHashMap<>();
 parts.put("caption", "vacation photo");
 parts.put("file", PartValue.of(photoBytes, "photo.jpg"));
 
  • Method Details

    • of

      public static PartValue of(File file, String fileName)
      Wraps a File part value with an explicit file name.
      Parameters:
      file - the file to send
      fileName - the file name to send it under, overriding the file's own name
      Returns:
      a PartValue wrapping file with fileName
    • of

      public static PartValue of(byte[] bytes, String fileName)
      Wraps a byte[] part value with an explicit file name.
      Parameters:
      bytes - the file content to send
      fileName - the file name to send it under
      Returns:
      a PartValue wrapping bytes with fileName
    • of

      public static PartValue of(InputStream stream, String fileName)
      Wraps an InputStream part value with an explicit file name.
      Parameters:
      stream - the file content to send
      fileName - the file name to send it under
      Returns:
      a PartValue wrapping stream with fileName
    • getValue

      public Object getValue()
      Returns the wrapped part value.
      Returns:
      the wrapped value
    • getFileName

      public String getFileName()
      Returns the file name to send the wrapped value under.
      Returns:
      the file name to send the wrapped value under