Class HttpPath

java.lang.Object
org.broadinstitute.http.nio.HttpPath
All Implemented Interfaces:
Comparable<Path>, Iterable<Path>, Path, Watchable

final class HttpPath extends Object implements Path
Path for HTTP/S.

The HTTP/S paths holds the following information:

  • The HttpFileSystem originating the path. The protocol is retrieved, if necessary, from the provider of the File System.
  • The hostname and domain for the URL/URI in a single authority String.
  • If present, the path component of the URL/URI.
  • If present, the query and reference Strings.
  • Field Details

    • fs

      private final HttpFileSystem fs
    • normalizedPath

      private final byte[] normalizedPath
    • offsets

      private volatile int[] offsets
    • query

      private final String query
    • reference

      private final String reference
    • absolute

      private final boolean absolute
  • Constructor Details

    • HttpPath

      private HttpPath(HttpFileSystem fs, String query, String reference, boolean absolute, byte... normalizedPath)
      Internal constructor.
      Parameters:
      fs - file system. Shouldn't be null.
      query - query. May be null.
      reference - reference. May be null.
      normalizedPath - normalized path (as a byte array). Shouldn't be null.
    • HttpPath

      HttpPath(HttpFileSystem fs, String path, String query, String reference)
      Creates a new Path in the provided HttpFileSystem, with optional query and reference.
      Parameters:
      fs - file system representing the base URL (scheme and authority).
      path - path (absolute) component for the URL (required).
      query - query component for the URL (optional).
      reference - reference component for the URL (optional).
  • Method Details

    • getFileSystem

      public HttpFileSystem getFileSystem()
      Specified by:
      getFileSystem in interface Path
    • isAbsolute

      public boolean isAbsolute()
      Specified by:
      isAbsolute in interface Path
    • getRoot

      public Path getRoot()
      Specified by:
      getRoot in interface Path
    • getFileName

      public Path getFileName()
      Specified by:
      getFileName in interface Path
    • getParent

      public Path getParent()
      Specified by:
      getParent in interface Path
    • getNameCount

      public int getNameCount()
      Specified by:
      getNameCount in interface Path
    • getName

      public Path getName(int index)
      Specified by:
      getName in interface Path
    • subpath

      public Path subpath(int beginIndex, int endIndex)
      Specified by:
      subpath in interface Path
    • subpath

      private HttpPath subpath(int beginIndex, int endIndex, boolean absolute)
      Helper method to implement different subpath routines with different absolute/relative status.

      The contract of this method is the same as Path.subpath(int, int)).

      Parameters:
      beginIndex - the index of the first element, inclusive
      endIndex - the index of the last element, exclusive
      absolute - true if the returned path is absolute; false otherwise.
      Returns:
      a new path object that is a subsequence of the nams elements in this HttpPath.
    • startsWith

      public boolean startsWith(Path other)
      Specified by:
      startsWith in interface Path
    • startsWith

      public boolean startsWith(String other)
      Specified by:
      startsWith in interface Path
    • startsWith

      private boolean startsWith(byte[] other)
      Private method to test startsWith only for the path component.

      The contract for this method is the same as startsWith(Path) (Path)}, but only for the path component.

      Parameters:
      other - the other path component.
      Returns:
      true if normalizedPath ends with other; false otherwise.
    • endsWith

      public boolean endsWith(Path other)
      Specified by:
      endsWith in interface Path
    • endsWith

      public boolean endsWith(String other)
      Specified by:
      endsWith in interface Path
    • endsWith

      private boolean endsWith(byte[] other, boolean pathVersion)
      Private method to test endsWith only for the path component.

      The contract for this method is the same as endsWith(Path), but only for the path component.

      Parameters:
      other - the other path component.
      pathVersion - if false, perform an extra check for the String version.
      Returns:
      true if normalizedPath ends with other; false otherwise.
    • normalize

      public Path normalize()
      Specified by:
      normalize in interface Path
    • resolve

      public HttpPath resolve(Path other)
      Specified by:
      resolve in interface Path
    • resolve

      private HttpPath resolve(URI other)
    • resolve

      public HttpPath resolve(String other)
      Specified by:
      resolve in interface Path
    • resolveSibling

      public Path resolveSibling(String other)
      Specified by:
      resolveSibling in interface Path
    • relativize

      public Path relativize(Path other)
      Specified by:
      relativize in interface Path
    • fromRelativeString

      private HttpPath fromRelativeString(String other)
    • toUri

      public URI toUri()
      Specified by:
      toUri in interface Path
    • toAbsolutePath

      public Path toAbsolutePath()
      Specified by:
      toAbsolutePath in interface Path
    • toRealPath

      public Path toRealPath(LinkOption... options) throws IOException
      Specified by:
      toRealPath in interface Path
      Throws:
      IOException
    • toFile

      public File toFile()
      Unsupported method.
      Specified by:
      toFile in interface Path
    • register

      public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
      Specified by:
      register in interface Path
      Specified by:
      register in interface Watchable
      Throws:
      IOException
    • register

      public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
      Specified by:
      register in interface Path
      Specified by:
      register in interface Watchable
      Throws:
      IOException
    • iterator

      public Iterator<Path> iterator()
      Specified by:
      iterator in interface Iterable<Path>
      Specified by:
      iterator in interface Path
    • compareTo

      public int compareTo(Path other)
      Specified by:
      compareTo in interface Comparable<Path>
      Specified by:
      compareTo in interface Path
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Path
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Path
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Specified by:
      toString in interface Path
      Overrides:
      toString in class Object
    • toUriString

      private String toUriString(boolean includeRoot)
    • initOffsets

      private void initOffsets()
      Creates the array of offsets if not already created.
    • getNormalizedPathBytes

      private static byte[] getNormalizedPathBytes(String path, boolean checkRelative)
      Gets the path as a normalized (without multiple slashes) array of bytes.
      Parameters:
      path - path to convert into byte[]
      checkRelative - if true, check if the path is absolute.
      Returns:
      array of bytes, without multiple slashes together.
    • getNormalizedPathBytes

      private static byte[] getNormalizedPathBytes(String path, int len, int offset)
    • isDoubleSeparator

      private static boolean isDoubleSeparator(char prevChar, char c)
    • checkNotNull

      private static char checkNotNull(String path, char c)
    • getLastIndexWithoutTrailingSlash

      private static int getLastIndexWithoutTrailingSlash(byte[] path)
      Gets the last index to consider in the path bytes.

      If the lst index is a trailing slash HttpUtils.HTTP_PATH_SEPARATOR_CHAR, it should not be considered for some operations. This method takes into account that problem.

      Parameters:
      path - bytes representing the path.
      Returns:
      last index of path to consider.
    • concatPaths

      private static byte[] concatPaths(byte[] array1, byte[] array2)