Package com.restfb

Class BinaryAttachment

java.lang.Object
com.restfb.BinaryAttachment
Direct Known Subclasses:
FacebookReelAttachment

public class BinaryAttachment extends Object
Represents a binary file that can be uploaded to Facebook.

Normally this would be a photo or video.

Since:
1.6.5
Author:
Mark Allen, Marcel Stoer
  • Field Details

    • data

      protected byte[] data
  • Constructor Details

    • BinaryAttachment

      protected BinaryAttachment()
    • BinaryAttachment

      protected BinaryAttachment(String filename, Supplier<InputStream> dataSupplier)
      Creates a new binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • BinaryAttachment

      protected BinaryAttachment(String fieldName, String filename, Supplier<InputStream> dataSupplier)
      Creates a new binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      fieldName - The field name the binary belongs to
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • BinaryAttachment

      protected BinaryAttachment(String filename, Supplier<InputStream> dataSupplier, String contentType)
      Creates a new binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      contentType - The attachment's contentType.
      Throws:
      IllegalArgumentException - If dataSupplier is null, filename is null or blank, or contentType is null or blank.
      Since:
      1.6.13
    • BinaryAttachment

      protected BinaryAttachment(String fieldName, String filename, Supplier<InputStream> dataSupplier, String contentType)
      Creates a new binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      contentType - The attachment's contentType.
      fieldName - The field name the binary belongs to
      Throws:
      IllegalArgumentException - If dataSupplier is null, filename is null or blank, or contentType is null or blank.
      Since:
      1.6.13
    • BinaryAttachment

      protected BinaryAttachment(String filename, byte[] data)
      Creates a new binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • BinaryAttachment

      protected BinaryAttachment(String fieldName, String filename, byte[] data)
      Creates a new binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      fieldName - The field name the binary belongs to
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • BinaryAttachment

      protected BinaryAttachment(String filename, byte[] data, String contentType)
      Creates a new binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      contentType - The attachment's contentType.
      Throws:
      IllegalArgumentException - If data is null, filename is null or blank, or contentType is null or blank.
      Since:
      1.6.17
    • BinaryAttachment

      protected BinaryAttachment(String fieldName, String filename, byte[] data, String contentType)
      Creates a new binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      contentType - The attachment's contentType.
      fieldName - The field name the binary belongs to
      Throws:
      IllegalArgumentException - If data is null, filename is null or blank, or contentType is null or blank.
      Since:
      1.6.17
  • Method Details

    • isFacebookReel

      public boolean isFacebookReel()
    • with

      public static BinaryAttachment with(String filename, Supplier<InputStream> dataSupplier)
      Creates a binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • with

      public static BinaryAttachment with(String fieldName, String filename, Supplier<InputStream> dataSupplier)
      Creates a binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      fieldName - The field name the binary belongs to
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • with

      public static BinaryAttachment with(String filename, Supplier<InputStream> dataSupplier, String contentType)
      Creates a binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      contentType - The attachment's contentType.
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • with

      public static BinaryAttachment with(String fieldName, String filename, Supplier<InputStream> dataSupplier, String contentType)
      Creates a binary attachment backed by a stream supplier.
      Parameters:
      filename - The attachment's filename.
      dataSupplier - Provides a fresh InputStream for each access.
      fieldName - The field name the binary belongs to
      contentType - The attachment's contentType.
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If dataSupplier is null or filename is null or blank.
    • with

      public static BinaryAttachment with(String filename, byte[] data)
      Creates a binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • with

      public static BinaryAttachment with(String fieldName, String filename, byte[] data)
      Creates a binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      fieldName - The field name the binary belongs to
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • with

      public static BinaryAttachment with(String filename, byte[] data, String contentType)
      Creates a binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      contentType - The attachment's contentType.
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • with

      public static BinaryAttachment with(String fieldName, String filename, byte[] data, String contentType)
      Creates a binary attachment.
      Parameters:
      filename - The attachment's filename.
      data - The attachment's data.
      contentType - The attachment's contentType.
      fieldName - The field name the binary belongs to
      Returns:
      A binary attachment.
      Throws:
      IllegalArgumentException - If data is null or filename is null or blank.
      Since:
      1.6.17
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getData

      public InputStream getData()
      The attachment's data.
      Returns:
      The attachment's data.
    • getContentType

      return the given content type or try to guess from stream or file name. Depending of the available data.
      Returns:
      the content type
    • hasBinaryData

      public boolean hasBinaryData()
    • getFormFieldName

      Returns the form field name used for multipart uploads.
      Returns:
      the explicit field name if set, otherwise the filename without its extension
    • getFilename

      public String getFilename()
    • getFieldName

      public String getFieldName()