Package org.broadinstitute.http.nio
Class HttpPath
java.lang.Object
org.broadinstitute.http.nio.HttpPath
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final HttpFileSystem
private final byte[]
private int[]
private final String
private final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
HttpPath
(HttpFileSystem fs, String query, String reference, boolean absolute, byte... normalizedPath) Internal constructor.(package private)
HttpPath
(HttpFileSystem fs, String path, String query, String reference) Creates a new Path in the providedHttpFileSystem
, with optional query and reference. -
Method Summary
Modifier and TypeMethodDescriptionprivate static char
checkNotNull
(String path, char c) int
private static byte[]
concatPaths
(byte[] array1, byte[] array2) private boolean
endsWith
(byte[] other, boolean pathVersion) Private method to test endsWith only for the path component.boolean
boolean
boolean
private HttpPath
fromRelativeString
(String other) private static int
getLastIndexWithoutTrailingSlash
(byte[] path) Gets the last index to consider in the path bytes.getName
(int index) int
private static byte[]
getNormalizedPathBytes
(String path, boolean checkRelative) Gets the path as a normalized (without multiple slashes) array of bytes.private static byte[]
getNormalizedPathBytes
(String path, int len, int offset) getRoot()
int
hashCode()
private void
Creates the array of offsets if not already created.boolean
private static boolean
isDoubleSeparator
(char prevChar, char c) iterator()
register
(WatchService watcher, WatchEvent.Kind<?>... events) register
(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) relativize
(Path other) private HttpPath
resolveSibling
(String other) private boolean
startsWith
(byte[] other) Private method to test startsWith only for the path component.boolean
startsWith
(String other) boolean
startsWith
(Path other) subpath
(int beginIndex, int endIndex) private HttpPath
subpath
(int beginIndex, int endIndex, boolean absolute) Helper method to implement different subpath routines with different absolute/relative status.toFile()
Unsupported method.toRealPath
(LinkOption... options) toString()
toUri()
private String
toUriString
(boolean includeRoot) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface java.nio.file.Path
resolveSibling
-
Field Details
-
fs
-
normalizedPath
private final byte[] normalizedPath -
offsets
private volatile int[] offsets -
query
-
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 benull
.query
- query. May benull
.reference
- reference. May benull
.normalizedPath
- normalized path (as a byte array). Shouldn't benull
.
-
HttpPath
HttpPath(HttpFileSystem fs, String path, String query, String reference) Creates a new Path in the providedHttpFileSystem
, 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
- Specified by:
getFileSystem
in interfacePath
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolute
in interfacePath
-
getRoot
-
getFileName
- Specified by:
getFileName
in interfacePath
-
getParent
-
getNameCount
public int getNameCount()- Specified by:
getNameCount
in interfacePath
-
getName
-
subpath
-
subpath
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, inclusiveendIndex
- the index of the last element, exclusiveabsolute
-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
- Specified by:
startsWith
in interfacePath
-
startsWith
- Specified by:
startsWith
in interfacePath
-
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
ifnormalizedPath
ends withother
;false
otherwise.
-
endsWith
-
endsWith
-
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
- iffalse
, perform an extra check for the String version.- Returns:
true
ifnormalizedPath
ends withother
;false
otherwise.
-
normalize
-
resolve
-
resolve
-
resolve
-
resolveSibling
- Specified by:
resolveSibling
in interfacePath
-
relativize
- Specified by:
relativize
in interfacePath
-
fromRelativeString
-
toUri
-
toAbsolutePath
- Specified by:
toAbsolutePath
in interfacePath
-
toRealPath
- Specified by:
toRealPath
in interfacePath
- Throws:
IOException
-
toFile
Unsupported method. -
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException - Specified by:
register
in interfacePath
- Specified by:
register
in interfaceWatchable
- Throws:
IOException
-
register
- Specified by:
register
in interfacePath
- Specified by:
register
in interfaceWatchable
- Throws:
IOException
-
iterator
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Path>
- Specified by:
compareTo
in interfacePath
-
equals
-
hashCode
public int hashCode() -
toString
-
toUriString
-
initOffsets
private void initOffsets()Creates the array of offsets if not already created. -
getNormalizedPathBytes
Gets the path as a normalized (without multiple slashes) array of bytes.- Parameters:
path
- path to convert into byte[]checkRelative
- iftrue
, check if the path is absolute.- Returns:
- array of bytes, without multiple slashes together.
-
getNormalizedPathBytes
-
isDoubleSeparator
private static boolean isDoubleSeparator(char prevChar, char c) -
checkNotNull
-
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)
-