public class FileUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
BACKWARD_SLASH
Standard backslash
|
protected static String |
m_tempDirectory |
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyFile(String fromFileName,
String toFileName,
boolean moveIt)
Copies a file to other location
|
static int |
copyStream(InputStream inputStream,
OutputStream outputStream)
Copies all the bits from the inputStream to the ouputStream
|
static File |
createTempDir()
Atomically creates a new directory somewhere beneath the system's
temporary directory (as defined by the
java.io.tmpdir system
property), and returns its name. |
static String |
ensureForwardSlashes(String path)
Changes backward slashes to forward slashes.
|
static String |
ensureTrailingSlash(String path)
Ensures the directory path has trailing slash
|
static void |
expandArchive(String archiveFileName,
String outputFolder)
Expands the whole archive (zip, jar, war) into a folder.
|
static void |
expandArchive(String archiveFileName,
String outputFolder,
FilenameFilter filenameFilter)
Expands a filtered set of fiels from the archive (zip, jar, war) into a folder.
|
static byte[] |
getContentToBytes(InputStream inStream)
Reads entire file into byte array.
|
static String |
getContentToString(InputStream inStream)
Reads entire file into the string
|
static String |
getTempDirectory()
Returns the system's temporary directory.
|
static String |
normalizeFileName(String fileName)
Any character in the filename that is not a dot, letter or digit is
replaced with '_'
|
static void |
removeDir(File dir)
Removes the folder with all files and subfolders
|
static void |
zipUp(String path,
File file,
ZipOutputStream archive)
Recursively adds the specified src file or directory into the specified dst archive
using the specified path within the archive.
|
static void |
zipUp(String directory,
String archive)
Recursively zips the specified src directory into the specified dst archive,
overwriting the archive if it already exists.
|
protected static String m_tempDirectory
FileUtil.getTempDirectory()
public static final String BACKWARD_SLASH
public static String getContentToString(InputStream inStream) throws IOException
inStream
- InputStream to be converted to StringIOException
- conversion failspublic static byte[] getContentToBytes(InputStream inStream) throws IOException
inStream
- InputStream to be converted to byte[]IOException
- conversion failurepublic static String getTempDirectory() throws IOException
IOException
public static String ensureTrailingSlash(String path)
path
- temporary directory pathpublic static String ensureForwardSlashes(String path)
path
- string to modifypublic static String normalizeFileName(String fileName)
fileName
- the source filenamepublic static int copyStream(InputStream inputStream, OutputStream outputStream) throws IOException
inputStream
- the source of the bits to be copiedoutputStream
- the destination for the copied bits.IOException
public static void removeDir(File dir) throws IOException
IOException
public static File createTempDir()
java.io.tmpdir
system
property), and returns its name.
Use this method instead of File.createTempFile(String, String)
when you wish to create a directory, not a regular file. A common pitfall
is to call createTempFile
, delete the file and create a
directory in its place, but this leads a race condition which can be
exploited to create security vulnerabilities, especially when executable
files are to be written into the directory.
This method assumes that the temporary volume is writable, has free inodes and free blocks, and that it will not be called thousands of times per second.
IllegalStateException
- if the directory could not be createdpublic static void copyFile(String fromFileName, String toFileName, boolean moveIt) throws IOException
IOException
public static void expandArchive(String archiveFileName, String outputFolder) throws IOException
archiveFileName
- the source fileoutputFolder
- the output folderIOException
public static void expandArchive(String archiveFileName, String outputFolder, FilenameFilter filenameFilter) throws IOException
archiveFileName
- the source fileoutputFolder
- the output folderthe
- filenameFilter to filter which files are includedIOException
public static void zipUp(String directory, String archive) throws IOException
IOException
public static void zipUp(String path, File file, ZipOutputStream archive) throws IOException
IOException