Package net.simplace.core.service
Class IOHelper
java.lang.Object
net.simplace.core.service.IOHelper
provides different helper methods for IO
- Author:
- Andreas Enders
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
helper class to check the operating system this Java VM runs in please keep the notes below as a pseudo-license http://stackoverflow.com/questions/228477/how-do-i-programmatically- determine-operating-system-in-java compare to http://svn.terracotta.org/svn /tc/dso/tags/2.6.4/code/base/common/src/com/tc/util/runtime/Os.java http:/ /www.docjar.com/html/api/org/apache/commons/lang/SystemUtils.java.html -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final void
addLineToFile
(File aFile, String aStringToAppend, int aMaxKBSizeOfFile) Constructs a FileWriter object given a File object.static URL
static File
chooseFile
(String aExtension) static String
static File
combineAndGZipFiles
(String aAbsolutePath, List<File> aFilesForPattern, int aHeaderLinesToInclude) static void
copyDirectory
(File aSourceDirectory, File aDestinationDirectory, boolean aCopySubFolders, boolean aOverwriteCopy) copies all contents of one folder to another one. use the last parameter to define, if you want to copy all subfolders including contentstatic final void
Copy a file and create the directory structure for the destination file if it doesnt already exist.static final void
Copies the content of the given directory to the given targetdirectory.static final void
copyFiles
(File aSourceDir, File aDesDir, FileFilter aFileFilter, boolean aShouldOverwrite) Copies the content of the given directory to the given targetdirectory.static final void
copyStream
(InputStream aInputStream, OutputStream aOutputStream) Copy data from an InputStream to an OutputStream.static final void
copyStream
(Reader aReader, Writer aWriter) Copy data from an Reader to an Writer.static final void
Create a directory including its parent directories if they dont already exist.static boolean
createLockFile
(File aDirectory) Locks the system.static final boolean
Deletes all the files in a directory including the sub directories files, if the given file is a directory and also the directory.static final boolean
Deletes all the files in a directory including the sub directories files, if the given file is a directory and also the directory.static final boolean
deleteDirContents
(File dir, boolean goOnOnError) Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself.static final boolean
deleteDirContents
(File aDir, String aExtension) Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself.It only deletes files with given extensionstatic final boolean
deleteDirContents
(File aDir, String aExtension, long aOlderThanMillis) Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself.static final boolean
deleteFile
(File aFile) Delete a file if it exists.static final void
deleteFiles
(File aFile) Deletes all the files in a directory including the sub directories files, if the given file is a directory. !!!static void
deleteFiles
(File aSourceDir, FileFilter aFileFilter) static final boolean
deleteFiles
(Collection<File> aFilesCollection) Deletes all the files in the given FilesCollection returning true if successfulstatic boolean
doesFileExist
(String aPath, boolean aSouldAcceptDirectories) static boolean
doesPatternFit
(String aFileName, String aPattern, boolean aIgnoreCase) static boolean
doesPatternFit
(String aFileName, List<String> aPatternList, boolean aIgnoreCase) static final String
encodedStringFromInputStream
(InputStream aInputStream) Returns the contents of a String from an InputStream in the UTF-8 encoded format.static final String
encodedStringFromInputStream
(InputStream aInputStream, String aEncoding) Returns the contents of a String from an InputStream in the given encoded format.static final void
fileFromInputStream
(File aFile, InputStream aInputStream) Copy data from an InputStream to a file.static final void
fileToOutputStream
(File aFile, OutputStream aOutputStream) Copy data from a file to an OututStream.static Collection<File>
fillFileCollection
(File aDirectory, boolean aIncludeDirectories, String aExtensionFilter) static Collection<File>
fillFileCollection
(File aDirectory, Collection<File> aFileCollection, boolean aIncludeDirectories) static Collection<File>
fillFileCollection
(File aDirectory, Collection<File> aFileCollection, String aExtensionFilter) static <T extends Number>
voidfillWithZero
(T[][] aValuesArray) getAllFileNamesInDirectory
(String aDirectory, String aExtension) static byte[]
getBytesFromFile
(File aFile) static final Collection<File>
getDirContents
(File aDir, String aExtension, long aOlderThanMillis) getDirectoriesOnly
(File aDir, boolean aRecursive) static File
getFile
(Collection<File> aFileCollection, String aFileName) static final String
getFileExtension
(String aFullFileName) static final String
getFilename
(String aFullFileName) static String
getFilenameWithExtension
(String aFullFileName) getFilesForPattern
(File aFile, String aRegexpPattern, boolean aShouldIncludeSubdirs, boolean aIgnoreCase) static long
getFileSize
(File aFile, boolean aRecursive) Returns the size of the given file.static String
getFileSizeString
(long aByte) getFilesWithExtension
(File aDirectory, String aExtension) getFilesWithExtension
(File aDirectory, String aExtension, boolean aIncludeSubDirs) static String
static InputStream
getInputStream
(File aFile) static final String
If add/remove characters also change returnValidPath/isValidFilenamestatic String
static final OutputStream
getOutputStream
(File aFile) Creates an OutputStream using the special needs of samba shares and gz.static String
getRelativePath
(File aFromDir, File aToFileOrDir) static String
getTemporaryExecutionFilePath
(String aFilePath) static boolean
static final boolean
static boolean
isInDirectory
(File aFile, File aDirectory) static final boolean
isValidFilename
(String aFilename) You should only give the filename without path!!!static final boolean
isXMLFileExtension
(String aExtension) static final void
Copy a file and create the directory structure for the destination file if it doesnt already exist.static final String
platformDefaultToUTF8
(String aString) Turns a String which was created using the platform standard encoding to an String which is encoded using UTF-8 encoding.static String[][]
readCSVtoArray
(File aFile, String aDivider, boolean aIncludeHeader) static String[][]
readCSVtoArray
(InputStream aInputStream, String aDivider, boolean aIncludeHeader) static final String
Reads the last line of a File and returns it in a String.static final String
Reads the last line of a File and returns it in a String.static String[][]
readFileToArray
(File aFileData, String aDivider, Integer[] aLinesToRead) Reads a file to an arraystatic String[][]
readFileToArray
(File aFileData, String aDivider, Integer[] aLinesToRead, Integer aSkipHeaderLines) Reads a file to an arraystatic final String
readFirstCharsOfFile
(File aFile, int aNumberOfChars) Reads the first chars of a File and returns it in a String.static final String
readLastLineOfFile
(File aFile) Reads the last line of a File and returns it in a String.readLinesOfFile
(File aFile) Reads the last line of a File and returns it in a String.readLinesOfFile
(File aFile, String aEncoding, Integer[] aLinesToRead) Reads the last line of a File and returns it in a String.readLinesOfStream
(InputStream aInputStream, Integer[] aLinesToRead, String encoding) Reads the last line of a File and returns it in a String.static final Object
readObjectFromFile
(File aSourceFile) static String[][]
readStreamToArray
(InputStream aInputStream, String aDivider, String aEncoding) Reads the last line of a File and returns it in a String.static Object
resizeArray
(Object oldArray, int newSize) Reallocates an array with a new size, and copies the contents of the old array to the new array.static final String
returnValidFilename
(String aUncheckedFilename) Replaces all letters that are maybe not supported by system for using in filename.static final String
returnValidPath
(String aUncheckedFilename) Replaces all letters that are maybe not supported by system for using in filename.static void
setAuthentication
(String aUsername, String aPassword) static final StringBuffer
stringBufferFromInputStream
(InputStream aInputStream) Read the contents of a String from an InputStream.static final StringBuffer
stringBufferFromInputStream
(InputStream aInputStream, String aEncoding) Read the contents of a String from an InputStream.static final void
stringBufferToOutputStream
(StringBuffer aStringBuffer, OutputStream aOutputStream) Write the contents of a StringBuffer to an OutputStream.static final String
stringFromInputStream
(InputStream aInputStream) Read the contents of a String from an InputStream.static final String
stringFromInputStream
(InputStream aInputStream, String aEncoding) Read the contents of a String from an InputStream.static final void
stringToFile
(String aString, File aFile) Write the contents of a String to a File in platform standard encoding.static final void
stringToFile
(String aString, File aFile, String aEncoding) Write the contents of a String to a File in the given encoding.static final void
stringToOutputStream
(String aString, OutputStream aOutputStream) Write the contents of a String to an OutputStream.static final void
stringToOutputStream
(String aString, OutputStream aOutputStream, String aEncoding) Write the contents of a String to an OutputStream in the given encoding.static final void
stringToOutputStreamAndClose
(String aString, OutputStream aOutputStream) Write the contents of a String to an OutputStream.static final void
stringToOutputStreamAndClose
(String aString, OutputStream aOutputStream, String aEncoding) Write the contents of a String to an OutputStream in the given encoding.static final String
UTF8ToPlatformDefault
(String aString) Turns a String which was created using the UTF-8 encoding to an String which is encoded using platform standard encoding.static <T> void
writeArrayToFile
(T[][] aSumOfCutValues, File aFile, String aSeperator) static final void
writeLinesOfFile
(Vector<String> aLinesVector, File aFile) Reads the last line of a File and returns it in a String.static void
writeObjectToFile
(File aDestFile, Object aObject) Returns the name part of a given full file name (without directory pathes).
-
Field Details
-
PATH_BACK_PATTERN
For the replacement of the '..' in paths
-
-
Method Details
-
getFileExtension
- Parameters:
aFullFileName
-- Returns:
- the extension of a given full File name.
-
getFilename
- Parameters:
aFullFileName
-- Returns:
- the name part of a given full file name (without directory pathes).
-
getFilenameWithExtension
- Parameters:
aFullFileName
-- Returns:
- the name with extension of a given full file name (without directory pathes).
-
getAllFileNamesInDirectory
- Parameters:
aDirectory
-aExtension
-- Returns:
- all the file names with the given extension in a directory.
-
writeObjectToFile
public static void writeObjectToFile(File aDestFile, Object aObject) throws FileNotFoundException, IOException Returns the name part of a given full file name (without directory pathes).- Parameters:
aDestFile
-aObject
-- Throws:
FileNotFoundException
IOException
-
readObjectFromFile
public static final Object readObjectFromFile(File aSourceFile) throws FileNotFoundException, IOException, Exception - Parameters:
aSourceFile
-- Returns:
- the name part of a given full file name (without directory pathes).
- Throws:
FileNotFoundException
IOException
Exception
-
copyFiles
Copies the content of the given directory to the given targetdirectory.- Parameters:
aSourceDir
-aDesDir
-- Throws:
IOException
-
copyFiles
public static final void copyFiles(File aSourceDir, File aDesDir, FileFilter aFileFilter, boolean aShouldOverwrite) throws IOException Copies the content of the given directory to the given targetdirectory. Copies only files that match the given FileFilter.- Parameters:
aSourceDir
-aDesDir
-aFileFilter
-aShouldOverwrite
-- Throws:
IOException
-
copyDirectory
public static void copyDirectory(File aSourceDirectory, File aDestinationDirectory, boolean aCopySubFolders, boolean aOverwriteCopy) throws IOException copies all contents of one folder to another one. use the last parameter to define, if you want to copy all subfolders including content- Parameters:
aSourceDirectory
-aDestinationDirectory
-aCopySubFolders
-aOverwriteCopy
-- Throws:
IOException
-
copyFile
public static final void copyFile(File aSourceFile, File aDestFile, boolean aShouldOverwrite) throws FileNotFoundException, IOException Copy a file and create the directory structure for the destination file if it doesnt already exist. Overwrite the destination file if it already exists.- Parameters:
aSourceFile
-aDestFile
-aShouldOverwrite
-- Throws:
FileNotFoundException
- Thrown if the source file cannot be found.IOException
- Thrown if an error occurs while copying.
-
moveFile
public static final void moveFile(File aSourceFile, File aDestFile, boolean aShouldOverwrite) throws FileNotFoundException, IOException Copy a file and create the directory structure for the destination file if it doesnt already exist. Overwrite the destination file if it already exists.- Parameters:
aSourceFile
-aDestFile
-aShouldOverwrite
-- Throws:
FileNotFoundException
- Thrown if the source file cannot be found.IOException
- Thrown if an error occurs while copying.
-
addLineToFile
public static final void addLineToFile(File aFile, String aStringToAppend, int aMaxKBSizeOfFile) throws IOException Constructs a FileWriter object given a File object. String will be written to the end of the file.- Parameters:
aFile
- a File object to write to, if doesn't exist it will be created.aStringToAppend
- String that should be appended to the FileaMaxKBSizeOfFile
- max size of File- Throws:
IOException
- if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
-
readFirstCharsOfFile
Reads the first chars of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.aNumberOfChars
- iftrue
, then bytes will be written to the end of the file rather than the beginning- Returns:
- the first chars of a File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readLinesOfFile
public static final Vector<String> readLinesOfFile(File aFile, String aEncoding, Integer[] aLinesToRead) throws IOException Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.aEncoding
- iftrue
, then bytes will be written to the end of the file rather than the beginningaLinesToRead
-- Returns:
- the last line of a File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readFile
Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.- Returns:
- the File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readFile
Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.aEncoding
- iftrue
, then bytes will be written to the end of the file rather than the beginning- Returns:
- the File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
getInputStream
- Parameters:
aFile
-- Returns:
- a File's
InputStream
- either from Zip, GZ, TarGZ, Resource or simply the file - Throws:
IOException
-
getOutputStream
Creates an OutputStream using the special needs of samba shares and gz.- Parameters:
aFile
-- Returns:
- the output stream to write to
- Throws:
IOException
-
readLinesOfFile
Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.- Returns:
- the last line of a File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readFileToArray
public static String[][] readFileToArray(File aFileData, String aDivider, Integer[] aLinesToRead, Integer aSkipHeaderLines) throws IOException Reads a file to an array- Parameters:
aFileData
- a File object to read from.aDivider
- iftrue
, then bytes will be written to the end of the file rather than the beginningaLinesToRead
-aSkipHeaderLines
-- Returns:
- Double array of file content
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readFileToArray
public static String[][] readFileToArray(File aFileData, String aDivider, Integer[] aLinesToRead) throws IOException Reads a file to an array- Parameters:
aFileData
- a File object to read from.aDivider
- iftrue
, then bytes will be written to the end of the file rather than the beginningaLinesToRead
-- Returns:
- Double array of file content
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readLinesOfStream
public static final Vector<String> readLinesOfStream(InputStream aInputStream, Integer[] aLinesToRead, String encoding) throws IOException Reads the last line of a File and returns it in a String.- Parameters:
aInputStream
- a File object to read from.aLinesToRead
-encoding
- iftrue
, then bytes will be written to the end of the file rather than the beginning- Returns:
- line vector of stream
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readStreamToArray
public static String[][] readStreamToArray(InputStream aInputStream, String aDivider, String aEncoding) throws IOException Reads the last line of a File and returns it in a String.- Parameters:
aInputStream
- a File object to read from.aDivider
- divider characteraEncoding
- iftrue
, then bytes will be written to the end of the file rather than the beginning- Returns:
- a stream to an array with encoding
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
writeLinesOfFile
public static final void writeLinesOfFile(Vector<String> aLinesVector, File aFile) throws IOException Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.aLinesVector
- iftrue
, then bytes will be written to the end of the file rather than the beginning- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
readLastLineOfFile
Reads the last line of a File and returns it in a String.- Parameters:
aFile
- a File object to read from.- Returns:
- the last line of a File and returns it in a String.
- Throws:
IOException
- if the file does not exist but cannot be created, or cannot be opened for any other reason
-
stringBufferFromInputStream
public static final StringBuffer stringBufferFromInputStream(InputStream aInputStream) throws IOException Read the contents of a String from an InputStream.- Parameters:
aInputStream
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
stringBufferFromInputStream
public static final StringBuffer stringBufferFromInputStream(InputStream aInputStream, String aEncoding) throws IOException Read the contents of a String from an InputStream.- Parameters:
aInputStream
-aEncoding
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
stringFromInputStream
Read the contents of a String from an InputStream.- Parameters:
aInputStream
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
stringFromInputStream
public static final String stringFromInputStream(InputStream aInputStream, String aEncoding) throws IOException Read the contents of a String from an InputStream.- Parameters:
aInputStream
-aEncoding
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
encodedStringFromInputStream
public static final String encodedStringFromInputStream(InputStream aInputStream, String aEncoding) throws IOException Returns the contents of a String from an InputStream in the given encoded format.- Parameters:
aInputStream
-aEncoding
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
encodedStringFromInputStream
public static final String encodedStringFromInputStream(InputStream aInputStream) throws IOException Returns the contents of a String from an InputStream in the UTF-8 encoded format.- Parameters:
aInputStream
-- Returns:
- the contents of a String from an InputStream.
- Throws:
IOException
-
platformDefaultToUTF8
Turns a String which was created using the platform standard encoding to an String which is encoded using UTF-8 encoding.- Parameters:
aString
-- Returns:
- a String as UTF encoding
- Throws:
IOException
-
isXMLFileExtension
- Parameters:
aExtension
-- Returns:
- if the extension belongs to an UTF-8 encoded XML file.
-
UTF8ToPlatformDefault
Turns a String which was created using the UTF-8 encoding to an String which is encoded using platform standard encoding.- Parameters:
aString
-- Returns:
- a String which was created using the UTF-8 encoding
- Throws:
IOException
-
stringToOutputStream
public static final void stringToOutputStream(String aString, OutputStream aOutputStream) throws IOException Write the contents of a String to an OutputStream. The Stream won't be closed at the end.- Parameters:
aString
-aOutputStream
-- Throws:
IOException
-
stringBufferToOutputStream
public static final void stringBufferToOutputStream(StringBuffer aStringBuffer, OutputStream aOutputStream) throws IOException Write the contents of a StringBuffer to an OutputStream. The Stream won't be closed at the end.- Parameters:
aStringBuffer
-aOutputStream
-- Throws:
IOException
-
stringToOutputStreamAndClose
public static final void stringToOutputStreamAndClose(String aString, OutputStream aOutputStream) throws IOException Write the contents of a String to an OutputStream. The Stream will be closed at the end.- Parameters:
aString
-aOutputStream
-- Throws:
IOException
-
stringToOutputStream
public static final void stringToOutputStream(String aString, OutputStream aOutputStream, String aEncoding) throws IOException Write the contents of a String to an OutputStream in the given encoding. The Stream won't be closed at the end.- Parameters:
aString
-aOutputStream
-aEncoding
-- Throws:
IOException
-
stringToOutputStreamAndClose
public static final void stringToOutputStreamAndClose(String aString, OutputStream aOutputStream, String aEncoding) throws IOException Write the contents of a String to an OutputStream in the given encoding. The Stream will be closed at the end.- Parameters:
aString
-aOutputStream
-aEncoding
-- Throws:
IOException
-
stringToFile
public static final void stringToFile(String aString, File aFile, String aEncoding) throws IOException Write the contents of a String to a File in the given encoding. The Stream will be closed at the end.- Parameters:
aString
-aFile
-aEncoding
-- Throws:
IOException
-
stringToFile
Write the contents of a String to a File in platform standard encoding. The Stream will be closed at the end.- Parameters:
aString
-aFile
-- Throws:
IOException
-
fileToOutputStream
public static final void fileToOutputStream(File aFile, OutputStream aOutputStream) throws IOException Copy data from a file to an OututStream.- Parameters:
aFile
-aOutputStream
-- Throws:
IOException
-
fileFromInputStream
public static final void fileFromInputStream(File aFile, InputStream aInputStream) throws IOException Copy data from an InputStream to a file.- Parameters:
aFile
-aInputStream
-- Throws:
IOException
-
copyStream
public static final void copyStream(InputStream aInputStream, OutputStream aOutputStream) throws IOException Copy data from an InputStream to an OutputStream.- Parameters:
aInputStream
-aOutputStream
-- Throws:
IOException
-
copyStream
Copy data from an Reader to an Writer.- Parameters:
aReader
-aWriter
-- Throws:
IOException
-
createDir
Create a directory including its parent directories if they dont already exist.- Parameters:
aDir
-- Throws:
IOException
-
deleteFile
Delete a file if it exists.- Parameters:
aFile
-- Returns:
- success
-
getFiles
- Parameters:
aFile
-aShouldIncludeSubdirs
-- Returns:
- all the file objects within a directory(and also sub directories) excluding the directories in it (Excluding the directory file objects.).
-
getFilesForPattern
public static final List<File> getFilesForPattern(File aFile, String aRegexpPattern, boolean aShouldIncludeSubdirs, boolean aIgnoreCase) - Parameters:
aFile
-aRegexpPattern
-aShouldIncludeSubdirs
-aIgnoreCase
-- Returns:
- all the file objects within a directory(and also sub directories) excluding the directories in it (Excluding the directory file objects.).
-
deleteFiles
Deletes all the files in a directory including the sub directories files, if the given file is a directory. !!!The sub directories won't be deleted!!!- Parameters:
aFile
-- Throws:
IOException
-
deleteFiles
- Parameters:
aSourceDir
-aFileFilter
- Deletes all the files accepted in the fileFilter returning true if successful
-
deleteFiles
Deletes all the files in the given FilesCollection returning true if successful- Parameters:
aFilesCollection
-- Returns:
- success
-
deleteDir
Deletes all the files in a directory including the sub directories files, if the given file is a directory and also the directory.- Parameters:
dir
-- Returns:
- success
-
deleteDir
Deletes all the files in a directory including the sub directories files, if the given file is a directory and also the directory.- Parameters:
dir
-goOnWithError
-- Returns:
- success
-
isEmpty
- Parameters:
aDirectory
-- Returns:
- if the given directory is an empty directory including sub directories.
-
deleteDirContents
Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself.- Parameters:
dir
-goOnOnError
-- Returns:
- success
-
deleteDirContents
Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself. It only deletes files with given extension (or null for all) if last modified date is older than given long-date.- Parameters:
aDir
-aExtension
-aOlderThanMillis
-- Returns:
- success
-
getDirContents
public static final Collection<File> getDirContents(File aDir, String aExtension, long aOlderThanMillis) - Parameters:
aDir
-aExtension
-aOlderThanMillis
-- Returns:
- Collection of Files fitting given criteria
-
getDirectoriesOnly
- Parameters:
aDir
-aRecursive
-- Returns:
- Collection of Directories in aDir
-
deleteDirContents
Deletes all the files in a directory including the sub directories files, if the given file is a directory but does not delete the directory itself.It only deletes files with given extension- Parameters:
aDir
-aExtension
-- Returns:
- success
-
returnValidFilename
Replaces all letters that are maybe not supported by system for using in filename. You should only give the filename without path!!!- Parameters:
aUncheckedFilename
-- Returns:
- valid file name
-
returnValidPath
Replaces all letters that are maybe not supported by system for using in filename. You should only give the filename without path!!! If add/remove characters also change isValidFilename/getInvalidFilenameCharacters- Parameters:
aUncheckedFilename
-- Returns:
- valid file name
-
isValidFilename
You should only give the filename without path!!! If add/remove characters also change returnValidPath/getInvalidFilenameCharacters- Parameters:
aFilename
-- Returns:
- if the given filename is valid
-
getInvalidFilenameCharacters
If add/remove characters also change returnValidPath/isValidFilename- Returns:
- a string containing all invalid characters.
-
getFileSizeString
- Parameters:
aByte
-- Returns:
- a string describing the given byte size
-
getHostNameOfLocalSystem
- Returns:
- HostName of localhost.
- Throws:
UnknownHostException
-
getIPOfLocalSystem
- Returns:
- IP of localhost.
- Throws:
UnknownHostException
-
getTemporaryExecutionFilePath
- Parameters:
aFilePath
-- Returns:
- If the File with the path is used by an other program a new one wit ~x is created and returned
- Throws:
IOException
-
doesPatternFit
public static boolean doesPatternFit(String aFileName, List<String> aPatternList, boolean aIgnoreCase) - Parameters:
aFileName
-aPatternList
-aIgnoreCase
-- Returns:
- if the given text fits to any of the given patterns.
-
doesPatternFit
- Parameters:
aFileName
-aPattern
-aIgnoreCase
-- Returns:
- if the given patterns fit .
-
getRelativePath
- Parameters:
aFromDir
-aToFileOrDir
-- Returns:
- the relative path. The first file is the directory, the second is the file.
- Throws:
IOException
-
fillFileCollection
public static Collection<File> fillFileCollection(File aDirectory, Collection<File> aFileCollection, boolean aIncludeDirectories) - Parameters:
aDirectory
-aFileCollection
-aIncludeDirectories
-- Returns:
- all files from the collection including dirs if wanted.
-
fillFileCollection
public static Collection<File> fillFileCollection(File aDirectory, Collection<File> aFileCollection, String aExtensionFilter) - Parameters:
aDirectory
-aFileCollection
-aExtensionFilter
-- Returns:
- all files from the collection without directories but only with given Extension - without extension all files are returned.
-
fillFileCollection
public static Collection<File> fillFileCollection(File aDirectory, boolean aIncludeDirectories, String aExtensionFilter) - Parameters:
aDirectory
-aIncludeDirectories
-aExtensionFilter
-- Returns:
- all files from the collection without directories but only with given Extension - without extension all files are returned.
-
getFileSize
Returns the size of the given file. If its a directory it will return the total size of all files in it (including the sub directories).- Parameters:
aFile
-aRecursive
-- Returns:
- file size
-
getFilesWithExtension
- Parameters:
aDirectory
- Directory in which too searchaExtension
- Extension to look for- Returns:
- all files in a directory with a given extension
-
getFilesWithExtension
public static ArrayList<File> getFilesWithExtension(File aDirectory, String aExtension, boolean aIncludeSubDirs) - Parameters:
aDirectory
- Directory in which too searchaExtension
- Extension to look foraIncludeSubDirs
-- Returns:
- all files in a directory with a given extension
-
getBytesFromFile
- Parameters:
aFile
-- Returns:
- the contents of the file in a byte array.
- Throws:
IOException
IllegalArgumentException
- if the file length is more than Integer.MAX_VALUE
-
isInDirectory
- Parameters:
aFile
-aDirectory
-- Returns:
- if the given file is a subfile/-directory of the given directory.
-
createLockFile
Locks the system.- Parameters:
aDirectory
-- Returns:
- success
-
getFile
- Parameters:
aFileCollection
-aFileName
-- Returns:
- the given fileList for the also given fileName.
-
checkURL
- Parameters:
aURL
-- Returns:
- the checked URL or null or MalformedURLException
-
chooseFile
- Parameters:
aExtension
-- Returns:
- the chosen file
-
doesFileExist
- Parameters:
aPath
-aSouldAcceptDirectories
-- Returns:
- if File exists
-
readCSVtoArray
public static String[][] readCSVtoArray(File aFile, String aDivider, boolean aIncludeHeader) throws IOException - Parameters:
aFile
-aDivider
-aIncludeHeader
-- Returns:
- the content of the CSV as Array
- Throws:
IOException
-
readCSVtoArray
public static String[][] readCSVtoArray(InputStream aInputStream, String aDivider, boolean aIncludeHeader) throws IOException - Parameters:
aInputStream
-aDivider
-aIncludeHeader
-- Returns:
- the content of the CSV as Array
- Throws:
IOException
-
resizeArray
Reallocates an array with a new size, and copies the contents of the old array to the new array.- Parameters:
oldArray
- the old array, to be reallocated.newSize
- the new array size.- Returns:
- A new array with the same contents.
-
writeArrayToFile
public static <T> void writeArrayToFile(T[][] aSumOfCutValues, File aFile, String aSeperator) throws IOException - Type Parameters:
T
-- Parameters:
aSumOfCutValues
-aFile
-aSeperator
-- Throws:
IOException
-
fillWithZero
- Type Parameters:
T
-- Parameters:
aValuesArray
-
-
setAuthentication
- Parameters:
aUsername
- the user name to setaPassword
- according to the user name to set
-
cleanPath
- Parameters:
aFileName
-- Returns:
- the cleaned path
-
hasAuthentication
public static boolean hasAuthentication()- Returns:
-
combineAndGZipFiles
public static File combineAndGZipFiles(String aAbsolutePath, List<File> aFilesForPattern, int aHeaderLinesToInclude) throws IOException - Parameters:
aAbsolutePath
-aFilesForPattern
-aHeaderLinesToInclude
-- Returns:
- Throws:
IOException
-