Interface Path

All Superinterfaces:
Normalisable<Path>, org.wiremock.stringparser.ParsedString, PercentEncoded<Path>

public interface Path extends PercentEncoded<Path>, org.wiremock.stringparser.ParsedString
Represents the path component of a URI as defined in RFC 3986 Section 3.3.

A path consists of a sequence of segments separated by forward slashes. Paths can be absolute (starting with /) or relative. Path segments may contain percent-encoded characters.

Implementations must be immutable and thread-safe.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Path
    An empty path with no segments.
    static final Path
    A root path consisting of a single forward slash.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Path
    append(Path toAppend)
     
    static Path
    encode(String unencoded)
    Encodes a string into a valid path with proper percent-encoding.
    default Segment
     
    default Segment
     
    Returns the segments of this path.
    boolean
    Returns true if this path is absolute (starts with /).
    default boolean
    Returns true if this path is a base path (empty, or ends with /).
    default boolean
    Returns true if this path is empty (has no segments).
    default boolean
    Returns true if this path is a leaf path (last segment is not empty).
    default boolean
    Returns true if this path is not absolute (does not start with /).
    Returns a normalised form of this path with dot segments removed.
    static Path
    of(List<Segment> segments)
     
    static Path
    of(Stream<Segment> segments)
     
    static Path
    parse(String path)
    Parses a string into a path.
    default Path
     
    resolve(Path other)
    Resolves the given path against this path using reference resolution rules.
    default Path
    Returns this path with a leading slash added if not present
    default Path
    Returns this path with a trailing slash added if not present and not empty
    default Path
    Returns this path with any trailing slash removed
    default Path
    Returns this path with any leading slash removed

    Methods inherited from interface org.wiremock.url.Normalisable

    isNormalForm

    Methods inherited from interface org.wiremock.stringparser.ParsedString

    toString

    Methods inherited from interface org.wiremock.url.PercentEncoded

    decode, length
  • Field Details

    • EMPTY

      static final Path EMPTY
      An empty path with no segments.
    • ROOT

      static final Path ROOT
      A root path consisting of a single forward slash.
  • Method Details

    • isAbsolute

      boolean isAbsolute()
      Returns true if this path is absolute (starts with /).
      Returns:
      true if this is an absolute path
    • isRelative

      default boolean isRelative()
      Returns true if this path is not absolute (does not start with /).
      Returns:
      true if this is a relative path
    • isBase

      default boolean isBase()
      Returns true if this path is a base path (empty, or ends with /). e.g. /base/
      Returns:
      true if this is a base path
    • isLeaf

      default boolean isLeaf()
      Returns true if this path is a leaf path (last segment is not empty). e.g. /segment/leaf
      Returns:
      true if this is a leaf path
    • getSegments

      List<Segment> getSegments()
      Returns the segments of this path.
      Returns:
      the list of path segments, never null
    • getFirstSegment

      default Segment getFirstSegment()
    • getLastSegment

      default Segment getLastSegment()
    • normalise

      Path normalise()
      Returns a normalised form of this path with dot segments removed.
      Specified by:
      normalise in interface Normalisable<Path>
      Returns:
      a normalised path
      See Also:
    • resolve

      Path resolve(Path other)
      Resolves the given path against this path using reference resolution rules.
      Parameters:
      other - the path to resolve
      Returns:
      the resolved path
      See Also:
    • isEmpty

      default boolean isEmpty()
      Returns true if this path is empty (has no segments).
      Specified by:
      isEmpty in interface PercentEncoded<Path>
      Returns:
      true if this path is empty
    • toAbsolutePath

      default Path toAbsolutePath()
      Returns this path with a leading slash added if not present
    • toRelativePath

      default Path toRelativePath()
      Returns this path with any leading slash removed
    • toBasePath

      default Path toBasePath()
      Returns this path with a trailing slash added if not present and not empty
    • toLeafPath

      default Path toLeafPath()
      Returns this path with any trailing slash removed
    • parse

      static Path parse(String path) throws IllegalPath
      Parses a string into a path.
      Parameters:
      path - the string to parse
      Returns:
      the parsed path
      Throws:
      IllegalPath - if the string is not a valid path
    • encode

      static Path encode(String unencoded)
      Encodes a string into a valid path with proper percent-encoding.
      Parameters:
      unencoded - the unencoded string
      Returns:
      the encoded path
    • of

      static Path of(List<Segment> segments)
    • of

      static Path of(Stream<Segment> segments)
    • removePrefix

      default Path removePrefix(Path prefix)
    • append

      default Path append(Path toAppend)