Class HttpStringPart

java.lang.Object
org.apache.juneau.http.part.HttpPartBean
org.apache.juneau.http.part.HttpStringPart
All Implemented Interfaces:
HttpPart

public class HttpStringPart extends HttpPartBean
An HttpPart whose value is a string.

Mirrors the semantics of BasicStringPart from juneau-rest-common-classic without the Apache HttpCore dependency.

Since:
10.0.0
  • Constructor Details

    • HttpStringPart

      protected HttpStringPart(String name, String value)
      Constructor.
      Parameters:
      name - The part name. Must not be null.
      value - The part value. May be null.
    • HttpStringPart

      protected HttpStringPart(String name, Supplier<String> valueSupplier)
      Constructor with lazy value supplier.
      Parameters:
      name - The part name. Must not be null.
      valueSupplier - Supplier that provides the value at request time. Must not be null.
  • Method Details

    • of

      public static HttpStringPart of(String name, String value)
      Creates an HttpStringPart with the given name and string value.
      Parameters:
      name - The part name. Must not be null.
      value - The part value. May be null.
      Returns:
      A new instance. Never null.
    • of

      public static HttpStringPart of(String name, Supplier<String> valueSupplier)
      Creates an HttpStringPart with the given name and lazy value supplier.
      Parameters:
      name - The part name. Must not be null.
      valueSupplier - Supplier for the value. Must not be null.
      Returns:
      A new instance. Never null.
    • ofPair

      public static HttpStringPart ofPair(String pair)
      Parses a part pair of the form "name=value" (or "name:value") into an HttpStringPart.

      If the input does not contain '=' or ':', the entire string is treated as a part name with an empty value.

      Parameters:
      pair - The part pair. May be null.
      Returns:
      A new instance, or null if pair is null.
    • asString

      Returns the value as an Optional.
      Returns:
      The value, wrapped in an Optional. Never null.
    • orElse

      public String orElse(String other)
      Returns the value if present, otherwise returns other.
      Parameters:
      other - The default value.
      Returns:
      The value or other.