public class GatewayUtils
extends java.lang.Object
Constructor and Description |
---|
GatewayUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
autoBackupDirectory(java.io.File base,
java.io.File sink,
int count,
java.lang.String prefix)
Creates an auto-backup folder underneath the base folder with all of the file contents of the base folder.
|
static void |
autoBackupDirectory(java.io.File base,
java.io.File sink,
int count,
java.lang.String prefix,
java.io.FileFilter filter) |
static void |
clearDirectory(java.io.File dir)
Removes all files from the given directory, but not any subfolders
|
static void |
clearDirectory(java.io.File dir,
java.io.FileFilter filter)
Removes all files from the given directory that match the criteria, but not any subfolders
|
static void |
clearDirectoryDeep(java.io.File dir)
Removes all files and subfolders from the given directory, but not the directory itself
|
static void |
copyAll(java.io.File sourceFolder,
java.io.File destFolder)
Copies all of the files (shallow) in the source folder into the destination folder
|
static void |
copyFile(java.io.File source,
java.io.File dest)
Copies the source file to the destination file, creating the destination if necessary.
|
static void |
copyFile(java.io.InputStream fin,
java.io.File dest)
Copies all remaining bytes in the input stream to the output file, creating the destination file if necessary.
|
static void |
createFile(java.io.File contextFile,
java.lang.String filePath,
byte[] fileData)
Creates a file at ${contextFile}/filePath.
|
static java.io.File |
createTempDirectory()
Creates a new, empty temp dir.
|
static java.lang.String |
getCertCommonName(java.security.cert.X509Certificate certificate,
boolean useIssuer)
Returns the CN field in a certificate.
|
static java.io.File |
getMostRecentAutobackupDirectory(java.io.File base,
java.lang.String prefix) |
static java.io.File |
getSubDir(java.io.File base,
java.lang.String... subDirs)
Returns a File representing a subdirectory, by following the paths from the base folder.
|
static java.io.File |
getSubFile(java.io.File base,
java.lang.String filePath)
Returns a subfile beneatha directory.
|
static java.lang.String |
md5(java.lang.String source) |
static void |
noCache_IE6(javax.servlet.http.HttpServletResponse res) |
static void |
noCache(javax.servlet.http.HttpServletResponse res)
Adds headers to a servlet response that should prevent it from caching at any level
|
static void |
removeDirectory(java.io.File dir)
Removes a directory, including all subfiles and subfolders recursively
|
static void |
removeDirectory(java.io.File contextFile,
java.lang.String dirPath)
Removes the directory at ${contextFile}/dirPath.
|
static boolean |
removeFile(java.io.File contextFile,
java.lang.String filePath)
Removes a file at ${contextFile}/filePath.
|
static java.lang.String |
sha256(java.lang.String source) |
static java.lang.String |
unzipFile(java.io.InputStream zipFile,
java.io.OutputStream output,
java.lang.String name)
Unzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this
function.
|
static byte[] |
unzipFile(java.io.InputStream zipFile,
java.lang.String name)
Unzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this
function.
|
static boolean |
zipEntryExists(java.io.InputStream zipFile,
java.lang.String name)
Retruns true if the zip file contains an entry with the given name (case insensitive)
|
public static void noCache(javax.servlet.http.HttpServletResponse res)
public static void noCache_IE6(javax.servlet.http.HttpServletResponse res)
public static java.io.File createTempDirectory() throws java.io.IOException
java.io.IOException
public static void autoBackupDirectory(java.io.File base, java.io.File sink, int count, java.lang.String prefix) throws java.io.IOException
Creates an auto-backup folder underneath the base folder with all of the file contents of the base folder. Using naming conventions, aims to keep a maximum of count autobackup directories at any one time.
For instance, given the following folder structure,
folder/ folder/file1.xyz folder/file2.txtcalling autobackup on Nov 3rd, 2008 at 2:30:59PM would make this:
folder/ folder/file1.xyz folder/file2.txt folder/autobackup_20081103_143059/ folder/autobackup_20081103_143059/file1.xyz folder/autobackup_20081103_143059/file2.txt
java.io.IOException
public static void autoBackupDirectory(java.io.File base, java.io.File sink, int count, java.lang.String prefix, java.io.FileFilter filter) throws java.io.IOException
java.io.IOException
public static java.io.File getMostRecentAutobackupDirectory(java.io.File base, java.lang.String prefix)
public static void copyAll(java.io.File sourceFolder, java.io.File destFolder) throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.File source, java.io.File dest) throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.InputStream fin, java.io.File dest) throws java.io.IOException
fin
- dest
- java.io.IOException
public static java.io.File getSubDir(java.io.File base, java.lang.String... subDirs)
base
- A File that represents the starting folders.subDirs
- Names of folders to follow from the base.public static java.io.File getSubFile(java.io.File base, java.lang.String filePath)
public static void removeDirectory(java.io.File dir)
public static void clearDirectoryDeep(java.io.File dir)
public static void clearDirectory(java.io.File dir)
public static void clearDirectory(java.io.File dir, java.io.FileFilter filter)
public static void createFile(java.io.File contextFile, java.lang.String filePath, byte[] fileData) throws java.io.IOException
contextFile
- filePath
- fileData
- java.io.IOException
public static boolean removeFile(java.io.File contextFile, java.lang.String filePath)
contextFile
- filePath
- public static void removeDirectory(java.io.File contextFile, java.lang.String dirPath)
dirPath
- public static byte[] unzipFile(java.io.InputStream zipFile, java.lang.String name) throws java.io.IOException
zipFile
- name
- java.io.IOException
- if the name was not found, or if any other IOException occurrspublic static java.lang.String unzipFile(java.io.InputStream zipFile, java.io.OutputStream output, java.lang.String name) throws java.io.IOException
zipFile
- An input stream for the zip file. Should not be a ZipInputStream. Will be closed.output
- An output stream to write the bytes to.name
- Path to the file. If the name ends in '*', the first matching entry that starts with the name will be used.java.io.IOException
- On IO error or if the entry isn't found.public static boolean zipEntryExists(java.io.InputStream zipFile, java.lang.String name) throws java.io.IOException
java.io.IOException
public static java.lang.String md5(java.lang.String source)
public static java.lang.String sha256(java.lang.String source)
public static java.lang.String getCertCommonName(java.security.cert.X509Certificate certificate, boolean useIssuer)
certificate
- the certificate to extract CN from.useIssuer
- if true
, extract the issuer CN; otherwise the subject SN.useIssuer
.