public final class FileUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
FileUtils.Constants |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
static String |
JAVA_IO_TEMP_DIR |
static String |
LINE_SEPARATOR |
static char[] |
LINE_SEPARATOR_CHARS |
static char |
SEPARATOR |
static char[] |
SUFFIX_class |
static char[] |
SUFFIX_CLASS |
static char[] |
SUFFIX_jar |
static char[] |
SUFFIX_JAR |
static char[] |
SUFFIX_java |
static char[] |
SUFFIX_JAVA |
static char[] |
SUFFIX_zip |
static char[] |
SUFFIX_ZIP |
static String |
TEMP_DIRECTORY |
Modifier and Type | Method and Description |
---|---|
static String |
buildDirectoryPath(String[] paths)
Builds a file directory path from a physical location and a location that needs
to be appended to the physical.
|
static File |
convertByteArrayToFile(byte[] contents,
String parentDirectoryPath,
String fileName) |
static void |
copy(String fromFileName,
String toFileName)
Copy a file.
|
static void |
copy(String fromFileName,
String toFileName,
boolean overwrite)
Copy a file
|
static void |
copyDirectoriesRecursively(File sourceDirectory,
File targetDirectory)
Copy recursively the
sourceDirectory and all its contents
to the targetDirectory . |
static void |
copyDirectoryContentsRecursively(File sourceDirectory,
File targetDirectory)
Copy recursively the contents of
sourceDirectory to
the targetDirectory . |
static void |
copyFile(String orginDirectory,
String destDirectory,
String fileName)
Copy file from orginating directory to the destination directory.
|
static void |
copyFile(String orginDirectory,
String orginFileName,
String destDirectory,
String destFileName)
Copy file from orginating directory to the destination directory.
|
static File[] |
findAllFilesInDirectory(String dir)
Returns a
File array that will contain all the files that exist in the directory |
static File[] |
findAllFilesInDirectoryRecursively(String dir)
Returns a
File array that will contain all the files that
exist in the specified directory or any nested directories |
static String |
getBaseFileNameWithoutExtension(String path) |
static String |
getExtension(File theFile)
Obtains the file extension of the specified
File . |
static String |
getExtension(String theFileName)
Obtains the file extension of the specified file name.
|
static String |
getFilenameWithoutExtension(String filename) |
static boolean |
isArchiveFileName(String name)
Returns true iff str.toLowerCase().endsWith(".jar") || str.toLowerCase().endsWith(".zip")
implementation is not creating extra strings.
|
static boolean |
isClassFileName(String name)
Returns true iff str.toLowerCase().endsWith(".class")
implementation is not creating extra strings.
|
static boolean |
isFilenameValid(String newName)
Determine whether the specified name is valid for a file or folder on the current file system.
|
static boolean |
isJavaFileName(String name)
Returns true iff str.toLowerCase().endsWith(".java")
implementation is not creating extra strings.
|
static void |
remove(File file) |
static void |
remove(String filePath) |
static void |
removeChildrenRecursively(File directory) |
static void |
removeDirectoryAndChildren(File directory) |
static void |
rename(String oldFilePath,
String newFilePath,
boolean overwrite)
Rename a file.
|
static String |
toFileNameWithExtension(String name,
String extension)
Convert the specified file name to end with the specified extension if it doesn't already end with an extension.
|
static String |
toFileNameWithExtension(String name,
String extension,
boolean force)
Convert the specified file name to end with the specified extension if it doesn't already end with an extension.
|
static void |
write(byte[] data,
File file)
Write a byte array to a file.
|
static void |
write(byte[] data,
String fileName)
Write a byte array to a file.
|
static void |
write(File f,
OutputStream outputStream)
Write an File to an OutputStream
Note: this will not close the outputStream;
|
static void |
write(File f,
OutputStream outputStream,
int bufferSize)
Write an File to an OutputStream
Note: this will not close the outputStream;
|
static void |
write(InputStream is,
File f)
Write an InputStream to a file.
|
static void |
write(InputStream is,
File f,
int bufferSize)
Write an InputStream to a file.
|
static void |
write(InputStream fis,
OutputStream outputStream,
int bufferSize)
Write the given input stream to outputstream
Note: this will not close in/out streams
|
static void |
write(InputStream is,
String fileName)
Write an InputStream to a file.
|
public static final char SEPARATOR
public static int DEFAULT_BUFFER_SIZE
public static String TEMP_DIRECTORY
public static String LINE_SEPARATOR
public static char[] LINE_SEPARATOR_CHARS
public static final String JAVA_IO_TEMP_DIR
public static final char[] SUFFIX_class
public static final char[] SUFFIX_CLASS
public static final char[] SUFFIX_java
public static final char[] SUFFIX_JAVA
public static final char[] SUFFIX_jar
public static final char[] SUFFIX_JAR
public static final char[] SUFFIX_zip
public static final char[] SUFFIX_ZIP
public static String toFileNameWithExtension(String name, String extension)
Convert the specified file name to end with the specified extension if it doesn't already end with an extension.
name
- The file name.extension
- The extension to append to the file name.public static String toFileNameWithExtension(String name, String extension, boolean force)
Convert the specified file name to end with the specified extension if it doesn't already end with an extension. If force is true, the specified extension will be appended to the name if the name doesn't end with that particular extension.
name
- The file name.extension
- The extension to append to the file name.force
- Indicates whether to force the specified extension as the extension of the file name.public static boolean isFilenameValid(String newName)
newName
- the new name to be checkedpublic static void copy(String fromFileName, String toFileName) throws IOException
fromFileName
- toFileName
- Exception
IOException
public static void copy(String fromFileName, String toFileName, boolean overwrite) throws IOException
fromFileName
- toFileName
- overwrite
- whether to overwrite the destination file if it exists.TeiidException
IOException
public static void copyDirectoryContentsRecursively(File sourceDirectory, File targetDirectory) throws Exception
sourceDirectory
to
the targetDirectory
. Note that sourceDirectory
will NOT be copied. If targetDirectory
does not exist, it will be created.sourceDirectory
- The source directory to copytargetDirectory
- The target directory to copy toException
- If the source directory does not exist.public static void copyFile(String orginDirectory, String destDirectory, String fileName) throws Exception
orginDirectory
- destDirectory
- fileName
- Exception
public static void copyFile(String orginDirectory, String orginFileName, String destDirectory, String destFileName) throws Exception
orginDirectory
- orginFileName
- destDirectory
- destFileName
- Exception
public static void copyDirectoriesRecursively(File sourceDirectory, File targetDirectory) throws Exception
sourceDirectory
and all its contents
to the targetDirectory
. If targetDirectory
does not exist, it will be created.sourceDirectory
- The source directory to copytargetDirectory
- The target directory to copy toException
- If the source directory does not exist.public static void write(InputStream is, String fileName) throws IOException
IOException
public static void write(InputStream is, File f) throws IOException
IOException
public static void write(InputStream is, File f, int bufferSize) throws IOException
IOException
public static void write(File f, OutputStream outputStream) throws IOException
IOException
public static void write(File f, OutputStream outputStream, int bufferSize) throws IOException
IOException
public static void write(InputStream fis, OutputStream outputStream, int bufferSize) throws IOException
IOException
public static void write(byte[] data, String fileName) throws IOException
IOException
public static void write(byte[] data, File file) throws IOException
IOException
public static File[] findAllFilesInDirectoryRecursively(String dir)
File
array that will contain all the files that
exist in the specified directory or any nested directoriespublic static File[] findAllFilesInDirectory(String dir)
File
array that will contain all the files that exist in the directorypublic static String getFilenameWithoutExtension(String filename)
string
- public static String getExtension(File theFile)
File
. The extension is considered to be all the
characters after the last occurrence of FileUtils.Constants.FILE_EXTENSION_SEPARATOR_CHAR
in the pathname
of the input.theFile
- the file whose extension is being requestednull
if not foundpublic static String getExtension(String theFileName)
FileUtils.Constants.FILE_EXTENSION_SEPARATOR_CHAR
.theFileName
- the file whose extension is being requestednull
if not foundpublic static final boolean isArchiveFileName(String name)
public static final boolean isClassFileName(String name)
public static final boolean isJavaFileName(String name)
public static File convertByteArrayToFile(byte[] contents, String parentDirectoryPath, String fileName)
public static void removeDirectoryAndChildren(File directory)
public static void removeChildrenRecursively(File directory)
public static String buildDirectoryPath(String[] paths)
physicalDirectory
- appendLocation
- public static void rename(String oldFilePath, String newFilePath, boolean overwrite) throws IOException
oldFilePath
- newFilePath
- overwrite
- If true, overwrite the old file if it exists. If false, throw an exception if the old file exists.TeiidException
IOException
public static void remove(File file)
public static void remove(String filePath) throws IOException
IOException
Copyright © 2018 JBoss by Red Hat. All rights reserved.