public class ResourceUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_ISO |
| Constructor and Description |
|---|
ResourceUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
appendFile(java.lang.String fileName1,
java.lang.String fileName2)
Appends file2 to file1
|
static boolean |
appendFileWithSize(java.lang.String fileName1,
java.lang.String fileName2)
Appends file2 to file1 and stores the size of file1 at the end as an 10
byte ascii number.
|
static void |
backupFile(java.lang.String sourceFileName,
java.lang.String destFileName,
boolean forceOverwrite)
backup a file.
|
static byte[] |
blockReadInputStream(java.io.InputStream inputStream,
int sizeToRead) |
static void |
copyFile(java.io.File sourceFile,
java.io.File destFile)
copy a file.
|
static void |
copyFile(java.lang.String sourceFileName,
java.io.File destFile)
copy a file.
|
static void |
copyFile(java.lang.String sourceFileName,
java.lang.String destFileName)
copy a file.
|
static void |
copyFileStreams(java.io.FileInputStream fis,
java.io.FileOutputStream fos)
Copy a FileInputStream to a FileOutputStream.
|
static java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.lang.String path)
Creates a new file
|
static void |
delete(java.lang.String fileName) |
static boolean |
deleteDir(java.io.File dir)
Deletes all files and subdirectories under dir.
|
static java.io.File |
getFile(java.lang.String resource)
Gets a URL(String) getFile replacing all %20 characters with spaces
|
static java.io.File |
getFile(java.net.URL resource)
Gets a URL getFile replacing all %20 characters with spaces
|
static java.io.File[] |
getFileList(java.lang.String fileLocation) |
static java.io.File[] |
getFileList(java.lang.String fileLocation,
java.lang.String filter) |
static java.io.InputStream |
getInputStream(java.lang.String resourceFileName)
Gets an InputStream from a File or from a Resource
|
static java.net.URL |
getResourceURL(org.springframework.context.ApplicationContext appContext,
java.lang.String resourceName,
java.lang.Class<?> clas)
Get a URL for a given resource.
|
static java.net.URL |
getResourceURL(java.lang.String resourceName)
Get a URL for a giver resource.
|
static java.io.File |
getTempFolder(java.lang.String appendFolderName)
Returns a tempory folder where tempory files can be stored.
|
static byte[] |
loadBinaryFile(java.lang.String fileName) |
static java.lang.String |
loadFile(java.lang.String fileName) |
static java.lang.String |
loadFileWithISO(java.lang.String fileName,
java.lang.String iso)
Load a file and apply the iso value when doing the byte to String
conversion
|
static java.util.Properties |
loadProperties(java.lang.String fileName) |
static java.lang.String |
loadXMLFileWithISO(java.lang.String fileName)
This will load a file assuming it's an XML file, then look for an ISO
declaration and if found will convert the string using that ISO value.
|
static int |
mkdir(java.io.File folder)
mkdir for folderName and set the lastModifiedDate to lastModifiedDate
|
static int |
mkdir(java.lang.String folderName,
long lastModifiedDate)
mkdir for folderName and set the lastModifiedDate to lastModifiedDate
|
static int |
mkdirs(java.io.File folder)
mkdirs for folderName
|
static java.lang.String |
mkdirsToday(java.lang.String pathName)
creates a new folder named "yyyy-MM-dd" and appends this onto the
pathName, then creates the folder.
|
static byte[] |
readInputStream(java.io.InputStream inputStream) |
static boolean |
renameFile(java.lang.String fileNameAndPath,
java.lang.String newFileNameAndPath,
boolean overWrite)
Rename a file to a new file name and path
|
static void |
saveBinaryFile(java.lang.String fileName,
byte[] buffer) |
static void |
saveFile(java.lang.String fileName,
java.lang.String buffer) |
static void |
setLastModified(java.lang.String fileName,
long modifiedTime) |
static void |
sortFiles(java.io.File[] files) |
public static final java.lang.String DEFAULT_ISO
public static java.lang.String loadFile(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String loadFileWithISO(java.lang.String fileName,
java.lang.String iso)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String loadXMLFileWithISO(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic static byte[] loadBinaryFile(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic static void saveFile(java.lang.String fileName,
java.lang.String buffer)
throws java.io.IOException
java.io.IOExceptionpublic static void saveBinaryFile(java.lang.String fileName,
byte[] buffer)
throws java.io.IOException
java.io.IOExceptionpublic static void delete(java.lang.String fileName)
throws java.lang.Exception
java.lang.Exceptionpublic static boolean deleteDir(java.io.File dir)
public static java.io.File[] getFileList(java.lang.String fileLocation,
java.lang.String filter)
throws java.lang.Exception
java.lang.Exceptionpublic static java.io.File[] getFileList(java.lang.String fileLocation)
throws java.lang.Exception
java.lang.Exceptionpublic static void setLastModified(java.lang.String fileName,
long modifiedTime)
throws java.lang.Exception
java.lang.Exceptionpublic static boolean renameFile(java.lang.String fileNameAndPath,
java.lang.String newFileNameAndPath,
boolean overWrite)
fileNameAndPath - is the existing filenewFileNameAndPath - is what we rename it tooverWrite - if set true will overwrite an existing file, false wont.public static boolean appendFile(java.lang.String fileName1,
java.lang.String fileName2)
throws java.lang.Exception
fileName1 - is the name of the file to append file2 onto. If file1 does
not exist it is created.fileName2 - is the name of an existing file to append to file1. if file2
does not exist an exception is thrownjava.lang.Exceptionpublic static boolean appendFileWithSize(java.lang.String fileName1,
java.lang.String fileName2)
throws java.lang.Exception
fileName1 - is the name of an existing file to append to file2fileName2 - is the name of the file to append file1 onto. If file2 does
not exist it is created.java.lang.Exceptionpublic static java.util.Properties loadProperties(java.lang.String fileName)
throws java.lang.Exception
java.lang.Exceptionpublic static byte[] readInputStream(java.io.InputStream inputStream)
throws java.io.IOException
java.io.IOExceptionpublic static byte[] blockReadInputStream(java.io.InputStream inputStream,
int sizeToRead)
throws java.lang.Exception
java.lang.Exceptionpublic static void backupFile(java.lang.String sourceFileName,
java.lang.String destFileName,
boolean forceOverwrite)
throws java.lang.Exception
sourceFileName - is the file we want to backup.destFileName - is the new name of the file, can contain a new path also.forceOverwrite - if set true will backup the source file over an existing
destination file.java.lang.Exceptionpublic static void copyFileStreams(java.io.FileInputStream fis,
java.io.FileOutputStream fos)
throws java.lang.Exception
fis - is the FileInputStream to copy from.fos - is the FileOutputStream to copy to.java.lang.Exception - if something goes wrong.public static void copyFile(java.lang.String sourceFileName,
java.lang.String destFileName)
throws java.lang.Exception
sourceFileName - is the file we want to copy.destFileName - is the name of the copy to file, can contain a new path also.java.lang.Exceptionpublic static void copyFile(java.lang.String sourceFileName,
java.io.File destFile)
throws java.lang.Exception
sourceFileName - is the file we want to copy.destFile - is the destination file to copy to.java.lang.Exceptionpublic static void copyFile(java.io.File sourceFile,
java.io.File destFile)
throws java.lang.Exception
sourceFile - is the file we want to copy.destFile - is the destination file to copy to.java.lang.Exceptionpublic static int mkdir(java.lang.String folderName,
long lastModifiedDate)
public static int mkdir(java.io.File folder)
public static int mkdirs(java.io.File folder)
public static java.lang.String mkdirsToday(java.lang.String pathName)
pathName - is the path to the folder.public static void sortFiles(java.io.File[] files)
public static java.io.File getTempFolder(java.lang.String appendFolderName)
appendFolderName - is the folder to be created inside the tempory folder
location.public static java.io.File createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.lang.String path)
throws java.lang.Exception
prefix - is the prefix used for the file name must be at least 3
characterssuffix - is the file extension and may be null in which case '.tmp' is
usedpath - is the folder path where the file will be createdjava.lang.Exception - if something goes wrong.public static java.net.URL getResourceURL(java.lang.String resourceName)
resourceName - public static java.net.URL getResourceURL(org.springframework.context.ApplicationContext appContext,
java.lang.String resourceName,
java.lang.Class<?> clas)
resourceName - public static java.io.File getFile(java.net.URL resource)
public static java.io.File getFile(java.lang.String resource)
public static java.io.InputStream getInputStream(java.lang.String resourceFileName)
throws java.io.IOException
resourceFileName - a reference to the file or resource.java.io.IOException