Package net.bytebuddy.utility
Class FileSystem
java.lang.Object
net.bytebuddy.utility.FileSystem
- Direct Known Subclasses:
FileSystem.ForLegacyVm,FileSystem.ForNio2CapableVm
A dispatcher to interact with the file system. If NIO2 is available, the API is used. Otherwise, byte streams are used.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA file system representation for a VM that does not support NIO2.protected static classA file system representation for a VM that does support NIO2. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidCopies a file.private static <T> TdoPrivileged(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.static FileSystemReturns theFileSysteminstance to use.voidLinks a file as a hard-link.abstract voidMoves a file.static FileValidates that a target file is contained within a folder once both paths are canonicalized.static StringValidates that a/-separated entry name does not escape the root directory it is resolved against when it is written to a folder or extracted from an archive.
-
Constructor Details
-
FileSystem
public FileSystem()
-
-
Method Details
-
getInstance
Returns theFileSysteminstance to use.- Returns:
- The
FileSysteminstance to use.
-
validated
Validates that a/-separated entry name does not escape the root directory it is resolved against when it is written to a folder or extracted from an archive. This guards against a path traversal from a type name that contains traversal segments, for example from a craftedthis_classconstant pool entry.- Parameters:
name- The entry name to validate, using/as a separator.- Returns:
- The supplied entry name.
-
validated
Validates that a target file is contained within a folder once both paths are canonicalized. This guards against a path traversal from a type or entry name that contains traversal segments when a file is written to the file system.- Parameters:
folder- The folder that the target file must be contained within.target- The target file to validate.- Returns:
- The supplied target file.
- Throws:
IOException- If the canonical path of either file cannot be resolved.
-
doPrivileged
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
copy
Copies a file.- Parameters:
source- The source file.target- The target file.- Throws:
IOException- If an I/O exception occurs.
-
link
Links a file as a hard-link. If linking is not supported, a copy is made.- Parameters:
source- The source file.target- The target file.- Throws:
IOException- If an I/O exception occurs.
-
move
Moves a file.- Parameters:
source- The source file.target- The target file.- Throws:
IOException- If an I/O exception occurs.
-