Class TruffleFile
- Since:
- 19.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a file's attribute.static final classA view over file's attributes values obtained bygetAttributes.static interfaceA detector for findingfile's MIME type and encoding. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TruffleFile.AttributeDescriptor<FileTime> The file's creation time.static final TruffleFile.AttributeDescriptor<Boolean> Represents the file a directory.static final TruffleFile.AttributeDescriptor<Boolean> Represents the file a special file (device, named pipe).static final TruffleFile.AttributeDescriptor<Boolean> Represents the file a regular file.static final TruffleFile.AttributeDescriptor<Boolean> Represents the file a symbolic link.static final TruffleFile.AttributeDescriptor<FileTime> The file's last access time.static final TruffleFile.AttributeDescriptor<FileTime> The file's last modified time.static final TruffleFile.AttributeDescriptor<Long> The file's size in bytes.static final TruffleFile.AttributeDescriptor<FileTime> The file's last status change time.static final TruffleFile.AttributeDescriptor<Long> The id of a device containing the file.static final TruffleFile.AttributeDescriptor<Integer> The group id of file owner.static final TruffleFile.AttributeDescriptor<GroupPrincipal> The group owner of the file.static final TruffleFile.AttributeDescriptor<Long> The file's inode number.static final TruffleFile.AttributeDescriptor<Integer> The file's mode containing the protection and file type bits.static final TruffleFile.AttributeDescriptor<Integer> The number of hard links.static final TruffleFile.AttributeDescriptor<UserPrincipal> The owner of the file.static final TruffleFile.AttributeDescriptor<Set<PosixFilePermission>> The file's Posix permissions.static final TruffleFile.AttributeDescriptor<Long> The id of a device represented by the file.static final TruffleFile.AttributeDescriptor<Integer> The user id of file owner. -
Method Summary
Modifier and TypeMethodDescriptionvoidcopy(TruffleFile target, CopyOption... options) Copies the file.voidcreateDirectories(FileAttribute<?>... attributes) Creates a directory and all nonexistent parent directories.voidcreateDirectory(FileAttribute<?>... attributes) Creates a new directory.voidcreateFile(FileAttribute<?>... attributes) Creates a new empty file.voidcreateLink(TruffleFile target) Creates a new link to an existing target (optional operation).voidcreateSymbolicLink(TruffleFile target, FileAttribute<?>... attrs) Creates a symbolic link to a target (optional operation).voiddelete()Deletes the file.Detects thefileMIME type.booleanendsWith(TruffleFile other) Tests if thisTruffleFilepath ends with the givenTruffleFilepath.booleanTests if thisTruffleFilepath ends with the given path.booleanbooleanexists(LinkOption... options) Tests existence of a file.Resolves thisTruffleFileto absoluteTruffleFile.<T> TgetAttribute(TruffleFile.AttributeDescriptor<T> attribute, LinkOption... linkOptions) Reads a single file's attribute.getAttributes(Collection<? extends TruffleFile.AttributeDescriptor<?>> attributes, LinkOption... linkOptions) Reads file's attributes as a bulk operation.getCanonicalFile(LinkOption... options) Returns aTruffleFilerepresenting the real (canonical) path of an existing file.getCreationTime(LinkOption... options) Returns the creation time.getGroup(LinkOption... options) Returns the group owner of the file.getLastAccessTime(LinkOption... options) Returns the last access time.getLastModifiedTime(LinkOption... options) Returns the last modified time.Deprecated.getName()Returns the name of thisTruffleFile.getOwner(LinkOption... options) Returns the owner of the file.Returns a parentTruffleFileor null when the file does not have a parent.getPath()Returns the string representation of thisTruffleFile.getPosixPermissions(LinkOption... linkOptions) Returns the file's Posix permissions.inthashCode()booleanTests if thisTruffleFile's path is absolute.booleanisDirectory(LinkOption... options) Tests if a file is a directory.booleanTests if a file is executable.booleanTests if a file is readable.booleanisRegularFile(LinkOption... options) Tests if a file is a regular file.booleanisSameFile(TruffleFile other, LinkOption... options) Tests if this and the givenTruffleFilerefer to the same physical file.booleanTests if a file is a symbolic link.booleanTests if a file is writable.list()Returns a collection ofTruffleFiles in the directory denoted by thisTruffleFile.voidmove(TruffleFile target, CopyOption... options) Moves or renames the file.Opens a file for reading returning aBufferedReaderto access the file content.newBufferedReader(Charset charset) Opens a file for reading returning aBufferedReaderto access the file content.newBufferedWriter(Charset charset, OpenOption... options) Opens a file for writing returning anBufferedWriter.newBufferedWriter(OpenOption... options) Opens a file for writing returning anBufferedWriter.newByteChannel(Set<? extends OpenOption> options, FileAttribute<?>... attributes) Opens or creates a file returning aSeekableByteChannelto access the file content.Opens a directory, returning aDirectoryStreamto iterate over all entries in the directory.newInputStream(OpenOption... options) Opens a file for reading returning anInputStreamto access the file content.newOutputStream(OpenOption... options) Opens a file for writing returning anOutputStream.Returns aTruffleFilewith removed redundant name elements in it's path.byte[]Reads a file content as bytes.Reads the target of a symbolic link.relativize(TruffleFile other) Resolves given string path representation against thisTruffleFile.resolveSibling(String name) Resolves given string path representation against the parent of thisTruffleFile.<T> voidsetAttribute(TruffleFile.AttributeDescriptor<T> attribute, T value, LinkOption... linkOptions) Sets a single file's attribute.voidsetCreationTime(FileTime time, LinkOption... options) Sets the file's creation time.voidsetLastAccessTime(FileTime time, LinkOption... options) Sets the file's last access time.voidsetLastModifiedTime(FileTime time, LinkOption... options) Sets the file's last modified time.voidsetPosixPermissions(Set<? extends PosixFilePermission> permissions, LinkOption... linkOptions) Sets the file's Posix permissions.longsize(LinkOption... options) Returns the size of a file.booleanstartsWith(TruffleFile other) Tests if thisTruffleFilepath starts with the givenTruffleFilepath.booleanstartsWith(String other) Tests if thisTruffleFilepath starts with the given path.Returns a relativeURIrepresentation of non absoluteTruffleFile.toString()toUri()Returns the absoluteURIrepresentation of thisTruffleFile.voidvisit(FileVisitor<TruffleFile> visitor, int maxDepth, FileVisitOption... options) Visits thisTruffleFilefile tree.
-
Field Details
-
LAST_MODIFIED_TIME
The file's last modified time. Supported by all filesystems.- Since:
- 19.0
-
LAST_ACCESS_TIME
The file's last access time. Supported by all filesystems.- Since:
- 19.0
-
CREATION_TIME
The file's creation time. Supported by all filesystems.- Since:
- 19.0
-
IS_REGULAR_FILE
Represents the file a regular file. Supported by all filesystems.- Since:
- 19.0
-
IS_DIRECTORY
Represents the file a directory. Supported by all filesystems.- Since:
- 19.0
-
IS_SYMBOLIC_LINK
Represents the file a symbolic link. Supported by all filesystems.- Since:
- 19.0
-
IS_OTHER
Represents the file a special file (device, named pipe). Supported by all filesystems.- Since:
- 19.0
-
SIZE
The file's size in bytes. Supported by all filesystems.- Since:
- 19.0
-
UNIX_OWNER
The owner of the file. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_GROUP
The group owner of the file. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_PERMISSIONS
The file's Posix permissions. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_MODE
The file's mode containing the protection and file type bits. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_INODE
The file's inode number. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_DEV
The id of a device containing the file. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_RDEV
The id of a device represented by the file. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_NLINK
The number of hard links. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_UID
The user id of file owner. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_GID
The group id of file owner. Supported only by UNIX native filesystem.- Since:
- 19.0
-
UNIX_CTIME
The file's last status change time. Supported only by UNIX native filesystem.- Since:
- 19.0
-
-
Method Details
-
exists
Tests existence of a file.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
trueif the file exists- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isReadable
public boolean isReadable()Tests if a file is readable. Checks if the file exists and this Java virtual machine has enough privileges to read the file.- Returns:
trueif the file exists and is readable- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isWritable
public boolean isWritable()Tests if a file is writable. Checks if the file exists and this Java virtual machine has enough privileges to write to the file.- Returns:
trueif the file exists and is writable- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isExecutable
public boolean isExecutable()Tests if a file is executable. Checks if the file exists and this Java virtual machine has enough privileges to execute the file.- Returns:
trueif the file exists and is executable- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isDirectory
Tests if a file is a directory. Checks if the file exists and is a directory.- Parameters:
options- the options determining how the symbolic links should be handled, by default the symbolic links are followed.- Returns:
trueif the file exists and is a directory- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isRegularFile
Tests if a file is a regular file. Checks if the file exists and is a regular file.- Parameters:
options- the options determining how the symbolic links should be handled, by default the symbolic links are followed.- Returns:
trueif the file exists and is a regular file- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isSymbolicLink
public boolean isSymbolicLink()Tests if a file is a symbolic link. Checks if the file exists and is a symbolic link.- Returns:
trueif the file exists and is a symbolic link- Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
isAbsolute
public boolean isAbsolute()Tests if thisTruffleFile's path is absolute.- Returns:
trueif the file path is absolute- Since:
- 19.0
-
getName
Returns the name of thisTruffleFile.- Returns:
- the name of file or directory denoted by this
TruffleFile, ornullif the file is a root directory - Since:
- 19.0
-
getPath
Returns the string representation of thisTruffleFile.- Returns:
- the path of this
TruffleFile - Since:
- 19.0
-
toUri
Returns the absoluteURIrepresentation of thisTruffleFile.- Returns:
- the absolute
URIrepresenting theTruffleFile - Throws:
SecurityException- if theFileSystemdenied a resolution of an absolute path- Since:
- 19.0
-
toRelativeUri
Returns a relativeURIrepresentation of non absoluteTruffleFile. If thisTruffleFileis relative it returns a relativeURI. For anabsoluteTruffleFileit returns an absoluteURI.- Returns:
- the
URIrepresenting theTruffleFile - Since:
- 19.0
-
getAbsoluteFile
Resolves thisTruffleFileto absoluteTruffleFile. If thisTruffleFileis already absolute this method returns thisTruffleFilewithout any resolution.- Returns:
- the absolute
TruffleFile - Throws:
SecurityException- if theFileSystemdenied a resolution of an absolute path- Since:
- 19.0
-
getCanonicalFile
Returns aTruffleFilerepresenting the real (canonical) path of an existing file.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- a
TruffleFilerepresenting the absolute canonical path - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getParent
Returns a parentTruffleFileor null when the file does not have a parent.- Returns:
- the parent
TruffleFile - Since:
- 19.0
-
resolve
Resolves given string path representation against thisTruffleFile.- Parameters:
name- the path to resolve- Returns:
- the resolved
TruffleFile - Throws:
InvalidPathException- if the path string contains non valid characters- Since:
- 19.0
-
resolveSibling
Resolves given string path representation against the parent of thisTruffleFile.- Parameters:
name- the path to resolve- Returns:
- the resolved
TruffleFile - Throws:
InvalidPathException- if the path string contains non valid characters- Since:
- 19.0
-
size
Returns the size of a file.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the file size in bytes
- Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getLastModifiedTime
Returns the last modified time.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the
FileTimerepresenting the time thisTruffleFilewas last modified - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
setLastModifiedTime
Sets the file's last modified time.- Parameters:
time- the new value of the last modified timeoptions- the options determining how the symbolic links should be handled- Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getLastAccessTime
Returns the last access time.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the
FileTimerepresenting the time thisTruffleFilewas last accessed - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
setLastAccessTime
Sets the file's last access time.- Parameters:
time- the new value of the last access timeoptions- the options determining how the symbolic links should be handled- Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getCreationTime
Returns the creation time.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the
FileTimerepresenting the time thisTruffleFilewas created - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
setCreationTime
Sets the file's creation time.- Parameters:
time- the new value of the creation timeoptions- the options determining how the symbolic links should be handled- Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
list
Returns a collection ofTruffleFiles in the directory denoted by thisTruffleFile.- Returns:
- a collection of
TruffleFiles located in the directory denoted by thisTruffleFile - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newByteChannel
public SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, FileAttribute<?>... attributes) throws IOException Opens or creates a file returning aSeekableByteChannelto access the file content. In most cases, the returnedSeekableByteChannelshould be closed using try-with-resources construct. When the channel must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose.- Parameters:
options- the options specifying how the file should be openedattributes- the optional attributes to set atomically when creating the new file- Returns:
- the created
SeekableByteChannel - Throws:
FileAlreadyExistsException- ifStandardOpenOption.CREATE_NEWoption is set and a file already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if the attributes contain an attribute which cannot be set atomicallyIllegalArgumentException- in case of invalid options combinationSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newInputStream
Opens a file for reading returning anInputStreamto access the file content. In most cases, the returnedInputStreamshould be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose.- Parameters:
options- the options specifying how the file should be opened- Returns:
- the created
InputStream - Throws:
IOException- in case of IO errorIllegalArgumentException- in case of invalid options combinationSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newBufferedReader
Opens a file for reading returning aBufferedReaderto access the file content. In most cases, the returnedBufferedReadershould be closed using try-with-resources construct. When the reader must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose.- Parameters:
charset- the file encoding- Returns:
- the created
BufferedReader - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newBufferedReader
Opens a file for reading returning aBufferedReaderto access the file content. SeenewBufferedReader(Charset).- Returns:
- the created
BufferedReader - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
readAllBytes
Reads a file content as bytes.- Returns:
- the created
byte[] - Throws:
IOException- in case of IO errorOutOfMemoryError- if an array of a file size cannot be allocatedSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newOutputStream
Opens a file for writing returning anOutputStream. In most cases, the returnedOutputStreamshould be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose.- Parameters:
options- the options specifying how the file should be opened- Returns:
- the created
OutputStream - Throws:
IOException- in case of IO errorIllegalArgumentException- in case of invalid options combinationSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newBufferedWriter
Opens a file for writing returning anBufferedWriter. In most cases, the returnedBufferedWritershould be closed using try-with-resources construct. When the writer must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose.- Parameters:
charset- the file encodingoptions- the options specifying how the file should be opened- Returns:
- the created
BufferedWriter - Throws:
IOException- in case of IO errorIllegalArgumentException- in case of invalid options combinationSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newBufferedWriter
Opens a file for writing returning anBufferedWriter. SeenewBufferedWriter(Charset, OpenOption...).- Parameters:
options- the options specifying how the file should be opened- Returns:
- the created
BufferedWriter - Throws:
IOException- in case of IO errorIllegalArgumentException- in case of invalid options combinationSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
createFile
Creates a new empty file.- Parameters:
attributes- the optional attributes to set atomically when creating the new file- Throws:
FileAlreadyExistsException- if the file already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if the attributes contain an attribute which cannot be set atomicallySecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
createDirectory
Creates a new directory.- Parameters:
attributes- the optional attributes to set atomically when creating the new file- Throws:
FileAlreadyExistsException- if the file or directory already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if the attributes contain an attribute which cannot be set atomicallySecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
createDirectories
Creates a directory and all nonexistent parent directories. Unlike thecreateDirectory(java.nio.file.attribute.FileAttribute<?>...)theFileAlreadyExistsExceptionis not thrown if the directory already exists.- Parameters:
attributes- the optional attributes to set atomically when creating the new file- Throws:
FileAlreadyExistsException- if a file (not a directory) already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if the attributes contain an attribute which cannot be set atomicallySecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
delete
Deletes the file. If theTruffleFiledenotes a directory, the directory must be empty before deleting. If theTruffleFiledenotes a symbolic link the symbolic link itself is deleted not its target.- Throws:
NoSuchFileException- if the file does not existDirectoryNotEmptyException- if theTruffleFiledenotes a non empty directoryIOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
move
Moves or renames the file.- Parameters:
target- the path of a target fileoptions- the options specifying how the move should be performed, seeStandardCopyOption- Throws:
UnsupportedOperationException- ifoptionscontains unsupported optionFileAlreadyExistsException- if the target path already exists and theoptionsdon't containStandardCopyOption.REPLACE_EXISTINGoptionDirectoryNotEmptyException- if theoptionscontainStandardCopyOption.REPLACE_EXISTINGbut thetargetis a non empty directoryAtomicMoveNotSupportedException- if theoptionscontainStandardCopyOption.ATOMIC_MOVEbut file cannot be moved atomicallyIOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getPosixPermissions
Returns the file's Posix permissions.- Parameters:
linkOptions- the options determining how the symbolic links should be handled- Returns:
- the the file's Posix permissions
- Throws:
IOException- in case of IO errorUnsupportedOperationException- when the Posix permissions are not supported by filesystemSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
setPosixPermissions
public void setPosixPermissions(Set<? extends PosixFilePermission> permissions, LinkOption... linkOptions) throws IOException Sets the file's Posix permissions.- Parameters:
permissions- the Posix permissions to setlinkOptions- the options determining how the symbolic links should be handled- Throws:
IOException- in case of IO errorUnsupportedOperationException- when the Posix permissions are not supported by filesystemSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
toString
-
hashCode
-
equals
-
normalize
Returns aTruffleFilewith removed redundant name elements in it's path.- Returns:
- the normalized
TruffleFile - Since:
- 19.0
-
relativize
Creates aTruffleFilewith a relative path between thisTruffleFileand a givenTruffleFile.Relativization is the inverse of
resolution. Relativization constructs aTruffleFilewith relative path that whenresolvedagainst thisTruffleFileyields aTruffleFilelocating the same file as givenTruffleFile. A relative path cannot be constructed if only one of theTruffleFiles isabsolute.- Parameters:
other- theTruffleFileto relativize against thisTruffleFile- Returns:
- the
TruffleFilewith relative path between this andotherTruffleFiles - Throws:
IllegalArgumentException- whenothercannot be relativized against thisTruffleFile- Since:
- 19.0
-
startsWith
Tests if thisTruffleFilepath starts with the given path. The pathfoo/barstarts withfooandfoo/barbut does not start withf.- Parameters:
other- the path- Returns:
trueif thisTruffleFilepath starts with given path- Throws:
IllegalArgumentException- if the path cannot be parsed.- Since:
- 19.0
-
startsWith
Tests if thisTruffleFilepath starts with the givenTruffleFilepath. The pathfoo/barstarts withfooandfoo/barbut does not start withf.- Parameters:
other- theTruffleFile- Returns:
trueif thisTruffleFilepath starts with givenTruffleFilepath- Since:
- 19.0
-
endsWith
Tests if thisTruffleFilepath ends with the given path. The pathfoo/barends withbarandfoo/barbut does not end withr.- Parameters:
other- the path- Returns:
trueif thisTruffleFilepath ends with given path- Throws:
IllegalArgumentException- if the path cannot be parsed.- Since:
- 19.0
-
endsWith
Tests if thisTruffleFilepath ends with the givenTruffleFilepath. The pathfoo/barends withbarandfoo/barbut does not end withr.- Parameters:
other- theTruffleFile- Returns:
trueif thisTruffleFilepath ends with givenTruffleFilepath- Since:
- 19.0
-
createLink
Creates a new link to an existing target (optional operation).- Parameters:
target- the existing file to link- Throws:
FileAlreadyExistsException- if the file or directory already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if theFileSystemimplementation does not support linksSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
createSymbolicLink
Creates a symbolic link to a target (optional operation).- Parameters:
target- the target of the symbolic linkattrs- the optional attributes to set atomically when creating the symbolic link- Throws:
FileAlreadyExistsException- if the file or directory already exists on given pathIOException- in case of IO errorUnsupportedOperationException- if theFileSystemimplementation does not support symbolic links or the attributes contain an attribute which cannot be set atomicallySecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
readSymbolicLink
Reads the target of a symbolic link.- Returns:
- the
TruffleFilerepresenting the target of the symbolic link - Throws:
NotLinkException- if theTruffleFileis not a symbolic linkIOException- in case of IO errorUnsupportedOperationException- if theFileSystemimplementation does not support symbolic linksSecurityException- if theFileSystemdenied the operation- Since:
- 20.3
-
getOwner
Returns the owner of the file.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the file owner
- Throws:
IOException- in case of IO errorUnsupportedOperationException- if theFileSystemimplementation does not support owner attributeSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getGroup
Returns the group owner of the file.- Parameters:
options- the options determining how the symbolic links should be handled- Returns:
- the file owner
- Throws:
IOException- in case of IO errorUnsupportedOperationException- if theFileSystemimplementation does not support group owner attributeSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
newDirectoryStream
Opens a directory, returning aDirectoryStreamto iterate over all entries in the directory.The
TruffleFiles returned by the directory stream'siteratorare created as if byresolvingthe name of the directory entry against thisTruffleFile.In most cases, the returned
DirectoryStreamshould be closed using try-with-resources construct. When the stream must keep being opened for the lifetime of a context it should beregisteredfor automatic close on context dispose. When not using the try-with-resources construct, then the directory stream'sclosemethod should be called after iteration is completed.The code which iterates over all files can use simpler
list()method.- Returns:
- a new opened
DirectoryStreamobject - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
visit
public void visit(FileVisitor<TruffleFile> visitor, int maxDepth, FileVisitOption... options) throws IOException Visits thisTruffleFilefile tree.This method walks a file tree rooted at this
TruffleFile. The file tree traversal is depth-first. The appropriate method on giveFileVisitoris invoked for each met file. File tree traversal completes when all accessible files in the tree have been visited, aFileVisitorvisit method returns aFileVisitResult.TERMINATEor aFileVisitormethod terminates due to an uncaught exception.For each file encountered this method attempts to read its
BasicFileAttributes. If the file is not a directory then thevisitFilemethod is invoked with the file attributes. If the file attributes cannot be read, due to an I/O exception, then thevisitFileFailedmethod is invoked with the I/O exception.Where the file is a directory, and the directory could not be opened, then the
visitFileFailedmethod is invoked with the I/O exception, after which, the file tree walk continues, by default, at the next sibling of the directory.Where the directory is opened successfully, then the entries in the directory, and their descendants are visited. When all entries have been visited, or an I/O error occurs during iteration of the directory, then the directory is closed and the visitor's
postVisitDirectorymethod is invoked. The file tree walk then continues, by default, at the next sibling of the directory.By default, symbolic links are not automatically followed by this method. If the
optionsparameter contains theFOLLOW_LINKSoption then symbolic links are followed.The
maxDepthparameter is the maximum number of levels of directories to visit. A value of0means that only the starting file is visited. ThevisitFilemethod is invoked for all files, including directories, encountered atmaxDepth, unless the basic file attributes cannot be read, in which case thevisitFileFailedmethod is invoked.- Parameters:
visitor- theFileVisitorto invoke for each filemaxDepth- the maximum number of directory levels to visit,MAX_VALUEmay be used to indicate that all levels should be visited.options- the options configuring the file tree traversal- Throws:
IllegalArgumentException- if themaxDepthparameter is negativeIOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
copy
Copies the file. When the file is a directory the copy creates an empty directory in the target location, the directory entries are not copied. This method can be used with thevisitmethod to copy the whole sub-tree.- Parameters:
target- the path of a target fileoptions- the options specifying how the copy should be performed, seeStandardCopyOption- Throws:
UnsupportedOperationException- ifoptionscontains unsupported optionFileAlreadyExistsException- if the target path already exists and theoptionsdon't containStandardCopyOption.REPLACE_EXISTINGoptionDirectoryNotEmptyException- if theoptionscontainStandardCopyOption.REPLACE_EXISTINGbut thetargetis a non empty directoryIOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
getMimeType
Deprecated.usedetectMimeType()Returns thefileMIME type.- Returns:
- the MIME type or
nullif the MIME type is not recognized - Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
detectMimeType
Detects thefileMIME type.- Returns:
- the MIME type or
nullif the MIME type is not recognized - Throws:
SecurityException- if theFileSystemdenied the operation- Since:
- 22.2
-
isSameFile
Tests if this and the givenTruffleFilerefer to the same physical file. If bothTruffleFileobjects areequalthen this method returnstruewithout any checks. If theTruffleFiles have different filesystems then this method returnsfalse. Otherwise, this method checks if bothTruffleFiles refer to the same physical file. Depending on theFileSystemimplementation it may require to read the files attributes. This implies:- Public and Internal files with disabled IO are never the same.
- Public and Internal files with allowed IO are potentially the same.
- Files created by different languages are potentially the same.
- Files created during the Context pre-initialization and files created during Context execution are potentially the same.
- Parameters:
other- the otherTruffleFile- Returns:
trueif this and the givenTruffleFilerefer to the same physical file- Throws:
IOException- in case of IO errorSecurityException- if theFileSystemdenied the operation- Since:
- 20.2.0
-
getAttribute
public <T> T getAttribute(TruffleFile.AttributeDescriptor<T> attribute, LinkOption... linkOptions) throws IOException Reads a single file's attribute.- Parameters:
attribute- the attribute to readlinkOptions- the options determining how the symbolic links should be handled- Returns:
- the attribute value
- Throws:
IOException- in case of IO errorUnsupportedOperationException- when the filesystem does not support required attribute.SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
setAttribute
public <T> void setAttribute(TruffleFile.AttributeDescriptor<T> attribute, T value, LinkOption... linkOptions) throws IOException Sets a single file's attribute.- Parameters:
attribute- the attribute to setvalue- the attribute valuelinkOptions- the options determining how the symbolic links should be handled- Throws:
IOException- in case of IO errorUnsupportedOperationException- when the filesystem does not support given attributeIllegalArgumentException- when the attribute value has an inappropriate valueSecurityException- if theFileSystemdenied the operation- Since:
- 19.1.0
-
getAttributes
public TruffleFile.Attributes getAttributes(Collection<? extends TruffleFile.AttributeDescriptor<?>> attributes, LinkOption... linkOptions) throws IOException Reads file's attributes as a bulk operation.- Parameters:
attributes- the attributes to readlinkOptions- the options determining how the symbolic links should be handled- Returns:
- the
attributes view - Throws:
IllegalArgumentException- when no attributes are givenIOException- in case of IO errorUnsupportedOperationException- when the filesystem does not support some of the required attributes.SecurityException- if theFileSystemdenied the operation- Since:
- 19.0
-
detectMimeType()