Package tilda.utils
Class FileUtil
- java.lang.Object
-
- tilda.utils.FileUtil
-
public class FileUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFileUtil.FileProcessor
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String_DEFAULT_ENV_VAR_NAMEprotected static java.lang.String[]_PROHIBITED_FILENAMESprotected static org.apache.logging.log4j.LoggerLOG
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyFileContentsIntoAnotherFile(java.lang.String inputFileName, java.io.PrintWriter Out)static booleanexistsFileOrResource(java.lang.String Name)This methods provide a general "exists" helper that covers both file-system and resource-based paths.static java.lang.StringgetBasePathFromFileOrResource(java.lang.String Name)static java.io.PrintWritergetBufferedPrintWriter(java.lang.String SourceFilePath, boolean append)static java.lang.StringgetContentsFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)static java.lang.StringgetContentsFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> headerss)static java.lang.StringgetContentsFromReader(java.io.BufferedReader r)static java.lang.StringgetContentsFromUrl(java.lang.String url)Gets contents from a GET URL provided,static java.lang.StringgetContentsFromUrl(java.lang.String url, boolean retry)Gets contents from a GET URL provided,
If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.static java.lang.StringgetContentsFromUrl(java.lang.String url, boolean retry, java.util.Map<java.lang.String,java.lang.String> headers)Gets contents from a GET URL provided,
If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.static java.util.List<org.apache.commons.csv.CSVRecord>getCSVRecords(java.lang.String fileName)Reads a whole CSV file in memory.static java.lang.StringgetFileOfResourceContents(java.io.File F)static java.lang.StringgetFileOfResourceContents(java.lang.String Name)static java.io.FilegetKeyFile(java.lang.String dataProjectName, java.lang.String appName)static java.io.FilegetKeyFile(java.lang.String envVariable, java.lang.String dataProjectName, java.lang.String appName)static java.io.BufferedReadergetReaderFromFileOrResource(java.lang.String Name)static java.io.BufferedReadergetReaderFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)Returns a Reader from a POST URL with parameters.static java.io.BufferedReadergetReaderFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> headers)Returns a Reader from a POST URL with parameters and headers.static java.io.BufferedReadergetReaderFromUrl(java.lang.String url)Returns a Reader from a GET URL.static java.io.BufferedReadergetReaderFromUrl(java.lang.String url, boolean retry)Returns a Reader from a GET URL.static java.io.BufferedReadergetReaderFromUrl(java.lang.String url, boolean retry, java.util.Map<java.lang.String,java.lang.String> headers)Returns a Reader from a GET URL and headers.static java.io.InputStreamgetResourceAsStream(java.lang.String ResourceName)static java.net.URLgetResourceUrl(java.lang.String ResourceName)static java.lang.StringgetUserHome()static booleanisExcluded(java.io.File f, java.lang.String[] Excludes)static booleanisFileNameProhibited(java.lang.String FileName)static voiditerate(java.io.File StartingFolder, FileUtil.FileProcessor FP, java.lang.String[] Excludes)static voiditerate(java.io.File StartingFolder, FileUtil.FileProcessor FP, java.lang.String[] Excludes, int Level)static java.lang.StringreadlnFromStdIn(boolean secure)protected static java.lang.StringreadToString(java.io.BufferedReader R)static booleanremoveDir(java.io.File dir, boolean recurse)
-
-
-
Field Detail
-
LOG
protected static final org.apache.logging.log4j.Logger LOG
-
_PROHIBITED_FILENAMES
protected static final java.lang.String[] _PROHIBITED_FILENAMES
-
_DEFAULT_ENV_VAR_NAME
public static final java.lang.String _DEFAULT_ENV_VAR_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResourceAsStream
public static java.io.InputStream getResourceAsStream(java.lang.String ResourceName)
-
getResourceUrl
public static java.net.URL getResourceUrl(java.lang.String ResourceName)
-
iterate
public static void iterate(java.io.File StartingFolder, FileUtil.FileProcessor FP, java.lang.String[] Excludes) throws java.lang.Exception- Throws:
java.lang.Exception
-
iterate
public static void iterate(java.io.File StartingFolder, FileUtil.FileProcessor FP, java.lang.String[] Excludes, int Level) throws java.lang.Exception- Throws:
java.lang.Exception
-
isExcluded
public static boolean isExcluded(java.io.File f, java.lang.String[] Excludes)
-
copyFileContentsIntoAnotherFile
public static void copyFileContentsIntoAnotherFile(java.lang.String inputFileName, java.io.PrintWriter Out) throws java.io.IOException- Throws:
java.io.IOException
-
getBufferedPrintWriter
public static java.io.PrintWriter getBufferedPrintWriter(java.lang.String SourceFilePath, boolean append) throws java.io.IOException- Throws:
java.io.IOException
-
isFileNameProhibited
public static boolean isFileNameProhibited(java.lang.String FileName)
-
getReaderFromUrl
public static java.io.BufferedReader getReaderFromUrl(java.lang.String url) throws java.lang.ExceptionReturns a Reader from a GET URL. It is the responsibility of the caller to close the Reader when done.- Parameters:
url-- Returns:
- Throws:
java.lang.Exception
-
getReaderFromUrl
public static java.io.BufferedReader getReaderFromUrl(java.lang.String url, boolean retry)Returns a Reader from a GET URL. It is the responsibility of the caller to close the Reader when done. If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.- Parameters:
url-retry-- Returns:
- Throws:
java.lang.Exception
-
getReaderFromUrl
public static java.io.BufferedReader getReaderFromUrl(java.lang.String url, boolean retry, java.util.Map<java.lang.String,java.lang.String> headers)Returns a Reader from a GET URL and headers. It is the responsibility of the caller to close the Reader when done. If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.- Parameters:
url-retry-- Returns:
- Throws:
java.lang.Exception
-
getContentsFromUrl
public static java.lang.String getContentsFromUrl(java.lang.String url) throws java.io.IOExceptionGets contents from a GET URL provided,- Parameters:
url-- Returns:
- Throws:
java.io.IOException
-
getContentsFromUrl
public static java.lang.String getContentsFromUrl(java.lang.String url, boolean retry) throws java.io.IOExceptionGets contents from a GET URL provided,
If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.- Parameters:
url-retry-- Returns:
- Throws:
java.io.IOException
-
getContentsFromUrl
public static java.lang.String getContentsFromUrl(java.lang.String url, boolean retry, java.util.Map<java.lang.String,java.lang.String> headers) throws java.io.IOExceptionGets contents from a GET URL provided,
If retry is true, in the case of a failure, the HTTP call will be tried another 2 times with a delay of 1000 and 2500 respectively.- Parameters:
url-retry-- Returns:
- Throws:
java.io.IOException
-
getReaderFromPostUrl
public static java.io.BufferedReader getReaderFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)Returns a Reader from a POST URL with parameters. It is the responsibility of the caller to close the Reader when done.- Parameters:
url-args-- Returns:
-
getReaderFromPostUrl
public static java.io.BufferedReader getReaderFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> headers)Returns a Reader from a POST URL with parameters and headers. It is the responsibility of the caller to close the Reader when done.- Parameters:
url-args-- Returns:
-
getContentsFromPostUrl
public static java.lang.String getContentsFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException- Throws:
java.io.IOException
-
getContentsFromPostUrl
public static java.lang.String getContentsFromPostUrl(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params, java.util.Map<java.lang.String,java.lang.String> headerss) throws java.io.IOException- Throws:
java.io.IOException
-
existsFileOrResource
public static boolean existsFileOrResource(java.lang.String Name)
This methods provide a general "exists" helper that covers both file-system and resource-based paths.- Parameters:
Name-- Returns:
- true if the resource was found either on the file system or in the classpath, or false otherwise.
-
getReaderFromFileOrResource
public static java.io.BufferedReader getReaderFromFileOrResource(java.lang.String Name) throws java.io.IOException- Throws:
java.io.IOException
-
readToString
protected static java.lang.String readToString(java.io.BufferedReader R) throws java.io.IOException- Throws:
java.io.IOException
-
getFileOfResourceContents
public static java.lang.String getFileOfResourceContents(java.lang.String Name) throws java.io.IOException- Throws:
java.io.IOException
-
getFileOfResourceContents
public static java.lang.String getFileOfResourceContents(java.io.File F) throws java.io.IOException- Throws:
java.io.IOException
-
getBasePathFromFileOrResource
public static java.lang.String getBasePathFromFileOrResource(java.lang.String Name) throws java.lang.Exception- Throws:
java.lang.Exception
-
readlnFromStdIn
public static java.lang.String readlnFromStdIn(boolean secure)
-
getUserHome
public static java.lang.String getUserHome()
-
removeDir
public static boolean removeDir(java.io.File dir, boolean recurse)
-
getCSVRecords
public static java.util.List<org.apache.commons.csv.CSVRecord> getCSVRecords(java.lang.String fileName)
Reads a whole CSV file in memory. Do not use for large files obviously!- Parameters:
fileName-- Returns:
-
getContentsFromReader
public static java.lang.String getContentsFromReader(java.io.BufferedReader r) throws java.io.IOException- Throws:
java.io.IOException
-
getKeyFile
public static java.io.File getKeyFile(java.lang.String dataProjectName, java.lang.String appName) throws java.io.FileNotFoundException, java.io.IOException- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
getKeyFile
public static java.io.File getKeyFile(java.lang.String envVariable, java.lang.String dataProjectName, java.lang.String appName) throws java.io.FileNotFoundException, java.io.IOException- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
-