Class GatewayUtils
java.lang.Object
com.inductiveautomation.ignition.gateway.util.GatewayUtils
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidautoBackupDirectory(File base, File sink, int count, String prefix) Creates an auto-backup folder underneath the base folder with all of the file contents of the base folder.static voidautoBackupDirectory(File base, File sink, int count, String prefix, FileFilter filter) static voidclearDirectory(File dir) Removes all files from the given directory, but not any subfoldersstatic voidclearDirectory(File dir, FileFilter filter) Removes all files from the given directory that match the criteria, but not any subfoldersstatic voidclearDirectoryDeep(File dir) Removes all files and subfolders from the given directory, but not the directory itselfstatic voidCopies all of the files (shallow) in the source folder into the destination folderstatic voidCopies the source file to the destination file, creating the destination if necessary.static voidcopyFile(InputStream fin, File dest) Copies all remaining bytes in the input stream to the output file, creating the destination file if necessary.static voidcreateFile(File contextFile, String filePath, byte[] fileData) Creates a file at ${contextFile}/filePath.static FileCreates a new, empty temp dir.static StringgetCertCommonName(X509Certificate certificate, boolean useIssuer) Returns the CN field in a certificate.static FilegetMostRecentAutobackupDirectory(File base, String prefix) static FileReturns a File representing a subdirectory, by following the paths from the base folder.static FilegetSubFile(File base, String filePath) Returns a subfile beneath directory.static Stringstatic voidnoCache(javax.servlet.http.HttpServletResponse res) Adds headers to a servlet response that should prevent it from caching at any levelstatic voidnoCache_IE6(javax.servlet.http.HttpServletResponse res) static voidremoveDirectory(File dir) Removes a directory, including all subfiles and subfolders recursivelystatic voidremoveDirectory(File contextFile, String dirPath) Removes the directory at ${contextFile}/dirPath.static booleanremoveFile(File contextFile, String filePath) Removes a file at ${contextFile}/filePath.static Stringstatic StringunzipFile(File zipFile, OutputStream output, String name) This version, which takes a direct file, is more efficient than using a stream.static byte[]Unzips the given file name from zip file at the path specified.static StringunzipFile(InputStream zipFile, OutputStream output, String name) Unzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this function.static byte[]unzipFile(InputStream zipFile, String name) Unzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this function.static StringunzipFile(ZipFile zip, OutputStream output, String name) static byte[]Unzips the given file name from the provided ZipFile.static booleanzipEntryExists(InputStream zipFile, String name) Returns true if the zip file contains an entry with the given name (case insensitive)static booleanzipEntryExists(ZipFile file, String name) 
- 
Constructor Details- 
GatewayUtilspublic GatewayUtils()
 
- 
- 
Method Details- 
noCachepublic static void noCache(javax.servlet.http.HttpServletResponse res) Adds headers to a servlet response that should prevent it from caching at any level
- 
noCache_IE6public static void noCache_IE6(javax.servlet.http.HttpServletResponse res) 
- 
createTempDirectoryCreates a new, empty temp dir. Does not delete automatically, make sure you remove it.- Throws:
- IOException
 
- 
autoBackupDirectorypublic static void autoBackupDirectory(File base, File sink, int count, String prefix) throws 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.txt calling 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 - Throws:
- IOException
 
- 
autoBackupDirectorypublic static void autoBackupDirectory(File base, File sink, int count, String prefix, FileFilter filter) throws IOException - Throws:
- IOException
 
- 
getMostRecentAutobackupDirectory
- 
copyAllCopies all of the files (shallow) in the source folder into the destination folder- Throws:
- IOException
 
- 
copyFileCopies the source file to the destination file, creating the destination if necessary.- Throws:
- IOException
 
- 
copyFileCopies all remaining bytes in the input stream to the output file, creating the destination file if necessary. Input steam is not closed.- Throws:
- IOException
 
- 
getSubDirReturns a File representing a subdirectory, by following the paths from the base folder. For example, if base is "C:\Program Files\Inductive Automation\SCADARail\" and you send "abc", "xyz" as subDirs, you'll get the following File back: "C:\Program Files\Inductive Automation\SCADARail\abc\xyz\"- Parameters:
- base- A File that represents the starting folders.
- subDirs- Names of folders to follow from the base.
 
- 
getSubFileReturns a subfile beneath directory. The filePath may contain multiple levels, separated by "/"
- 
removeDirectoryRemoves a directory, including all subfiles and subfolders recursively
- 
clearDirectoryDeepRemoves all files and subfolders from the given directory, but not the directory itself
- 
clearDirectoryRemoves all files from the given directory, but not any subfolders
- 
clearDirectoryRemoves all files from the given directory that match the criteria, but not any subfolders
- 
createFilepublic static void createFile(File contextFile, String filePath, byte[] fileData) throws IOException Creates a file at ${contextFile}/filePath. The passed contextFile must be a File object that can be returned from the context, such as context.getDataDir() or context.getUserlibDir(). File path should be like "abc.txt" or "folder/abc.txt"- Throws:
- IOException
 
- 
removeFileRemoves a file at ${contextFile}/filePath. The passed contextFile must be a File object that can be returned from the context, such as context.getDataDir() or context.getUserlibDir().
- 
removeDirectoryRemoves the directory at ${contextFile}/dirPath. The passed contextFile must be a File object that can be returned from the context, such as context.getDataDir() or context.getUserlibDir().
- 
unzipFileUnzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this function.- Parameters:
- name- the filename entry in the zip file to extract.
- Returns:
- a byte[] representing the file
- Throws:
- IOException- if the name was not found, or if any other IOException occurrs
 
- 
unzipFileUnzips the given file name from zip file at the path specified.- Parameters:
- zipFile- the path to a file, which should be a zip file.
- name- the filename entry in the zip file to extract.
- Returns:
- a byte[] representing the file
- Throws:
- IOException- if the name was not found, or if any other IOException occurrs
 
- 
unzipFileUnzips the given file name from the provided ZipFile.- Parameters:
- zipFile- the ZipFile representation of a zip.
- name- the filename entry in the zip file to extract.
- Returns:
- a byte[] representing the file
- Throws:
- IOException- if the name was not found, or if any other IOException occurrs
 
- 
unzipFilepublic static String unzipFile(InputStream zipFile, OutputStream output, String name) throws IOException Unzips the given file from the given input stream, which will be wrapped in a ZipInputStream within this function. The file will be written to the given outputstream. The streams will be closed.- Parameters:
- 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.
- Returns:
- the full name of the entry. Useful when using wildcard names, to see what the actual entry was.
- Throws:
- IOException- On IO error or if the entry isn't found.
 
- 
unzipFileThis version, which takes a direct file, is more efficient than using a stream.- Throws:
- IOException
 
- 
unzipFile- Throws:
- IOException
 
- 
zipEntryExistsReturns true if the zip file contains an entry with the given name (case insensitive)- Throws:
- IOException
 
- 
zipEntryExists
- 
md5
- 
sha256
- 
getCertCommonNameReturns the CN field in a certificate. If useIssuer is true, then the issuer's CN field is used. Otherwise, the subject's CN field is used- Parameters:
- certificate- the certificate to extract CN from.
- useIssuer- if- true, extract the issuer CN; otherwise the subject SN.
- Returns:
- either the issuer or subject CN, depending on useIssuer.
 
 
-