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 voidaddTestFile(File tempDir, String fileName) Add file at this directory level - ending with .txt Note that file content is name of file.static FileReturn a temp copy of a passed filestatic voidcopyDirectory(File sourceLocation, File targetLocation) Copy all files in a directory to another directory (will overwrite)static voidCopy file from one directory to anotherstatic voidCopy files in one directory to another directory based on matchin a regular expression.static booleanstatic voiddeleteEmptyPath(File dir) Delete up a directory path until a non-empty node is found Basically remove all empty directory levels above this directory.static voiddeleteEmptyPath(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 BooleandeleteTempFile(File testFile) Delete file if is tempstatic longextractFileCnt(File extFile, long dflt) static voidCopy one file to anotherstatic Stringfile2String(File extractFile) Extract the value of file to a string (utf-8)static Stringfile2String(File extractFile, String encType) Extract the value of file to a string (utf-8)static FilefileFromURL(URL url) Get a file from a URL value - bug in 1.5static voidgetDirectoryFiles(File sourceLocation, Vector<File> files) Build list of files for a directorystatic longgetDirectorySize(File directory) Return the size of all files in Directorystatic DirectoryStatsgetDirectoryStats(File directory) Return the count and size of all files in Directorystatic voidgetDirectoryStats(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 FilegetTempDir(String directoryPrefix) Get a temporary directorystatic FilegetTempDir(String directoryPrefix, LoggerInf logger) Get a temporary directorystatic FilegetTempFile(String prefix, String suffix) Create a temp file using prefix and suffix (THREAD SAFE)static StringgetURLEncodeFilePath(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 voidIncrement a stored file value and save back to filestatic booleanisTempFile(File file) is this a temp filestatic voidpopulateTest(File tempDir, String name, int lvl, int maxlvl) Create a test directory of form: A AA AB AC ...static voidremoveFile(File inputFile) static voidremoveLineFromFile(String file, String lineToRemove, String linePortion) remove line(s) from a text filestatic voidstream2File(InputStream inStream, File outFile) Create a file from a streamstatic voidstream2Stream(InputStream inStream, OutputStream outStream) Copy input stream to output streamstatic voidstring2File(File createFile, String fileContent) Create a file containing this string value (utf-8)static voidupdateDirectory(File sourceLocation, File targetLocation) Copy all files in a directory to another directory (will not overwrite)static voidGet content referenced by a url and save in a filestatic voidGet content referenced by a url and save in a filestatic voidGet content referenced by a url and save in a filestatic voidGet content referenced by a url and save in a filestatic voidurl2OutputStream(String urlS, OutputStream outStream, int retry) Move url response to output streamstatic Fileurl2TempFile(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
-
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
-
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
-
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
-
url2TempFile
get remote file- Parameters:
manifestFile-- Returns:
-
stream2File
Create a file from a stream- Parameters:
inStream- stream used to create fileoutFile- file to create
-
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
-
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
-
file2String
Extract the value of file to a string (utf-8)- Parameters:
extractFile- file to be extracted- Returns:
- string form of file content
-
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
-
getTempFile
Create a temp file using prefix and suffix (THREAD SAFE)- Parameters:
prefix- prefix of temp file namesuffix- suffix of temp file nameiStream- InputStrea of data to be copied- 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
-
updateDirectory
Copy all files in a directory to another directory (will not overwrite)- Parameters:
sourceLocation- source for copytargetLocation- target for copy
-
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
-
copy2Temp
Return a temp copy of a passed file- Parameters:
sourceFile- file to be copied- Returns:
- copied form of sourceFile as temporary file
-
incFile
Increment a stored file value and save back to file- Parameters:
incFile- file containing a numeric integer to be incrementedinc- amount to increment
-
extractFileCnt
- Parameters:
extFile- file containing a numeric valuedflt- default value if not found- Returns:
- extracted value
-
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
-