Package io.trino.filesystem
Class Location
java.lang.Object
io.trino.filesystem.Location
Location of a file or directory in a blob or hierarchical file system.
The location uses the URI like format
scheme://[userInfo@]host[:port][/path], but does not
follow the format rules of a URI or URL which support escapes and other special characters.
Alternatively, a location can be specified as /path for usage with legacy HDFS installations,
or as file:/path for local file systems as returned by File.toURI().
The API of this class is very limited, so blob storage locations can be used as well. Specifically, methods are provided to get the name of a file location, get the parent of a location, append a path to a location, and parse a location. This allows for the operations needed for analysing data in an object store where you need to create subdirectories, and get peers of a file. Specifically, walking up a path is discouraged as some blob locations have invalid inner path parts.
-
Method Summary
Modifier and TypeMethodDescriptionappendPath(String newPathElement) Creates a new location by appending the given path element to the current path.appendSuffix(String suffix) Creates a new location by appending the given suffix to the current path.booleanfileName()Returns the file name of the location.inthashCode()host()Returns the host of the location, if present.static LocationCreates a new location with all characters removed after the last slash in the path.path()Returns the path of the location.port()scheme()Returns the scheme of the location, if present.Returns a new location with the same parent directory as the current location, but with the filename corresponding to the specified name.toString()Return the original location string.userInfo()Returns the user info of the location, if present.voidVerifies the location is valid for a file reference.
-
Method Details
-
of
-
scheme
Returns the scheme of the location, if present. If the scheme is present, the value will not be an empty string. Legacy HDFS paths do not have a scheme. -
userInfo
Returns the user info of the location, if present. The user info will be present if the location authority contains an at sign, but the value may be an empty string. -
host
Returns the host of the location, if present. If the host is present, the value will not be an empty string. -
port
-
path
Returns the path of the location. The path will not start with a slash, and might be empty. -
fileName
Returns the file name of the location. The location must be a valid file location. The file name is all characters after the last slash in the path.- Throws:
IllegalStateException- if the location is not a valid file location
-
sibling
Returns a new location with the same parent directory as the current location, but with the filename corresponding to the specified name. The location must be a valid file location. -
parentDirectory
Creates a new location with all characters removed after the last slash in the path. This should only be used once, as recursive calls for blob paths may lead to incorrect results.- Throws:
IllegalStateException- if the location is not a valid file location
-
appendPath
Creates a new location by appending the given path element to the current path. A slash will be added between the current path and the new path element if needed.- Throws:
IllegalArgumentException- if the new path element is empty or starts with a slash
-
appendSuffix
Creates a new location by appending the given suffix to the current path. Typical usage for this method is to append a file extension to a file name, but it may be used to append anything, including a slash.Use
appendPath(String)instead of this method to append a path element. -
verifyValidFileLocation
public void verifyValidFileLocation()Verifies the location is valid for a file reference. Specifically, the path must not be empty and must not end with a slash.- Throws:
IllegalStateException- if the location is not a valid file location
-
equals
-
hashCode
public int hashCode() -
toString
Return the original location string.
-