Package ch.pontius.nio.smb
Class SMBPath
- java.lang.Object
-
- ch.pontius.nio.smb.SMBPath
-
- All Implemented Interfaces:
java.lang.Comparable<java.nio.file.Path>,java.lang.Iterable<java.nio.file.Path>,java.nio.file.Path,java.nio.file.Watchable
public final class SMBPath extends java.lang.Object implements java.nio.file.PathAPathimplementation that can be used with SMBNio
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(java.nio.file.Path other)Compares two abstract paths lexicographically.booleanendsWith(java.lang.String other)Tests if this path ends with the provided string.booleanendsWith(java.nio.file.Path other)Tests if this path ends with the given path.booleanequals(java.lang.Object other)Tests this path for equality with the given object.java.nio.file.PathgetFileName()java.nio.file.FileSystemgetFileSystem()Getter forSMBFileSystemthisSMBPathbelongs to.java.nio.file.PathgetName(int index)intgetNameCount()Returns the number of path components in the currentSMBPath's path.java.nio.file.PathgetParent()java.nio.file.PathgetRoot()Returns the root component of thisSMBPathor null, if the path is relative.booleanisAbsolute()SMBPathis always absolute!booleanisFolder()Checks whether the currentSMBPathis a folder.java.util.Iterator<java.nio.file.Path>iterator()Returns an iterator over the name elements of thisSMBPath.java.nio.file.Pathnormalize()Returns a path that is this path with redundant name elements, like "." or ".." eliminated.java.nio.file.WatchKeyregister(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events)java.nio.file.WatchKeyregister(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers)java.nio.file.Pathrelativize(java.nio.file.Path other)Constructs a relative path between this path and a given path.java.nio.file.Pathresolve(java.lang.String other)Resolve the given path string against thisSMBPath.java.nio.file.Pathresolve(java.nio.file.Path other)Resolve the given path against thisSMBPath.java.nio.file.PathresolveSibling(java.lang.String other)Resolve the given path string against thisSMBPath.java.nio.file.PathresolveSibling(java.nio.file.Path other)Resolve the given path against thisSMBPath's parent.booleanstartsWith(java.lang.String other)Tests if this path starts with the provided string.booleanstartsWith(java.nio.file.Path other)Tests if this path starts with the given path.java.nio.file.Pathsubpath(int beginIndex, int endIndex)Returns a relative Path that is a subsequence of the name elements of this path.java.nio.file.PathtoAbsolutePath()If thisSMBPathis absolute then the method returns this.java.io.FiletoFile()java.nio.file.PathtoRealPath(java.nio.file.LinkOption... options)java.lang.StringtoString()Default toString() method.java.net.URItoUri()Returns a URI to represent thisSMBPath.
-
-
-
Method Detail
-
getFileSystem
public final java.nio.file.FileSystem getFileSystem()
Getter forSMBFileSystemthisSMBPathbelongs to.- Specified by:
getFileSystemin interfacejava.nio.file.Path- Returns:
SMBFileSystem
-
isAbsolute
public final boolean isAbsolute()
SMBPathis always absolute!- Specified by:
isAbsolutein interfacejava.nio.file.Path- Returns:
- true
-
getRoot
public java.nio.file.Path getRoot()
Returns the root component of thisSMBPathor null, if the path is relative.- Specified by:
getRootin interfacejava.nio.file.Path- Returns:
- Root component of this
SMBPath
-
getFileName
public java.nio.file.Path getFileName()
Returns a new, relativeSMBPathinstance that just contains the last path component of the currentSMBPath's path.- Specified by:
getFileNamein interfacejava.nio.file.Path- Returns:
SMBPathfor the file name.
-
getParent
public java.nio.file.Path getParent()
Returns a newSMBPaththat points to the parent of the currentSMBPath. If the currentSMBPathinstance does not have a parent, this method returns null.- Specified by:
getParentin interfacejava.nio.file.Path- Returns:
- Parent
SMBPath.
-
getNameCount
public int getNameCount()
Returns the number of path components in the currentSMBPath's path.- Specified by:
getNameCountin interfacejava.nio.file.Path- Returns:
- Number of path components.
-
getName
public java.nio.file.Path getName(int index)
Returns a name element of thisSMBPathas a newSMBPathobject. The index parameter is the index of the name element to return. The element that is closest to the root in the directory hierarchy has index 0. The element that is farthest from the root has index count-1.- Specified by:
getNamein interfacejava.nio.file.Path- Parameters:
index- The index of the element- Returns:
- The name element.
-
subpath
public java.nio.file.Path subpath(int beginIndex, int endIndex)Returns a relative Path that is a subsequence of the name elements of this path.- Specified by:
subpathin interfacejava.nio.file.Path- Parameters:
beginIndex- The index of the first element, inclusiveendIndex- The index of the last element, exclusive- Returns:
- The resulting subpath.
- Throws:
java.lang.IllegalArgumentException- If beginIndex is negative, or greater than or equal to the number of elements. If endIndex is less than or equal to beginIndex, or larger than the number of elements.
-
startsWith
public boolean startsWith(java.nio.file.Path other)
Tests if this path starts with the given path. If the two paths belong to a differentFileSystemthen this method always returns false. Otherwise, a string comparison is performed.- Specified by:
startsWithin interfacejava.nio.file.Path- Parameters:
other- The given path- Returns:
- True if this path starts with the given path; otherwise false
-
startsWith
public boolean startsWith(java.lang.String other)
Tests if this path starts with the provided string. The path separators will be taken into account.- Specified by:
startsWithin interfacejava.nio.file.Path- Parameters:
other- The given path- Returns:
- True if this path starts with the given string; otherwise false
-
endsWith
public boolean endsWith(java.nio.file.Path other)
Tests if this path ends with the given path. If the two paths belong to a differentFileSystemthen this method always returns false. Otherwise, a string comparison is performed.- Specified by:
endsWithin interfacejava.nio.file.Path- Parameters:
other- The given path- Returns:
- True if this path starts with the given path; otherwise false
-
endsWith
public boolean endsWith(java.lang.String other)
Tests if this path ends with the provided string. The path separators will be taken into account.- Specified by:
endsWithin interfacejava.nio.file.Path- Parameters:
other- The given path- Returns:
- True if this path starts with the given string; otherwise false
-
normalize
public java.nio.file.Path normalize()
Returns a path that is this path with redundant name elements, like "." or ".." eliminated.- Specified by:
normalizein interfacejava.nio.file.Path- Returns:
- Normalized
SMBPath.
-
resolve
public java.nio.file.Path resolve(java.nio.file.Path other)
Resolve the given path against thisSMBPath. If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns this path.- Specified by:
resolvein interfacejava.nio.file.Path- Parameters:
other- The path to resolve against this path- Returns:
- The resulting
SMBPath - Throws:
java.lang.IllegalArgumentException- If other path is not aSMBPathOR does not belong to the sameSMBFileSystemOR if this path points to a file.
-
resolve
public java.nio.file.Path resolve(java.lang.String other)
Resolve the given path string against thisSMBPath. If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns this path.- Specified by:
resolvein interfacejava.nio.file.Path- Parameters:
other- The path to resolve against this path- Returns:
- The resulting
SMBPath - Throws:
java.lang.IllegalArgumentException- If other path is not aSMBPathOR does not belong to the sameSMBFileSystemOR if this path points to a file.
-
resolveSibling
public java.nio.file.Path resolveSibling(java.nio.file.Path other)
Resolve the given path against thisSMBPath's parent. If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns this path.- Specified by:
resolveSiblingin interfacejava.nio.file.Path- Parameters:
other- The path to resolve against this path- Returns:
- The resulting
SMBPath - Throws:
java.lang.IllegalArgumentException- If other path is not aSMBPathOR does not belong to the sameSMBFileSystem.
-
resolveSibling
public java.nio.file.Path resolveSibling(java.lang.String other)
Resolve the given path string against thisSMBPath. If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns this path.- Specified by:
resolveSiblingin interfacejava.nio.file.Path- Parameters:
other- The path to resolve against this path- Returns:
- The resulting
SMBPath - Throws:
java.lang.IllegalArgumentException- If other path is not aSMBPathOR does not belong to the sameSMBFileSystemOR if this path points to a file.
-
relativize
public java.nio.file.Path relativize(java.nio.file.Path other)
Constructs a relative path between this path and a given path.- Specified by:
relativizein interfacejava.nio.file.Path- Parameters:
other- The other path.- Throws:
java.lang.IllegalArgumentException- If other path is not aSMBPathOR does not belong to the sameSMBFileSystemOR if this path points to a file.
-
toUri
public java.net.URI toUri()
Returns a URI to represent thisSMBPath.- Specified by:
toUriin interfacejava.nio.file.Path- Returns:
- The URI representing this path
-
toAbsolutePath
public java.nio.file.Path toAbsolutePath()
If thisSMBPathis absolute then the method returns this. Otherwise, the given path is resolved against the top-level directory.- Specified by:
toAbsolutePathin interfacejava.nio.file.Path- Returns:
- Absolute
SMBPath
-
iterator
public java.util.Iterator<java.nio.file.Path> iterator()
Returns an iterator over the name elements of thisSMBPath. The first element returned by the iterator represents the name element that is closest to the root in the directory hierarchy, the second element is the next closest, and so on. The last element returned is the name of the file or directory denoted by this path. The root component, if present, is not returned by the iterator.- Specified by:
iteratorin interfacejava.lang.Iterable<java.nio.file.Path>- Specified by:
iteratorin interfacejava.nio.file.Path- Returns:
- An iterator over the name elements of this path.
-
compareTo
public int compareTo(java.nio.file.Path other)
Compares two abstract paths lexicographically. This method does not access the file system and neither file is required to exist.- Specified by:
compareToin interfacejava.lang.Comparable<java.nio.file.Path>- Specified by:
compareToin interfacejava.nio.file.Path- Parameters:
other- The path compared to thisSMBPath.- Returns:
- Zero if the argument is equal to this path, a value less than zero if this path is lexicographically less than the argument, or a value greater than zero if this path is lexicographically greater than the argument
-
toString
public java.lang.String toString()
Default toString() method.- Specified by:
toStringin interfacejava.nio.file.Path- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation of
SMBPath.
-
equals
public boolean equals(java.lang.Object other)
Tests this path for equality with the given object. If the given object is not aSMBPath, or is aSMBPathassociated with a differentSMBFileSystem, then this method returns false.
-
isFolder
public boolean isFolder()
Checks whether the currentSMBPathis a folder.- Returns:
- True if current
SMBPathis a folder.
-
toFile
public java.io.File toFile()
- Specified by:
toFilein interfacejava.nio.file.Path
-
toRealPath
public java.nio.file.Path toRealPath(java.nio.file.LinkOption... options) throws java.io.IOException- Specified by:
toRealPathin interfacejava.nio.file.Path- Throws:
java.io.IOException
-
register
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers) throws java.io.IOException- Specified by:
registerin interfacejava.nio.file.Path- Specified by:
registerin interfacejava.nio.file.Watchable- Throws:
java.io.IOException
-
register
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events) throws java.io.IOException- Specified by:
registerin interfacejava.nio.file.Path- Specified by:
registerin interfacejava.nio.file.Watchable- Throws:
java.io.IOException
-
-