Class FileUtils

java.lang.Object
io.github.syst3ms.skriptparser.util.FileUtils

public class FileUtils extends Object
Utility functions for file parsing
  • Field Details

    • LEADING_WHITESPACE_PATTERN

      public static final Pattern LEADING_WHITESPACE_PATTERN
    • MULTILINE_SYNTAX_TOKEN

      public static final String MULTILINE_SYNTAX_TOKEN
      See Also:
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • readAllLines

      public static List<String> readAllLines(Path filePath) throws IOException
      Parses a file and returns a list containing all of its lines.

      This parser offers the possibility to stretch out code across multiple lines by simply adding a single backslash before a line break to indicate to the parser that it should be considered as a single line. For example :

          set {large_list::*} to "one long string", \
                                 "a second long string", \
                                 "yet another long string" \
                                 "an even longer string which would make reading very awkward otherwise", \
                                 "nearing the end of the list" and \
                                 "the end of the list"
      
      This text will be interpreted as a single long line with all the strings back to back. The actual indentation before each additional line doesn't matter, all that matters is that it stays consistent.
      Parameters:
      filePath - the file to parse
      Returns:
      the lines of the file
      Throws:
      IOException - if the file can't be read
    • getIndentationLevel

      public static int getIndentationLevel(String line, boolean countAllSpaces)
      Counts the number of indents (a single tab or 4 spaces) at the beginning of a line, or alternatively just counts the amount of spaces at the beginning of a line (with a tab counting as 4 regular spaces).
      Parameters:
      line - the line
      countAllSpaces - if true, the method will count each space separately rather than in groups of 4
      Returns:
      the indentation level
    • removeExtension

      public static String removeExtension(String s)
    • loadClasses

      public static void loadClasses(File jarFile, String rootPackage, String... subPackages) throws IOException
      Loads all classes of selected packages of the provided JAR file.
      Parameters:
      jarFile - the JAR file
      rootPackage - a root package
      subPackages - a list of all subpackages of the root package, in which classes will be loaded
      Throws:
      IOException - if an I/O error has occurred
    • loadClasses

      public static void loadClasses(Path directory, String rootPackage, String... subPackages) throws IOException
      Loads all classes of selected packages of the skript-parser JAR.
      Parameters:
      directory - the directory in which the root package is contained
      rootPackage - a root package
      subPackages - a list of all subpackages of the root package, in which classes will be leadied
      Throws:
      IOException - if an I/O error has occurred
    • getJarFile

      public static File getJarFile(Class<?> cla) throws URISyntaxException
      Retrieves the JAR file containing the given Class. Passing down the current class is recommended.
      Parameters:
      cla - the class
      Returns:
      the JAR file containing the class
      Throws:
      URISyntaxException