|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dawb.common.util.io.FileUtils
public final class FileUtils
A class with a collection of file management static utility classes. Several method contents copied from code snippets available on the web.
Field Summary | |
---|---|
static char |
BOM
|
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
copy(java.io.File source_file,
java.io.File destination_file)
Overwrites destination_file if it exists, creates new if not. |
static void |
copy(java.io.File source_file,
java.io.File destination_file,
byte[] buffer)
Overwrites destination_file if it exists, creates new if not. |
static void |
copy(java.io.File source_file,
java.lang.String destination_dir)
|
static void |
copyNio(java.io.File source_file,
java.io.File destination_file)
|
static void |
copyNioNoCopyOver(java.io.File source_file,
java.io.File destination_file)
|
static java.io.File |
createNewUniqueDir(java.io.File file)
|
static java.io.File |
createNewUniqueDir(java.io.File file,
java.lang.String templateName)
|
static void |
deleteContents(java.io.File parent)
|
static java.lang.String |
formatSize(long longSize,
int decimalPos)
Formats a file size |
static byte[] |
getByteArrayFromStream(java.io.InputStream source)
|
static byte[] |
getByteArrayFromStream(java.io.InputStream source,
boolean shouldClose)
|
static java.io.ByteArrayOutputStream |
getByteStream(java.io.InputStream source)
|
static java.io.ByteArrayOutputStream |
getByteStream(java.io.InputStream source,
boolean shouldClose)
|
static java.lang.String |
getDirectory(java.lang.String filePath)
|
static long |
getDiskSpace(java.io.File dir)
|
static java.lang.String |
getFileExtension(java.io.File file)
Get File extension (result will NOT include ".") |
static java.lang.String |
getFileExtension(java.lang.String fileName)
Get File extension (result will NOT include ".") |
static java.lang.String |
getFileNameNoExtension(java.io.File file)
Get Filename minus it's extension if present |
static long |
getFileSizeRecursive(java.io.File file,
boolean subFolders)
|
static java.lang.String |
getParentDirName(java.lang.String name)
|
static java.io.File |
getUnique(java.io.File dir,
java.lang.String template,
java.lang.String ext)
Generates a unique file of the name template or template+an integer |
static java.io.File |
getUnique(java.io.File dir,
java.lang.String template,
java.lang.String ext,
int i)
|
static boolean |
isBOM(java.lang.String stringToTest)
Returns true if the string is starting with a BOM |
static boolean |
isDiskSpaceAvaliable(java.io.File tmp,
long sizeInB)
|
static boolean |
isDiskSpaceAvaliableMB(java.io.File tmp,
long sizeInMB)
|
static boolean |
isUnix(java.lang.String stringToTest)
This method returns true if file is Unix and false if Windows line endings. |
static java.lang.StringBuffer |
readFile(java.io.File file)
|
static java.lang.StringBuffer |
readFile(java.io.InputStream in)
|
static java.lang.StringBuffer |
readFile(java.io.InputStream in,
java.lang.String charsetName)
|
static java.util.List<java.lang.String> |
readFileAsList(java.io.File f)
|
static java.util.List<java.lang.String> |
readFileAsList(java.io.File file,
java.lang.String encodingOfFile,
boolean removeBom,
boolean trimLines)
Reads a file using the encoding parameter passed and returns each line as an item in the result list Optionally: the BOM can be removed (first character of file if present) the line can be trimmed of whitespace |
static void |
recursiveCopy(java.io.File source_dir,
java.io.File destination_dir)
Recursively copy one folder to another Deleting the contents of the destination folder before copying. |
static void |
recursiveCopyNio(java.io.File source_dir,
java.io.File destination_dir)
Recursively copy one folder to another Deleting the contents of the destination folder before copying. |
static void |
recursiveCopyNioNoDelete(java.io.File source_dir,
java.io.File destination_dir)
Recursively copy one folder to another Not deleting the contents of the destination folder before copying. |
static boolean |
recursiveDelete(java.io.File parent)
|
static void |
recursiveDeleteOnExit(java.io.File parent)
Recursively delete parent folder on exit of JVM |
static void |
recursiveIncrementalCopy(java.io.File source_dir,
java.io.File destination_dir)
Recursively copy one folder to another, but not deleting destination data. |
static void |
recursiveIncrementalCopy(java.io.File source_dir,
java.io.File destination_dir,
int[] inf)
Recursively copy one folder to another, but not deleting destination data. |
static java.lang.String |
setExtension(java.lang.String path,
java.lang.String ext)
|
static void |
write(java.io.BufferedInputStream source,
java.io.File destination_file)
|
static void |
write(java.io.File file,
java.util.List<java.lang.String> list)
|
static void |
write(java.io.File file,
java.lang.String text)
This method attempts to write a string to file in US-ASCII. |
static void |
write(java.io.File file,
java.lang.String text,
java.lang.String encoding)
|
static void |
write(java.io.InputStream source_raw,
java.io.OutputStream destination_raw)
|
static void |
write(java.io.OutputStream out,
java.lang.String text,
java.lang.String charset,
boolean addBomIfNeeded)
This method writes to a stream a potentially large String. |
static void |
writeToFile(java.io.File file,
java.io.InputStream fromNoClose)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char BOM
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static final boolean recursiveDelete(java.io.File parent)
parent
-
public static final void deleteContents(java.io.File parent)
parent
- public static java.io.File getUnique(java.io.File dir, java.lang.String template, java.lang.String ext)
dir
- template
- ext
-
public static java.io.File getUnique(java.io.File dir, java.lang.String template, java.lang.String ext, int i)
dir
- template
- ext
- i
-
public static final void recursiveDeleteOnExit(java.io.File parent)
parent
- public static final void recursiveCopy(java.io.File source_dir, java.io.File destination_dir) throws java.io.IOException
source_dir
- destination_dir
-
java.io.IOException
public static final void recursiveCopyNio(java.io.File source_dir, java.io.File destination_dir) throws java.io.IOException
source_dir
- destination_dir
-
java.io.IOException
public static final void recursiveCopyNioNoDelete(java.io.File source_dir, java.io.File destination_dir) throws java.io.IOException
source_dir
- destination_dir
-
java.io.IOException
public static final void recursiveIncrementalCopy(java.io.File source_dir, java.io.File destination_dir) throws java.io.IOException
source_dir
- destination_dir
-
java.io.IOException
public static final void recursiveIncrementalCopy(java.io.File source_dir, java.io.File destination_dir, int[] inf) throws java.io.IOException
source_dir
- destination_dir
- inf
-
java.io.IOException
public static final void copy(java.io.File source_file, java.lang.String destination_dir) throws java.io.IOException
source_file
- destination_dir
-
java.io.IOException
public static final void copy(java.io.File source_file, java.io.File destination_file) throws java.io.IOException
source_file
- destination_file
-
java.io.IOException
public static final void copy(java.io.File source_file, java.io.File destination_file, byte[] buffer) throws java.io.IOException
source_file
- destination_file
- buffer
-
java.io.IOException
public static final void copyNio(java.io.File source_file, java.io.File destination_file) throws java.io.IOException
source_file
- destination_file
-
java.io.IOException
public static final void copyNioNoCopyOver(java.io.File source_file, java.io.File destination_file) throws java.io.IOException
source_file
- destination_file
-
java.io.IOException
public static final void write(java.io.BufferedInputStream source, java.io.File destination_file) throws java.io.IOException
source
- destination_file
-
java.io.IOException
public static final void write(java.io.InputStream source_raw, java.io.OutputStream destination_raw) throws java.io.IOException
source_raw
- destination_raw
-
java.io.IOException
public static final byte[] getByteArrayFromStream(java.io.InputStream source) throws java.io.IOException
source
-
java.io.IOException
public static final byte[] getByteArrayFromStream(java.io.InputStream source, boolean shouldClose) throws java.io.IOException
source
- shouldClose
-
java.io.IOException
public static final java.io.ByteArrayOutputStream getByteStream(java.io.InputStream source) throws java.io.IOException
source
-
java.io.IOException
public static final java.io.ByteArrayOutputStream getByteStream(java.io.InputStream source, boolean shouldClose) throws java.io.IOException
source
- shouldClose
-
java.io.IOException
public static final java.lang.StringBuffer readFile(java.io.File file) throws java.lang.Exception
file
-
java.lang.Exception
public static final java.lang.StringBuffer readFile(java.io.InputStream in) throws java.lang.Exception
in
-
java.lang.Exception
public static final java.lang.StringBuffer readFile(java.io.InputStream in, java.lang.String charsetName) throws java.lang.Exception
in
- charsetName
-
java.lang.Exception
public static final java.util.List<java.lang.String> readFileAsList(java.io.File f) throws java.lang.Exception
f
-
java.lang.Exception
public static final java.util.List<java.lang.String> readFileAsList(java.io.File file, java.lang.String encodingOfFile, boolean removeBom, boolean trimLines) throws java.io.IOException
file
- The file to readencodingOfFile
- The encoding format the file should be read asremoveBom
- Whether the BOM should be removed, if present.trimLines
- If each line should have leading and trailing whitespace removed
java.io.IOException
- If the file can not be readpublic static boolean isUnix(java.lang.String stringToTest)
stringToTest
- The text of the file
public static boolean isBOM(java.lang.String stringToTest)
stringToTest
-
public static void write(java.io.File file, java.lang.String text, java.lang.String encoding) throws java.lang.Exception
file
- text
- encoding
-
java.lang.Exception
public static void write(java.io.File file, java.lang.String text) throws java.lang.Exception
file
- text
-
java.lang.Exception
public static void write(java.io.OutputStream out, java.lang.String text, java.lang.String charset, boolean addBomIfNeeded) throws java.lang.Exception
out
- text
- charset
- addBomIfNeeded
-
java.lang.Exception
public static void write(java.io.File file, java.util.List<java.lang.String> list) throws java.lang.Exception
file
- list
-
java.lang.Exception
public static java.io.File createNewUniqueDir(java.io.File file)
file
-
public static java.io.File createNewUniqueDir(java.io.File file, java.lang.String templateName)
file
- templateName
-
public static final java.lang.String getParentDirName(java.lang.String name)
name
-
public static final void writeToFile(java.io.File file, java.io.InputStream fromNoClose) throws java.lang.Exception
file
- fromNoClose
-
java.lang.Exception
public static long getDiskSpace(java.io.File dir)
dir
-
public static boolean isDiskSpaceAvaliableMB(java.io.File tmp, long sizeInMB) throws java.io.IOException
tmp
- sizeInMB
-
java.io.IOException
public static boolean isDiskSpaceAvaliable(java.io.File tmp, long sizeInB) throws java.io.IOException
tmp
- sizeInB
-
java.io.IOException
public static long getFileSizeRecursive(java.io.File file, boolean subFolders)
file
- subFolders
-
public static java.lang.String getFileExtension(java.lang.String fileName)
fileName
-
public static java.lang.String getFileExtension(java.io.File file)
file
-
public static java.lang.String getFileNameNoExtension(java.io.File file)
file
- File to get filename from
public static java.lang.String formatSize(long longSize, int decimalPos)
longSize
- decimalPos
-
public static java.lang.String setExtension(java.lang.String path, java.lang.String ext)
public static java.lang.String getDirectory(java.lang.String filePath)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |