Class FileSystem

java.lang.Object
net.bytebuddy.utility.FileSystem
Direct Known Subclasses:
FileSystem.ForLegacyVm, FileSystem.ForNio2CapableVm

public abstract class FileSystem extends Object
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 Classes
    Modifier and Type
    Class
    Description
    protected static class 
    A file system representation for a VM that does not support NIO2.
    protected static class 
    A file system representation for a VM that does support NIO2.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    copy(File source, File target)
    Copies a file.
    private static <T> T
    A proxy for java.security.AccessController#doPrivileged that is activated if available.
    static FileSystem
    Returns the FileSystem instance to use.
    void
    link(File source, File target)
    Links a file as a hard-link.
    abstract void
    move(File source, File target)
    Moves a file.
    static File
    validated(File folder, File target)
    Validates that a target file is contained within a folder once both paths are canonicalized.
    static String
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileSystem

      public FileSystem()
  • Method Details

    • getInstance

      @Enhance("INSTANCE") public static FileSystem getInstance()
      Returns the FileSystem instance to use.
      Returns:
      The FileSystem instance to use.
    • validated

      public static String validated(String name)
      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 crafted this_class constant pool entry.
      Parameters:
      name - The entry name to validate, using / as a separator.
      Returns:
      The supplied entry name.
    • validated

      public static File validated(File folder, File target) throws IOException
      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

      @Enhance private static <T> T doPrivileged(PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that 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

      public abstract void copy(File source, File target) throws IOException
      Copies a file.
      Parameters:
      source - The source file.
      target - The target file.
      Throws:
      IOException - If an I/O exception occurs.
    • link

      public void link(File source, File target) throws IOException
      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

      public abstract void move(File source, File target) throws IOException
      Moves a file.
      Parameters:
      source - The source file.
      target - The target file.
      Throws:
      IOException - If an I/O exception occurs.