Package org.cdlib.mrt.utility
Class FileUtil
java.lang.Object
org.cdlib.mrt.utility.FileUtil
Generalized file utilities
- Author:
- dloy
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
addTestFile
(File tempDir, String fileName) Add file at this directory level - ending with .txt Note that file content is name of file.static File
Return a temp copy of a passed filestatic void
copyDirectory
(File sourceLocation, File targetLocation) Copy all files in a directory to another directory (will overwrite)static void
Copy file from one directory to anotherstatic void
Copy files in one directory to another directory based on matchin a regular expression.static boolean
static void
deleteEmptyPath
(File dir) Delete up a directory path until a non-empty node is found Basically remove all empty directory levels above this directory.static void
deleteEmptyPath
(File dir, File stopDir) Delete up a directory path until a non-empty node is found Basically remove all empty directory levels above this directory.static Boolean
deleteTempFile
(File testFile) Delete file if is tempstatic long
extractFileCnt
(File extFile, long dflt) static void
Copy one file to anotherstatic String
file2String
(File extractFile) Extract the value of file to a string (utf-8)static String
file2String
(File extractFile, String encType) Extract the value of file to a string (utf-8)static File
fileFromURL
(URL url) Get a file from a URL value - bug in 1.5static void
getDirectoryFiles
(File sourceLocation, Vector<File> files) Build list of files for a directorystatic long
getDirectorySize
(File directory) Return the size of all files in Directorystatic DirectoryStats
getDirectoryStats
(File directory) Return the count and size of all files in Directorystatic void
getDirectoryStats
(File directory, DirectoryStats stats) Return the count and size of all files in Directorystatic String[]
getLinesFromFile
(File splitFile) Return array of nonempty lines from a filestatic String[]
getLinesFromURL
(LoggerInf logger, String urlS) Return array of nonempty lines from url contentstatic File
getTempDir
(String directoryPrefix) Get a temporary directorystatic File
getTempDir
(String directoryPrefix, LoggerInf logger) Get a temporary directorystatic File
getTempFile
(String prefix, String suffix) Create a temp file using prefix and suffix (THREAD SAFE)static String
getURLEncodeFilePath
(String filePath) Build a URL equivalent path using a java file path This routine maintains all slashes in the file path as a slash in the URL.static void
Increment a stored file value and save back to filestatic boolean
isTempFile
(File file) is this a temp filestatic void
populateTest
(File tempDir, String name, int lvl, int maxlvl) Create a test directory of form: A AA AB AC ...static void
removeFile
(File inputFile) static void
removeLineFromFile
(String file, String lineToRemove, String linePortion) remove line(s) from a text filestatic void
stream2File
(InputStream inStream, File outFile) Create a file from a streamstatic void
stream2Stream
(InputStream inStream, OutputStream outStream) Copy input stream to output streamstatic void
string2File
(File createFile, String fileContent) Create a file containing this string value (utf-8)static void
updateDirectory
(File sourceLocation, File targetLocation) Copy all files in a directory to another directory (will not overwrite)static void
Get content referenced by a url and save in a filestatic void
Get content referenced by a url and save in a filestatic void
Get content referenced by a url and save in a filestatic void
Get content referenced by a url and save in a filestatic void
url2OutputStream
(String urlS, OutputStream outStream, int retry) Move url response to output streamstatic File
url2TempFile
(LoggerInf m_logger, String urlS) get remote file
-
Field Details
-
NAME
- See Also:
-
MESSAGE
- See Also:
-
BUFSIZE
protected static final int BUFSIZE- See Also:
-
DEFAULT_TIMEOUT
protected static final int DEFAULT_TIMEOUT- See Also:
-
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
url2File
Get content referenced by a url and save in a file- Parameters:
m_logger
- loggerfileURL
- link to file to be extractedoutFile
- target file to create- Throws:
org.cdlib.mrt.utility.MException
TException
-
url2File
Get content referenced by a url and save in a file- Parameters:
m_logger
- loggerurlS
- link to file to be extractedoutFile
- target file to create- Throws:
org.cdlib.mrt.utility.MException
TException
-
url2File
public static void url2File(LoggerInf m_logger, URL fileURL, File outFile, int retry) throws TException Get content referenced by a url and save in a file- Parameters:
m_logger
- loggerfileURL
- link to file to be extractedoutFile
- target file to createretry
- number of retry attempts- Throws:
org.cdlib.mrt.utility.MException
TException
-
url2File
public static void url2File(LoggerInf m_logger, String urlS, File outFile, int retry) throws TException Get content referenced by a url and save in a file- Parameters:
m_logger
- loggerurlS
- link to file to be extractedoutFile
- target file to createretry
- number of retry attempts- Throws:
org.cdlib.mcur.utility.MException
TException
-
url2TempFile
get remote file- Parameters:
manifestFile
-- Returns:
- Throws:
org.cdlib.framework.utility.FrameworkException
TException
-
stream2File
Create a file from a stream- Parameters:
inStream
- stream used to create fileoutFile
- file to create- Throws:
org.cdlib.mrt.utility.MException
TException
-
url2OutputStream
public static void url2OutputStream(String urlS, OutputStream outStream, int retry) throws TException Move url response to output stream- Parameters:
urlS
- link to file to be extractedoutStream
- output streamretry
- number of retry attempts- Throws:
org.cdlib.mcur.utility.MException
TException
-
stream2Stream
Copy input stream to output stream- Parameters:
inStream
- - input streamoutStream
- - output Stream- Throws:
TException
- process exception
-
copyFile
public static void copyFile(String fileName, File sourceDirectory, File targetDirectory) throws TException Copy file from one directory to another- Parameters:
fileName
- string name of file (may include some path extensions)sourceDirectory
- from directorytargetDirectory
- to directory- Throws:
TException
-
file2file
Copy one file to another- Parameters:
sourceFile
- input filetargetFile
- output file- Throws:
TException
- service exception
-
getURLEncodeFilePath
Build a URL equivalent path using a java file path This routine maintains all slashes in the file path as a slash in the URL. All other special charecters are url encoded- Parameters:
filePath
- file path to convert to a URL form- Returns:
- URI valid path
-
copyReg
public static void copyReg(String fileExp, File sourceDirectory, File targetDirectory) throws TException Copy files in one directory to another directory based on matchin a regular expression. If a directory matches the expression then it will also be copied- Parameters:
fileExp
- regex used for matching the fileNamesourceDirectory
- source directory for copytargetDirectory
- target directory for copy- Throws:
TException
- process exception
-
string2File
Create a file containing this string value (utf-8)- Parameters:
createFile
- file to createfileContent
- string containing content to save in file- Throws:
org.cdlib.mrt.utility.MException
TException
-
file2String
Extract the value of file to a string (utf-8)- Parameters:
extractFile
- file to be extracted- Returns:
- string form of file content
- Throws:
org.cdlib.mrt.utility.MException
TException
-
file2String
Extract the value of file to a string (utf-8)- Parameters:
extractFile
- file to be extractedencType
- bit to character encoding- Returns:
- string form of file content
- Throws:
org.cdlib.mrt.utility.MException
TException
-
getTempFile
Create a temp file using prefix and suffix (THREAD SAFE)- Parameters:
iStream
- InputStrea of data to be copiedprefix
- prefix of temp file namesuffix
- suffix of temp file name- Throws:
TException
-
deleteTempFile
Delete file if is temp- Parameters:
testFile
- temp file to be deleted- Returns:
- true=file no longer exists on completion; false=file not deleted
-
isTempFile
is this a temp file- Parameters:
file
-- Returns:
- true=is temp; false=is not temp
-
getTempDir
Get a temporary directory- Parameters:
directoryPrefix
- prefix for temporary file- Returns:
- temp file
- Throws:
TException
-
getTempDir
Get a temporary directory- Parameters:
directoryPrefix
- prefix for temporary filelogger
- log file- Returns:
- temporary directory
- Throws:
TException
-
copyDirectory
Copy all files in a directory to another directory (will overwrite)- Parameters:
sourceLocation
- source for copytargetLocation
- target for copy- Throws:
org.cdlib.mrt.utility.MException
TException
-
updateDirectory
Copy all files in a directory to another directory (will not overwrite)- Parameters:
sourceLocation
- source for copytargetLocation
- target for copy- Throws:
org.cdlib.mrt.utility.MException
TException
-
getDirectorySize
Return the size of all files in Directory- Parameters:
directory
- starting directory for accumulating size- Returns:
-
getDirectoryStats
Return the count and size of all files in Directory- Parameters:
directory
- start directory for tally
-
getDirectoryStats
Return the count and size of all files in Directory- Parameters:
directory
- start directory for tallystats
- accumulating stats object
-
getDirectoryFiles
Build list of files for a directory- Parameters:
sourceLocation
- start directory for extractionfiles
- list of file contents- Throws:
org.cdlib.mrt.utility.MException
TException
-
copy2Temp
Return a temp copy of a passed file- Parameters:
sourceFile
- file to be copied- Returns:
- copied form of sourceFile as temporary file
- Throws:
org.cdlib.mrt.utility.MException
TException
-
incFile
Increment a stored file value and save back to file- Parameters:
incFile
- file containing a numeric integer to be incrementedinc
- amount to increment- Throws:
org.cdlib.mrt.utility.MException
TException
-
extractFileCnt
- Parameters:
extFile
- file containing a numeric valuedflt
- default value if not found- Returns:
- extracted value
- Throws:
org.cdlib.mrt.utility.MException
TException
-
deleteDir
-
deleteEmptyPath
Delete up a directory path until a non-empty node is found Basically remove all empty directory levels above this directory.- Parameters:
dir
- directory
-
deleteEmptyPath
Delete up a directory path until a non-empty node is found Basically remove all empty directory levels above this directory.- Parameters:
dir
- directorystopDir
- stop at this parent directory
-
populateTest
Create a test directory of form: A AA AB AC ... AAAA.txt AAAB.txt AAAC.txt Note content of .txt file is name of file
- Parameters:
tempDir
- this level directorylvl
- level beginning with one indicating level in test treemaxlvl
- maximum level count before file (not directories) are created- Throws:
TException
-
addTestFile
Add file at this directory level - ending with .txt Note that file content is name of file.- Parameters:
tempDir
-fileName
-- Throws:
TException
-
fileFromURL
Get a file from a URL value - bug in 1.5- Parameters:
url
- to be converted- Returns:
- file
-
removeLineFromFile
remove line(s) from a text file- Parameters:
file
- file to be processedlineToRemove
- line to be removedlinePortion
- begins, ends contains or matches line (BEGIN, END, CONTAIN or MATCH, default: MATCH)
-
getLinesFromFile
Return array of nonempty lines from a file- Parameters:
logger
- merritt loggerurlS
- url to file to be split- Returns:
- array of lines from original file
- Throws:
TException
-
getLinesFromURL
Return array of nonempty lines from url content- Parameters:
logger
- merritt loggerurlS
- url to file to be split- Returns:
- array of lines from original file
- Throws:
TException
-
removeFile
-