Class IOUtil

java.lang.Object
es.urjc.etsii.grafo.util.IOUtil

public class IOUtil extends Object
Util methods for managing input/output
  • Constructor Details

    • IOUtil

      public IOUtil()
  • Method Details

    • createFolder

      public static void createFolder(String path)
      Create folder if not exists, recursively
      Parameters:
      path - a String object.
    • checkExists

      public static String checkExists(String path)
      Verify that the given path exists
      Parameters:
      path - path to check
    • checkIsFolder

      public static void checkIsFolder(String path)
      Check that the given path is a folder
      Parameters:
      path - path to check
    • isJAR

      public static boolean isJAR(Class<?> c)
      Check if the given class is in a JAR file
      Parameters:
      c - class to check
      Returns:
      true if inside a JAR, false otherwise
    • getInputStreamForIrace

      public static InputStream getInputStreamForIrace(String s, boolean isJar) throws IOException
      Get input stream for the given path
      Parameters:
      s - path to resource
      isJar - true if the resource is inside a JAR file, false otherwise
      Returns:
      InputStream to the resource given as a parameter
      Throws:
      IOException - if anything goes wrong
    • extractResource

      public static void extractResource(String path, String target, boolean isJar, boolean autodelete)
      Get input stream for the given path
      Parameters:
      path - path to resource
      target - where to copy the resource
      isJar - true if the resource is inside a JAR file, false otherwise
    • markAsExecutable

      public static void markAsExecutable(String s)
      Mark a file as executable
      Parameters:
      s - path to file as string
    • copyWithSubstitutions

      public static void copyWithSubstitutions(InputStream origin, Path target, Map<String,String> substitutions) throws IOException
      Replace substitutions in the given input stream
      Parameters:
      origin - input stream where the data is read from
      target - where should data be written to
      substitutions - list of substitutions to do while copying the adta
      Throws:
      IOException - if anything goes wrong
    • isNormalFile

      public static boolean isNormalFile(Path p)
      Returns true if it is a file (not a folder) and the file is not hidden and its name does not start with a dot.
      Parameters:
      p - Path to check
      Returns:
      true if passes all checks, false otherwise
    • iterate

      public static List<String> iterate(Path path)
      List all normal files under a given path. Ignores hidden files. Recursively explores folders.
      Parameters:
      path - Path to iterate
      Returns:
      list of paths to normal files
    • iterate

      public static List<String> iterate(String path)
      List all normal files under a given path. Ignores hidden files. Recursively explores folders.
      Parameters:
      path - Path to iterate
      Returns:
      list of paths to normal files
    • expandIfContainer

      public static Stream<String> expandIfContainer(Path p)
      Check if the file represented by the given path is a compressed file, and if so, return list of files inside the archive.
      Parameters:
      p - Path to check
      Returns:
      list of files inside the archive, or the path itself if it is not a compressed file
    • getInputStream

      public static InputStream getInputStream(String path) throws IOException
      Throws:
      IOException
    • relativizePath

      public static String relativizePath(String path)