Package es.urjc.etsii.grafo.util
Class IOUtil
java.lang.Object
es.urjc.etsii.grafo.util.IOUtil
Util methods for managing input/output
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
checkExists
(String path) Verify that the given path existsstatic void
checkIsFolder
(String path) Check that the given path is a folderstatic void
copyWithSubstitutions
(InputStream origin, Path target, Map<String, String> substitutions) Replace substitutions in the given input streamstatic void
createFolder
(String path) Create folder if not exists, recursivelyCheck if the file represented by the given path is a compressed file, and if so, return list of files inside the archive.static void
extractResource
(String path, String target, boolean isJar, boolean autodelete) Get input stream for the given pathstatic InputStream
getInputStream
(String path) static InputStream
getInputStreamForIrace
(String s, boolean isJar) Get input stream for the given pathstatic boolean
Check if the given class is in a JAR filestatic 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.List all normal files under a given path.List all normal files under a given path.static void
Mark a file as executablestatic String
relativizePath
(String path)
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
createFolder
Create folder if not exists, recursively- Parameters:
path
- aString
object.
-
checkExists
Verify that the given path exists- Parameters:
path
- path to check
-
checkIsFolder
Check that the given path is a folder- Parameters:
path
- path to check
-
isJAR
Check if the given class is in a JAR file- Parameters:
c
- class to check- Returns:
- true if inside a JAR, false otherwise
-
getInputStreamForIrace
Get input stream for the given path- Parameters:
s
- path to resourceisJar
- 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
Get input stream for the given path- Parameters:
path
- path to resourcetarget
- where to copy the resourceisJar
- true if the resource is inside a JAR file, false otherwise
-
markAsExecutable
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 IOExceptionReplace substitutions in the given input stream- Parameters:
origin
- input stream where the data is read fromtarget
- where should data be written tosubstitutions
- list of substitutions to do while copying the adta- Throws:
IOException
- if anything goes wrong
-
isNormalFile
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
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
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
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
- Throws:
IOException
-
relativizePath
-