Package net.runelite.client.util
Class Filepath
- java.lang.Object
-
- net.runelite.client.util.Filepath
-
- All Implemented Interfaces:
Comparable<Filepath>
public class Filepath extends Object implements Comparable<Filepath>
A path to a file or directory that cannot escape its original location. AFilepathwrapsPathin a way that prevents Plugins from writing to unexpected locations. Plugins may obtain aFilepathby callingPlugin.getPluginDirectory()or using aFilepath.Chooser- See Also:
Path
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFilepath.ChooserProvides a dialog for users to select a Filepathstatic classFilepath.UncheckedInteracting with these methods prevent PluginHub plugins from being automatically reviewed
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Filepath o)voidcopyTo(Filepath target, CopyOption... options)Copies this file totargetvoidcreateDirectories()voidcreateDirectory()FilepathcreateTempDir(String prefix)FilepathcreateTempFile(String prefix, String suffix)voiddelete()voiddeleteIfExists()voiddeleteRecursively()Deletes this file/directory, and all of the files inside it.booleanequals(Object obj)booleanexists()StringgetFileName()FileTimegetLastModifiedTime()FilepathgetParent()Gets the parent directory of this filepath.FilepathgetRoot()Gets the highest levelFilepaththis can access.inthashCode()booleanisDirectory()booleanisFile()booleanisRoot()Filepathjoin(String append, String... more)Append the given path segments to this pathFilepathjoinSegment(String append)Append a single segment to this path, throwing ifappendis not a single segmentvoidmoveTo(Filepath target, CopyOption... options)Moves this file totargetBufferedReaderopenBufferedReader(OpenOption... options)Opens a file, returning a buffered UTF-8ReaderBufferedWriteropenBufferedWriter(OpenOption... options)Opens or creates a file, returning an buffered UTF-8WriterFileChannelopenFileChannel(OpenOption... options)InputStreamopenInputStream(OpenOption... options)OutputStreamopenOutputStream(OpenOption... options)ReaderopenReader(OpenOption... options)Opens a file, returning an unbuffered UTF-8ReaderWriteropenWriter(OpenOption... options)Opens or creates a file, returning an unbuffered UTF-8WriterFilepathrooted()Create a new filepath with its root set to this filepathlongsize()booleanstartsWith(Filepath other)StringtoString()Stream<Filepath>walk(int maxDepth, FileVisitOption... options)Stream<Filepath>walk(FileVisitOption... options)voidwrite(byte @NonNull [] bytes, OpenOption... options)voidwrite(@NonNull String string, OpenOption... options)Writesstringto this filepath as UTF-8.
-
-
-
Method Detail
-
join
public Filepath join(String append, String... more)
Append the given path segments to this path- See Also:
Path.resolve(java.nio.file.Path)
-
joinSegment
public Filepath joinSegment(String append)
Append a single segment to this path, throwing ifappendis not a single segment
-
getParent
public Filepath getParent()
Gets the parent directory of this filepath.- Throws:
IllegalArgumentException- if this filepathisRoot()- See Also:
Path.getParent()
-
isRoot
public boolean isRoot()
- Returns:
- true if this path can't be used to access it's parent
-
getRoot
public Filepath getRoot()
Gets the highest levelFilepaththis can access.
-
rooted
public Filepath rooted()
Create a new filepath with its root set to this filepath
-
getFileName
public String getFileName()
- See Also:
Path.getFileName()
-
startsWith
public boolean startsWith(Filepath other)
- See Also:
Path.startsWith(Path)
-
createTempFile
public Filepath createTempFile(String prefix, String suffix) throws IOException
-
createTempDir
public Filepath createTempDir(String prefix) throws IOException
-
walk
public Stream<Filepath> walk(FileVisitOption... options) throws IOException
-
walk
public Stream<Filepath> walk(int maxDepth, FileVisitOption... options) throws IOException
-
exists
public boolean exists()
- See Also:
Files.exists(Path, LinkOption...)
-
isFile
public boolean isFile()
- See Also:
Files.isRegularFile(Path, LinkOption...)
-
isDirectory
public boolean isDirectory()
- See Also:
Files.isDirectory(Path, LinkOption...)
-
size
public long size() throws IOException- Throws:
IOException- See Also:
Files.size(Path)
-
getLastModifiedTime
public FileTime getLastModifiedTime() throws IOException
- Throws:
IOException- See Also:
Files.getLastModifiedTime(Path, LinkOption...)
-
delete
public void delete() throws IOException- Throws:
IOException- See Also:
Files.delete(Path)
-
deleteIfExists
public void deleteIfExists() throws IOException- Throws:
IOException- See Also:
Files.deleteIfExists(Path)
-
deleteRecursively
public void deleteRecursively() throws IOExceptionDeletes this file/directory, and all of the files inside it.- Throws:
IOException
-
createDirectory
public void createDirectory() throws IOException
-
createDirectories
public void createDirectories() throws IOException
-
copyTo
public void copyTo(Filepath target, CopyOption... options) throws IOException
Copies this file totarget- Throws:
IOException- See Also:
Files.copy(Path, Path, CopyOption...)
-
moveTo
public void moveTo(Filepath target, CopyOption... options) throws IOException
Moves this file totarget- Throws:
IOException- See Also:
Files.move(Path, Path, CopyOption...)
-
openFileChannel
public FileChannel openFileChannel(OpenOption... options) throws IOException
- Throws:
IOException- See Also:
FileChannel.open(Path, OpenOption...)
-
openInputStream
public InputStream openInputStream(OpenOption... options) throws IOException
- Throws:
IOException- See Also:
Files.newInputStream(Path, OpenOption...)
-
openOutputStream
public OutputStream openOutputStream(OpenOption... options) throws IOException
- Throws:
IOException- See Also:
Files.newOutputStream(Path, OpenOption...)
-
openReader
public Reader openReader(OpenOption... options) throws IOException
Opens a file, returning an unbuffered UTF-8Reader- Throws:
IOException
-
openBufferedReader
public BufferedReader openBufferedReader(OpenOption... options) throws IOException
Opens a file, returning a buffered UTF-8Reader- Throws:
IOException
-
openWriter
public Writer openWriter(OpenOption... options) throws IOException
Opens or creates a file, returning an unbuffered UTF-8Writer- Throws:
IOException
-
openBufferedWriter
public BufferedWriter openBufferedWriter(OpenOption... options) throws IOException
Opens or creates a file, returning an buffered UTF-8Writer- Throws:
IOException
-
write
public void write(byte @NonNull [] bytes, OpenOption... options) throws IOException- Throws:
IOException- See Also:
Files.write(Path, byte[], OpenOption...)
-
write
public void write(@NonNull @NonNull String string, OpenOption... options) throws IOExceptionWritesstringto this filepath as UTF-8.- Throws:
IOException- See Also:
Files.write(Path, byte[], OpenOption...)
-
compareTo
public int compareTo(Filepath o)
- Specified by:
compareToin interfaceComparable<Filepath>
-
-