Package be.panako.util
Class FileUtils
java.lang.Object
be.panako.util.FileUtils
An utility class for file interaction.
- 
Nested Class SummaryNested Classes
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidappendFile(String contents, String name) Appends a string to a file on disk.static StringReturns the filename without path and without extension.static StringJoins path elements using the systems path separator.static voidcopyFileFromJar(String source, String target) Copy a file from a jar.static voidCopy from source to target.static booleancreateLock(String fileName) static booleanChecks if a file exists.static StringexpandHomeDir(String dir) static StringReturn the extension of a file.static intgetIdentifier(String resource) Returns an identifier for a resource.static StringgetLockFileName(String fileName) Return a list of files in directory that satisfy pattern.static booleanisDirectory(String inputFile) Tests whether the file denoted by this abstract pathname is a directory.static booleanisFileLocked(String fileName) static booleanCreates a directory and parent directories if needed.static StringReturns the path for a file.
 path("/home/user/random.jpg") == "/home/user"
 Uses the correct pathSeparator depending on the operating system.readColumnFromCSVData(List<String[]> data, int columnIndex, FileUtils.RowFilter filter) static StringReads the contents of a file.static StringreadFileFromJar(String path) Reads the contents of a file in a jar.static booleanRemoves a file from disk.static Stringstatic Stringstatic voidWrites a file to disk.
- 
Field Details- 
ACCEPT_ALL_ROWFILTER
 
- 
- 
Method Details- 
temporaryDirectory
- 
expandHomeDir
- 
isFileLocked
- 
createLock
- 
getLockFileName
- 
combineJoins path elements using the systems path separator. e.g. "/tmp" and "com.random.test.wav" combined together should yield /tmp/com.random.test.wav on UNIX.- Parameters:
- path- The path parts part.
- Returns:
- Each element from path joined by the systems path separator.
 
- 
runtimeDirectory- Returns:
- The path where the program is executed.
 
- 
writeFileWrites a file to disk. Uses the string contents as content. Failures are logged.- Parameters:
- contents- The contents of the file.
- name- The name of the file to create.
 
- 
appendFileAppends a string to a file on disk. Fails silently.- Parameters:
- contents- The contents of the file.
- name- The name of the file to create.
 
- 
readFileReads the contents of a file.- Parameters:
- name- the name of the file to read
- Returns:
- the contents of the file if successful, an empty string otherwise.
 
- 
readFileFromJarReads the contents of a file in a jar.- Parameters:
- path- the path to read e.g. /package/name/here/help.html
- Returns:
- the contents of the file when successful, an empty string otherwise.
 
- 
copyFileFromJarCopy a file from a jar.- Parameters:
- source- The path to read e.g. /package/name/here/help.html
- target- The target to save the file to.
 
- 
readColumnFromCSVDatapublic static List<String> readColumnFromCSVData(List<String[]> data, int columnIndex, FileUtils.RowFilter filter) 
- 
globReturn a list of files in directory that satisfy pattern. Pattern should be a valid regular expression not a 'unix glob pattern' so in stead of *.wavyou could use.*\.wavE.g. in a directory homewith the filescom.test.txt,blaat.wavandfoobar.wavthe pattern.*\.wavmatchesblaat.wavandfoobar.wav- Parameters:
- directory- A readable directory.
- pattern- A valid regular expression.
- recursive- A boolean defining if directories should be traversed recursively.
- Returns:
- a list of filenames matching the pattern for directory.
- Throws:
- Error- an error is thrown if the directory is not ... a directory.
- PatternSyntaxException- Unchecked exception thrown to indicate a syntax error in a regular-expression pattern.
 
- 
extensionReturn the extension of a file.- Parameters:
- fileName- the file to get the extension for
- Returns:
- the extension. E.g. TXT or JPEG.
 
- 
basenameReturns the filename without path and without extension.- Parameters:
- fileName- The name of the file.
- Returns:
- the file name without extension and path
 
- 
pathReturns the path for a file.
 path("/home/user/random.jpg") == "/home/user"
 Uses the correct pathSeparator depending on the operating system. On windows c:/com.test/ is not c:\com.test\- Parameters:
- fileName- The name of the file using correct path separators.
- Returns:
- The path of the file.
 
- 
existsChecks if a file exists.- Parameters:
- fileName- the name of the file to check.
- Returns:
- true if and only if the file or directory denoted by this abstract pathname exists; false otherwise
 
- 
mkdirsCreates a directory and parent directories if needed.- Parameters:
- path- the path of the directory to create
- Returns:
- true if the directory was created (possibly with parent directories) , false otherwise
 
- 
cpCopy from source to target.- Parameters:
- source- the source file.
- target- the target file.
 
- 
rmRemoves a file from disk.- Parameters:
- fileName- the file to remove
- Returns:
- true if and only if the file or directory is successfully deleted; false otherwise
 
- 
isDirectoryTests whether the file denoted by this abstract pathname is a directory.- Parameters:
- inputFile- A pathname string.
- Returns:
- true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise.
 
- 
getIdentifierReturns an identifier for a resource. It is either based on the hashCode of a string or on the name of the resource. If a resource is called e.g.1855.mp3, the number part is used as identifier.- Parameters:
- resource- The resource to get an identifier for.
- Returns:
- an identifier.
 
 
-