|
||||||||||
| 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(File pSource,
File pTarget,
FileUtil.CopyMode pMode,
String... pPatterns)
Copies one file into another file. |
static void |
copy(File pSource,
File pTarget,
String... pPatterns)
Copy a file or directory to another file or directory. |
static long |
copy(InputStream pIn,
boolean pCloseIn,
OutputStream pOut,
boolean pCloseOut)
Copies the content of an InputStream to the desired OutputStream. |
static long |
copy(InputStream pIn,
File pTarget)
Copies the content from a stream into a file. |
static long |
copy(InputStream pIn,
OutputStream pOut)
Copies the content of an InputStream to the desired OutputStream. |
static boolean |
delete(File pSource,
String... pPattern)
Delete a file or directory. |
static boolean |
deleteEmpty(File pDirectory,
String... pPattern)
Delete empty directories, recursive. |
static boolean |
deleteIfEmpty(File... pDirectory)
Deletes directories if they are empty. |
static boolean |
deleteSub(File pSource,
String... pPattern)
Delete all files and directories in the given directory. |
static String |
formatAsDirectory(String pPath)
Formats the given path as directory. |
static byte[] |
getContent(File pFile)
Gets the content from a file. |
static byte[] |
getContent(InputStream pStream)
Reads the content of an InputStream into a byte array and closes the stream after reading. |
static byte[] |
getContent(InputStream pStream,
boolean pAutoClose)
Reads the content of an InputStream into a byte array. |
static byte[] |
getContent(InputStreamReader pReader)
Reads the content of an InputStreamReader into a byte array and closes the stream after reading. |
static byte[] |
getContent(InputStreamReader pReader,
boolean pAutoClose)
Reads the content of an InputStreamReader into a byte array. |
static byte[] |
getContent(String pFileName)
Gets the content from a file. |
static String |
getDirectory(String pAbsolutePath)
Gets the directory for a path. |
static String |
getExtension(String pPath)
Gets the extension of an absolute file path. |
static String |
getName(String pAbsolutePath)
Gets the name of a file from an absolute path. |
static File |
getNotExistingFile(File pFile)
Gets a file that does not exist. |
static File |
getNotExistingFile(File pFile,
String pOpenBracket,
String pCloseBracket)
Gets a file that does not exist. |
static boolean |
like(String pSource,
String pSearch)
Fast like search in path with wildcard(**, * and ?) |
static List<String> |
listZipEntries(InputStream pArchive)
Gets a list of all entries from a zip archive. |
static void |
move(File pSource,
File pTarget)
Moves the given source file to another location. |
static void |
move(File pSource,
File pTarget,
FileUtil.CopyMode pMode)
Moves the given source file to another location. |
static String |
removeExtension(String pPath)
Removes the file extension from a file name. |
static void |
replace(File pInput,
File pOutput,
Hashtable<String,String> pMapping,
String pEncoding)
Replaces key/value mappings read from the given input file and writes the result to the given output file. |
static void |
replace(File pInput,
File pOutput,
Hashtable<String,String> pMapping,
String pInEncoding,
String pOutEncoding)
Replaces key/value mappings read from the given input file and writes the result to the given output file. |
static void |
replace(InputStream pInput,
OutputStream pOutput,
Hashtable<String,String> pMapping,
String pInEncoding,
String pOutEncoding)
Replaces key/value mappings read from the given input stream and writes the result to the given output stream. |
static void |
save(File pFile,
byte[] byContent)
Saves the given content into a file. |
static void |
save(File pFile,
InputStream pInput)
Saves the given stream into a file. |
static void |
unzip(File pFile,
String pTarget)
Unzips the given file. |
static void |
unzip(InputStream pArchive,
File pTarget)
Extracts the content of a zip archive. |
static void |
unzip(InputStream pArchive,
String pTarget)
Extracts the content of a zip archive. |
static void |
unzip(String pFile,
String pTarget)
Unzips the given file. |
static void |
zip(OutputStream pOut,
int pMode,
File... pFiles)
Creates a zip package for given files. |
static void |
zip(OutputStream pOut,
int pMode,
String[] pSearchPath,
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(InputStream pIn,
File pTarget)
throws IOException
pIn - the input streampTarget - the output file
IOException - if it's not possible to read from the InputStream
or write to the File
public static long copy(InputStream pIn,
OutputStream pOut)
throws IOException
InputStream to the desired OutputStream.
pIn - input stream with contentpOut - output stream
IOException - if it's not possible to read from the InputStream
or write to the OutputStream
public static long copy(InputStream pIn,
boolean pCloseIn,
OutputStream pOut,
boolean pCloseOut)
throws IOException
InputStream to the desired OutputStream.
pIn - input stream with contentpCloseIn - true, if the input streampOut - output streampCloseOut - true, if the output stream
IOException - if it's not possible to read from the InputStream
or write to the OutputStream
public static void copy(File pSource,
File pTarget,
String... pPatterns)
throws IOException
pSource - the source filepTarget - the target filepPatterns - the include/exclude patterns. This parameter is only used for directory copy.
IOException - if the copy process failed
public static void copy(File pSource,
File pTarget,
FileUtil.CopyMode pMode,
String... pPatterns)
throws IOException
pSource - source filepTarget - target filepMode - the copy modepPatterns - include/exclude file pattern(s)
IOException - if it's not possible to copy the file or directory
public static void move(File pSource,
File pTarget)
throws IOException
pSource - the source filepTarget - the target location
IOException - if an error occurs during moving
public static void move(File pSource,
File pTarget,
FileUtil.CopyMode pMode)
throws IOException
pSource - the source filepTarget - the target locationpMode - the copy mode
IOException - if an error occurs during movingpublic static byte[] getContent(InputStream pStream)
InputStream into a byte array and closes the stream after reading.
pStream - the input stream
public static byte[] getContent(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(File pFile)
throws IOException
pFile - the file
IOException - if the file does not exist
public static byte[] getContent(String pFileName)
throws IOException
pFileName - the path to the file
IOException - if the file does not existpublic static byte[] getContent(InputStreamReader pReader)
InputStreamReader into a byte array and closes the stream after reading.
pReader - the input stream reader
public static byte[] getContent(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 String removeExtension(String pPath)
pPath - the filename
public static String getExtension(String pPath)
pPath - the absolute path of a file
null if the path is null
or has no extensionpublic static File getNotExistingFile(File pFile)
pFile - the desired file name
public static File getNotExistingFile(File pFile,
String pOpenBracket,
String pCloseBracket)
pFile - the desired file namepOpenBracket - the start bracketpCloseBracket - the close bracket
public static String getName(String pAbsolutePath)
pAbsolutePath - the absolute path for a file
public static String getDirectory(String pAbsolutePath)
pAbsolutePath - a path
null if no path separator was foundpublic static String formatAsDirectory(String pPath)
pPath - the path
public static boolean deleteSub(File pSource,
String... pPattern)
pSource - the file or directorypPattern - the patterns
false otherwise
public static boolean delete(File pSource,
String... pPattern)
pSource - the file or directorypPattern - the patterns
false otherwise
public static boolean deleteEmpty(File pDirectory,
String... pPattern)
pDirectory - the start directoriespPattern - the include/exclude pattern
true if all empty directories were deleted, false
otherwisepublic static boolean deleteIfEmpty(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(OutputStream pOut,
int pMode,
String[] pSearchPath,
String... pExtension)
throws IOException
pOut - the output streampMode - ZipOutputStream.STORED or ZipOutputStream.DEFLATEDpSearchPath - all search pathpExtension - all allowed extensions
IOException - if a problem occurs during zip creation
public static void zip(OutputStream pOut,
int pMode,
File... pFiles)
throws IOException
pOut - the output streampMode - ZipOutputStream.STORED or ZipOutputStream.DEFLATEDpFiles - all search path
IOException - if a problem occurs during zip creation
public static void unzip(String pFile,
String pTarget)
throws IOException
pFile - the path to the zip archivepTarget - the target directory
IOException - if unzipping fails
public static void unzip(File pFile,
String pTarget)
throws IOException
pFile - the zip archivepTarget - the target directory
IOException - if unzipping fails
public static void unzip(InputStream pArchive,
String pTarget)
throws IOException
pArchive - the zip archivepTarget - where the content should go
IOException - if an error occurs during extractionunzip(InputStream, File)
public static void unzip(InputStream pArchive,
File pTarget)
throws IOException
pArchive - the zip archivepTarget - where the content should go
IOException - if an error occurs during extraction
public static List<String> listZipEntries(InputStream pArchive)
throws IOException
pArchive - the stream for the zip archive
IOException - if the archive does not contain zip content or a read error occurs
public static void save(File pFile,
byte[] byContent)
throws IOException
pFile - the output filebyContent - the data
IOException - if an error occurs during output
public static void save(File pFile,
InputStream pInput)
throws IOException
pFile - the output filepInput - the input stream
IOException - if an error occurs during output
public static void replace(File pInput,
File pOutput,
Hashtable<String,String> pMapping,
String pEncoding)
throws IOException
pInput - the input filepOutput - the output filepMapping - the key/value mapping e.g. ${PARAM1} = JVxpEncoding - the encoding for the input/output files
IOException - if a read or write error occurs
public static void replace(File pInput,
File pOutput,
Hashtable<String,String> pMapping,
String pInEncoding,
String pOutEncoding)
throws 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
IOException - if a read or write error occurs
public static void replace(InputStream pInput,
OutputStream pOutput,
Hashtable<String,String> pMapping,
String pInEncoding,
String pOutEncoding)
throws 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
IOException - if a read or write error occurs
public static boolean like(String pSource,
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 | |||||||||