Truffle files.
| Modifier and Type | Method and Description |
|---|---|
| public static FileSystem | allowLanguageHomeAccess(FileSystem fileSystem)
Decorates the given |
| public void | checkAccess(Path
the path to the file to check path, Set<? extends AccessMode> the access modes to check, possibly empty to check existence only. modes, LinkOption... options determining how the symbolic links should be handled linkOptions)Checks existence and accessibility of a file. |
| public default void | copy(Path
the path to file to copy source, Path the path to the target file target, CopyOption... the options specifying how the copy should be performed, see
options)StandardCopyOptionCopies source file to target file. |
| public void | createDirectory(Path
the directory to create dir, FileAttribute<?>... the optional attributes to set atomically when creating the directory attrs)Creates a directory. |
| public default void | createLink(Path
the path to link to create link, Path the path to existing file existing)Creates a new link for an existing file. |
| public default void | createSymbolicLink(Path
the path to symbolic link to create link, Path the target path of the symbolic link target, FileAttribute<?>... the optional attributes to set atomically when creating the new symbolic link attrs)Creates a new symbolic link. |
| public void | |
| public default Charset | Returns: the file encoding ornull if the file encoding is not detected or the
filesystem does not support file encoding detectionthe file to find an file encoding for path)Returns an file encoding for given path. |
| public default String | Returns: the MIME type ornull if the MIME type is not recognized or the
filesystem does not support MIME type detectionthe file to find a MIME type for path)Returns a MIME type for given path. |
| public default String | Returns: the path separatorReturns the path separator used to separate filenames in a path list. |
| public default String | Returns: the name separatorReturns the name separator used to separate names in a path string. |
| public default Path | |
| public default boolean | Returns: true if the given paths refer to the same physical filethe path to the file path1, Path the other path path2, LinkOption... the options determining how the symbolic links should be handled options)Tests if the given paths refer to the same physical file. |
| public default void | move(Path
the path to file to move source, Path the path to the target file target, CopyOption... the options specifying how the move should be performed, see
options)StandardCopyOptionMoves (renames) source file to target file. |
| public SeekableByteChannel | Returns: the createdSeekableByteChannelthe path to the file to open path, Set<? extends OpenOption> the options specifying how the file should be opened options, FileAttribute<?>... the optional attributes to set atomically when creating the new file attrs)Opens or creates a file returning a |
| public static FileSystem | |
| public DirectoryStream | Returns: the newDirectoryStreamthe path to the directory to iterate entries for dir, DirectoryStream.the filter filterReturns directory entries. |
| public static FileSystem | newFileSystem(FileSystem fileSystem)
Creates a |
| public static FileSystem | newReadOnlyFileSystem(FileSystem fileSystem)
Decorates the given |
| public Path | |
| public Path | |
| public Map | Returns: theMap containing the file attributes. The map's keys are attribute names,
map's values are the attribute values. The map may contain a subset of required
attributes in case when the FileSystem does not support some of the required
attributes.the path to file to read attributes for path, String the attributes to read. The attributes, LinkOption... attributes parameter has the form:
[view-name:]attribute-list. The optional view-name corresponds to
FileAttributeView#name() and determines the set of attributes, the default
value is "basic". The attribute-list is a comma separated list of
attributes. If the attribute-list contains '*' then all the
attributes from given view are read.the options determining how the symbolic links should be handled options)Reads a file's attributes as a bulk operation. |
| public default Path | Returns: thePath representing the symbolic link targetthe path to symbolic link to read link)Reads the target of the symbolic link. |
| public default void | setAttribute(Path
the path to file to set an attribute to path, String the attribute to set. The attribute, Object attribute parameter has the form:
[view-name:]attribute-name. The optional view-name corresponds to
FileAttributeView#name() and determines the set of attributes, the default
value is "basic". The attribute-name is a name of an attribute.the attribute value value, LinkOption... the options determining how the symbolic links should be handled options)Sets a file's attribute. |
| public default void | setCurrentWorkingDirectory(Path
the new current working directory currentWorkingDirectory)Sets the current working directory. |
| public Path | Returns: an absolutePaththe path to resolve, may be a non normalized path path)Resolves given path to an absolute path. |
| public Path | Returns: an absolute canonical paththe path to resolve, may be a non normalized path path, LinkOption... options determining how the symbolic links should be handled linkOptions)Returns the real (canonical) path of an existing file. |
| allowLanguageHomeAccess | back to summary |
|---|---|
| public static FileSystem allowLanguageHomeAccess(FileSystem fileSystem) Decorates the given
| |
| checkAccess | back to summary |
|---|---|
| public void checkAccess(Path path, Set<? extends AccessMode> modes, LinkOption... linkOptions) throws IOException Checks existence and accessibility of a file.
| |
| copy | back to summary |
|---|---|
| public default void copy(Path source, Path target, CopyOption... options) throws IOException Copies source file to target file.
| |
| createDirectory | back to summary |
|---|---|
| public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException Creates a directory.
| |
| createLink | back to summary |
|---|---|
| public default void createLink(Path link, Path existing) throws IOException Creates a new link for an existing file.
| |
| createSymbolicLink | back to summary |
|---|---|
| public default void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException Creates a new symbolic link.
| |
| delete | back to summary |
|---|---|
| public void delete(Path path) throws IOException Deletes a file.
| |
| getEncoding | back to summary |
|---|---|
| public default Charset getEncoding(Path path) Returns an file encoding for given path. An optional operation for
| |
| getMimeType | back to summary |
|---|---|
| public default String getMimeType(Path path) Returns a MIME type for given path. An optional operation for
| |
| getPathSeparator | back to summary |
|---|---|
| public default String getPathSeparator() Returns the path separator used to separate filenames in a path list. On UNIX the path
separator is
| |
| getSeparator | back to summary |
|---|---|
| public default String getSeparator() Returns the name separator used to separate names in a path string. The separator is used
when creating path strings by invoking the
| |
| getTempDirectory | back to summary |
|---|---|
| public default Path getTempDirectory() Returns the default temporary directory.
| |
| isSameFile | back to summary |
|---|---|
| public default boolean isSameFile(Path path1, Path path2, LinkOption... options) throws IOException Tests if the given paths refer to the same physical file.
The default implementation firstly converts the paths into absolute paths. If the absolute
paths are equal it returns
| |
| move | back to summary |
|---|---|
| public default void move(Path source, Path target, CopyOption... options) throws IOException Moves (renames) source file to target file.
| |
| newByteChannel | back to summary |
|---|---|
| public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException Opens or creates a file returning a
| |
| newDefaultFileSystem | back to summary |
|---|---|
| public static FileSystem newDefaultFileSystem() Creates a
For an untrusted code execution, access to the host filesystem should be prevented either by
using
The following example shows a
class TracingFileSystem implements FileSystem {
private static final Logger LOGGER = Logger.getLogger(TracingFileSystem.class.getName());
private final FileSystem delegate;
TracingFileSystem() {
this.delegate = FileSystem.newDefaultFileSystem();
}
@Override
public Path parsePath(String path) {
return delegate.parsePath(path);
}
@Override
public Path parsePath(URI uri) {
return delegate.parsePath(uri);
}
@Override
public SeekableByteChannel newByteChannel(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs) throws IOException {
boolean success = false;
try {
SeekableByteChannel result = delegate.newByteChannel(path, options, attrs);
success = true;
return result;
} finally {
trace("newByteChannel", path, success);
}
}
...
private void trace(String operation, Path path, boolean success) {
LOGGER.log(Level.FINE, "The {0} request for the path {1} {2}.",new Object[] {
operation, path, success ? "was successful" : "failed"
});
}
}
| |
| newDirectoryStream | back to summary |
|---|---|
| public DirectoryStream Returns directory entries.
| |
| newFileSystem | back to summary |
|---|---|
| public static FileSystem newFileSystem(FileSystem fileSystem) Creates a
The following example shows how to configure
Path zipFile = Paths.get("filesystem.zip");
try (java.nio.file.FileSystem nioFs = FileSystems.newFileSystem(zipFile)) {
IOAccess ioAccess = IOAccess.newBuilder().fileSystem(FileSystem.newFileSystem(nioFs)).build();
try (Context ctx = Context.newBuilder().allowIO(ioAccess).build()) {
Value result = ctx.eval("js", "load('scripts/app.sh'); execute()");
}
}
| |
| newReadOnlyFileSystem | back to summary |
|---|---|
| public static FileSystem newReadOnlyFileSystem(FileSystem fileSystem) Decorates the given
| |
| parsePath | back to summary |
|---|---|
| public Path parsePath(URI uri) Parses a path from an
| |
| parsePath | back to summary |
|---|---|
| public Path parsePath(String path) Parses a path from a
| |
| readAttributes | back to summary |
|---|---|
| public Map Reads a file's attributes as a bulk operation.
| |
| readSymbolicLink | back to summary |
|---|---|
| public default Path readSymbolicLink(Path link) throws IOException Reads the target of the symbolic link.
| |
| setAttribute | back to summary |
|---|---|
| public default void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException Sets a file's attribute.
| |
| setCurrentWorkingDirectory | back to summary |
|---|---|
| public default void setCurrentWorkingDirectory(Path currentWorkingDirectory) Sets the current working directory. The current working directory is used to resolve non
absolute paths in
| |
| toAbsolutePath | back to summary |
|---|---|
| public Path toAbsolutePath(Path path) Resolves given path to an absolute path.
| |
| toRealPath | back to summary |
|---|---|
| public Path toRealPath(Path path, LinkOption... linkOptions) throws IOException Returns the real (canonical) path of an existing file.
| |