|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sibvisions.util.type.FileUtil
public final class FileUtil
The FileUtil contains file and filename dependent
utility methods.
| Nested Class Summary | |
|---|---|
static class |
FileUtil.CopyMode
File or directory copy mode. |
| Method Summary | |
|---|---|
static void |
copy(java.io.File pSource,
java.io.File pTarget,
FileUtil.CopyMode pMode,
java.lang.String... pPatterns)
Copies one file into another file. |
static void |
copy(java.io.File pSource,
java.io.File pTarget,
java.lang.String... pPatterns)
Copy a file or directory to another file or directory. |
static long |
copy(java.io.InputStream pIn,
boolean pCloseIn,
java.io.OutputStream pOut,
boolean pCloseOut)
Copies the content of an InputStream to the desired OutputStream. |
static long |
copy(java.io.InputStream pIn,
java.io.File pTarget)
Copies the content from a stream into a file. |
static long |
copy(java.io.InputStream pIn,
java.io.OutputStream pOut)
Copies the content of an InputStream to the desired OutputStream. |
static boolean |
delete(java.io.File pSource,
boolean pStopAfterError,
java.lang.String... pPattern)
Deletes a file or directory. |
static boolean |
delete(java.io.File pSource,
java.lang.String... pPattern)
Deletes a file or directory. |
static boolean |
deleteEmpty(java.io.File pDirectory,
java.lang.String... pPattern)
Delete empty directories, recursive. |
static boolean |
deleteIfEmpty(java.io.File... pDirectory)
Deletes directories if they are empty. |
static boolean |
deleteSub(java.io.File pSource,
boolean pStopAfterError,
java.lang.String... pPattern)
Delete all files and directories in the given directory. |
static boolean |
deleteSub(java.io.File pSource,
java.lang.String... pPattern)
Delete all files and directories in the given directory. |
static java.lang.String |
formatAsDirectory(java.lang.String pPath)
Formats the given path as directory. |
static byte[] |
getContent(java.io.File pFile)
Gets the content from a file. |
static byte[] |
getContent(java.io.InputStream pStream)
Reads the content of an InputStream into a byte array and closes the stream after reading. |
static byte[] |
getContent(java.io.InputStream pStream,
boolean pAutoClose)
Reads the content of an InputStream into a byte array. |
static byte[] |
getContent(java.io.InputStreamReader pReader)
Reads the content of an InputStreamReader into a byte array and closes the stream after reading. |
static byte[] |
getContent(java.io.InputStreamReader pReader,
boolean pAutoClose)
Reads the content of an InputStreamReader into a byte array. |
static byte[] |
getContent(java.lang.String pFileName)
Gets the content from a file. |
static java.lang.String |
getDirectory(java.lang.String pAbsolutePath)
Gets the directory for a path. |
static java.lang.String |
getExtension(java.lang.String pPath)
Gets the extension of an absolute file path. |
static java.lang.String |
getName(java.lang.String pAbsolutePath)
Gets the name of a file from an absolute path. |
static java.io.File |
getNotExistingFile(java.io.File pFile)
Gets a file that does not exist. |
static java.io.File |
getNotExistingFile(java.io.File pFile,
java.lang.String pOpenBracket,
java.lang.String pCloseBracket)
Gets a file that does not exist. |
static boolean |
like(java.lang.String pSource,
java.lang.String pSearch)
Fast like search in path with wildcard(**, * and ?) |
static java.util.List<java.lang.String> |
listZipEntries(java.io.InputStream pArchive)
Gets a list of all entries from a zip archive. |
static void |
move(java.io.File pSource,
java.io.File pTarget)
Moves the given source file to another location. |
static void |
move(java.io.File pSource,
java.io.File pTarget,
FileUtil.CopyMode pMode)
Moves the given source file to another location. |
static java.lang.String |
removeExtension(java.lang.String pPath)
Removes the file extension from a file name. |
static void |
replace(java.io.File pInput,
java.io.File pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pEncoding)
Replaces key/value mappings read from the given input file and writes the result to the given output file. |
static void |
replace(java.io.File pInput,
java.io.File pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pInEncoding,
java.lang.String pOutEncoding)
Replaces key/value mappings read from the given input file and writes the result to the given output file. |
static void |
replace(java.io.InputStream pInput,
java.io.OutputStream pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pInEncoding,
java.lang.String pOutEncoding)
Replaces key/value mappings read from the given input stream and writes the result to the given output stream. |
static void |
save(java.io.File pFile,
byte[] byContent)
Saves the given content into a file. |
static void |
save(java.io.File pFile,
java.io.InputStream pInput)
Saves the given stream into a file. |
static void |
unzip(java.io.File pFile,
java.lang.String pTarget)
Unzips the given file. |
static void |
unzip(java.io.InputStream pArchive,
java.io.File pTarget)
Extracts the content of a zip archive. |
static void |
unzip(java.io.InputStream pArchive,
java.lang.String pTarget)
Extracts the content of a zip archive. |
static void |
unzip(java.lang.String pFile,
java.lang.String pTarget)
Unzips the given file. |
static void |
zip(java.io.OutputStream pOut,
int pMode,
java.io.File... pFiles)
Creates a zip package for given files. |
static void |
zip(java.io.OutputStream pOut,
int pMode,
java.lang.String[] pSearchPath,
java.lang.String... pExtension)
Creates a zip package for given directories. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static long copy(java.io.InputStream pIn,
java.io.File pTarget)
throws java.io.IOException
pIn - the input streampTarget - the output file
java.io.IOException - if it's not possible to read from the InputStream
or write to the File
public static long copy(java.io.InputStream pIn,
java.io.OutputStream pOut)
throws java.io.IOException
InputStream to the desired OutputStream.
pIn - input stream with contentpOut - output stream
java.io.IOException - if it's not possible to read from the InputStream
or write to the OutputStream
public static long copy(java.io.InputStream pIn,
boolean pCloseIn,
java.io.OutputStream pOut,
boolean pCloseOut)
throws java.io.IOException
InputStream to the desired OutputStream.
pIn - input stream with contentpCloseIn - true, if the input streampOut - output streampCloseOut - true, if the output stream
java.io.IOException - if it's not possible to read from the InputStream
or write to the OutputStream
public static void copy(java.io.File pSource,
java.io.File pTarget,
java.lang.String... pPatterns)
throws java.io.IOException
pSource - the source filepTarget - the target filepPatterns - the include/exclude patterns. This parameter is only used for directory copy.
java.io.IOException - if the copy process failed
public static void copy(java.io.File pSource,
java.io.File pTarget,
FileUtil.CopyMode pMode,
java.lang.String... pPatterns)
throws java.io.IOException
pSource - source filepTarget - target filepMode - the copy modepPatterns - include/exclude file pattern(s)
java.io.IOException - if it's not possible to copy the file or directory
public static void move(java.io.File pSource,
java.io.File pTarget)
throws java.io.IOException
pSource - the source filepTarget - the target location
java.io.IOException - if an error occurs during moving
public static void move(java.io.File pSource,
java.io.File pTarget,
FileUtil.CopyMode pMode)
throws java.io.IOException
pSource - the source filepTarget - the target locationpMode - the copy mode
java.io.IOException - if an error occurs during movingpublic static byte[] getContent(java.io.InputStream pStream)
InputStream into a byte array and closes the stream after reading.
pStream - the input stream
public static byte[] getContent(java.io.InputStream pStream,
boolean pAutoClose)
InputStream into a byte array.
pStream - the input streampAutoClose - whether the input stream should be closed after reading
public static byte[] getContent(java.io.File pFile)
throws java.io.IOException
pFile - the file
java.io.IOException - if the file does not exist
public static byte[] getContent(java.lang.String pFileName)
throws java.io.IOException
pFileName - the path to the file
java.io.IOException - if the file does not existpublic static byte[] getContent(java.io.InputStreamReader pReader)
InputStreamReader into a byte array and closes the stream after reading.
pReader - the input stream reader
public static byte[] getContent(java.io.InputStreamReader pReader,
boolean pAutoClose)
InputStreamReader into a byte array.
pReader - the input stream readerpAutoClose - whether the input stream should be closed after reading
public static java.lang.String removeExtension(java.lang.String pPath)
pPath - the filename
public static java.lang.String getExtension(java.lang.String pPath)
pPath - the absolute path of a file
null if the path is null
or has no extensionpublic static java.io.File getNotExistingFile(java.io.File pFile)
pFile - the desired file name
public static java.io.File getNotExistingFile(java.io.File pFile,
java.lang.String pOpenBracket,
java.lang.String pCloseBracket)
pFile - the desired file namepOpenBracket - the start bracketpCloseBracket - the close bracket
public static java.lang.String getName(java.lang.String pAbsolutePath)
pAbsolutePath - the absolute path for a file
public static java.lang.String getDirectory(java.lang.String pAbsolutePath)
pAbsolutePath - a path
null if no path separator was foundpublic static java.lang.String formatAsDirectory(java.lang.String pPath)
pPath - the path
public static boolean deleteSub(java.io.File pSource,
java.lang.String... pPattern)
pSource - the file or directorypPattern - the patterns
false otherwise
public static boolean deleteSub(java.io.File pSource,
boolean pStopAfterError,
java.lang.String... pPattern)
pSource - the file or directorypStopAfterError - true to stop after delete error, false to
continue with next filepPattern - the patterns
false otherwise
public static boolean delete(java.io.File pSource,
java.lang.String... pPattern)
pSource - the file or directorypPattern - the patterns
false otherwise
public static boolean delete(java.io.File pSource,
boolean pStopAfterError,
java.lang.String... pPattern)
pSource - the file or directorypStopAfterError - true to stop after delete error, false to
continue with next filepPattern - the patterns
false otherwise
public static boolean deleteEmpty(java.io.File pDirectory,
java.lang.String... pPattern)
pDirectory - the start directoriespPattern - the include/exclude pattern
true if all empty directories were deleted, false
otherwisepublic static boolean deleteIfEmpty(java.io.File... pDirectory)
pDirectory - a list of directories
true if all empty directories were deleted, false if an empty
directory can not be deleted
public static void zip(java.io.OutputStream pOut,
int pMode,
java.lang.String[] pSearchPath,
java.lang.String... pExtension)
throws java.io.IOException
pOut - the output streampMode - ZipOutputStream.STORED or ZipOutputStream.DEFLATEDpSearchPath - all search pathpExtension - all allowed extensions
java.io.IOException - if a problem occurs during zip creation
public static void zip(java.io.OutputStream pOut,
int pMode,
java.io.File... pFiles)
throws java.io.IOException
pOut - the output streampMode - ZipOutputStream.STORED or ZipOutputStream.DEFLATEDpFiles - all search path
java.io.IOException - if a problem occurs during zip creation
public static void unzip(java.lang.String pFile,
java.lang.String pTarget)
throws java.io.IOException
pFile - the path to the zip archivepTarget - the target directory
java.io.IOException - if unzipping fails
public static void unzip(java.io.File pFile,
java.lang.String pTarget)
throws java.io.IOException
pFile - the zip archivepTarget - the target directory
java.io.IOException - if unzipping fails
public static void unzip(java.io.InputStream pArchive,
java.lang.String pTarget)
throws java.io.IOException
pArchive - the zip archivepTarget - where the content should go
java.io.IOException - if an error occurs during extractionunzip(InputStream, File)
public static void unzip(java.io.InputStream pArchive,
java.io.File pTarget)
throws java.io.IOException
pArchive - the zip archivepTarget - where the content should go
java.io.IOException - if an error occurs during extraction
public static java.util.List<java.lang.String> listZipEntries(java.io.InputStream pArchive)
throws java.io.IOException
pArchive - the stream for the zip archive
java.io.IOException - if the archive does not contain zip content or a read error occurs
public static void save(java.io.File pFile,
byte[] byContent)
throws java.io.IOException
pFile - the output filebyContent - the data
java.io.IOException - if an error occurs during output
public static void save(java.io.File pFile,
java.io.InputStream pInput)
throws java.io.IOException
pFile - the output filepInput - the input stream
java.io.IOException - if an error occurs during output
public static void replace(java.io.File pInput,
java.io.File pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pEncoding)
throws java.io.IOException
pInput - the input filepOutput - the output filepMapping - the key/value mapping e.g. ${PARAM1} = JVxpEncoding - the encoding for the input/output files
java.io.IOException - if a read or write error occurs
public static void replace(java.io.File pInput,
java.io.File pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pInEncoding,
java.lang.String pOutEncoding)
throws java.io.IOException
pInput - the input filepOutput - the output filepMapping - the key/value mapping e.g. ${PARAM1} = JVxpInEncoding - the encoding of the input filepOutEncoding - the encoding for the output file
java.io.IOException - if a read or write error occurs
public static void replace(java.io.InputStream pInput,
java.io.OutputStream pOutput,
java.util.Hashtable<java.lang.String,java.lang.String> pMapping,
java.lang.String pInEncoding,
java.lang.String pOutEncoding)
throws java.io.IOException
pInput - the input streampOutput - the output streampMapping - the key/value mapping e.g. ${PARAM1} = JVxpInEncoding - the encoding of the input streampOutEncoding - the encoding for the output stream
java.io.IOException - if a read or write error occurs
public static boolean like(java.lang.String pSource,
java.lang.String pSearch)
pSource - any stringpSearch - search pattern with or without wildcards.
true if, and only if, the string matches the pattern
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||