Class GatewayUtils

java.lang.Object
com.inductiveautomation.ignition.gateway.util.GatewayUtils

public class GatewayUtils extends Object
  • Constructor Details

    • GatewayUtils

      public GatewayUtils()
  • Method Details

    • noCache

      public static void noCache(javax.servlet.http.HttpServletResponse res)
      Adds headers to a servlet response that should prevent it from caching at any level
    • noCache_IE6

      public static void noCache_IE6(javax.servlet.http.HttpServletResponse res)
    • createTempDirectory

      public static File createTempDirectory() throws IOException
      Creates a new, empty temp dir. Does not delete automatically, make sure you remove it.
      Throws:
      IOException
    • autoBackupDirectory

      public 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
    • autoBackupDirectory

      public static void autoBackupDirectory(File base, File sink, int count, String prefix, FileFilter filter) throws IOException
      Throws:
      IOException
    • getMostRecentAutobackupDirectory

      public static File getMostRecentAutobackupDirectory(File base, String prefix)
    • copyAll

      public static void copyAll(File sourceFolder, File destFolder) throws IOException
      Copies all of the files (shallow) in the source folder into the destination folder
      Throws:
      IOException
    • copyFile

      public static void copyFile(File source, File dest) throws IOException
      Copies the source file to the destination file, creating the destination if necessary.
      Throws:
      IOException
    • copyFile

      public static void copyFile(InputStream fin, File dest) throws IOException
      Copies all remaining bytes in the input stream to the output file, creating the destination file if necessary. Input steam is not closed.
      Throws:
      IOException
    • getSubDir

      public static File getSubDir(File base, String... subDirs)
      Returns 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.
    • getSubFile

      public static File getSubFile(File base, String filePath)
      Returns a subfile beneath directory. The filePath may contain multiple levels, separated by "/"
    • removeDirectory

      public static void removeDirectory(File dir)
      Removes a directory, including all subfiles and subfolders recursively
    • clearDirectoryDeep

      public static void clearDirectoryDeep(File dir)
      Removes all files and subfolders from the given directory, but not the directory itself
    • clearDirectory

      public static void clearDirectory(File dir)
      Removes all files from the given directory, but not any subfolders
    • clearDirectory

      public static void clearDirectory(File dir, FileFilter filter)
      Removes all files from the given directory that match the criteria, but not any subfolders
    • createFile

      public 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
    • removeFile

      public static boolean removeFile(File contextFile, String filePath)
      Removes 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().
    • removeDirectory

      public static void removeDirectory(File contextFile, String dirPath)
      Removes 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().
    • unzipFile

      public static byte[] unzipFile(InputStream zipFile, String name) throws IOException
      Unzips 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
    • unzipFile

      public static byte[] unzipFile(File zipFile, String name) throws IOException
      Unzips 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
    • unzipFile

      public static byte[] unzipFile(ZipFile zipFile, String name) throws IOException
      Unzips 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
    • unzipFile

      public 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.
    • unzipFile

      public static String unzipFile(File zipFile, OutputStream output, String name) throws IOException
      This version, which takes a direct file, is more efficient than using a stream.
      Throws:
      IOException
    • unzipFile

      public static String unzipFile(ZipFile zip, OutputStream output, String name) throws IOException
      Throws:
      IOException
    • zipEntryExists

      public static boolean zipEntryExists(InputStream zipFile, String name) throws IOException
      Returns true if the zip file contains an entry with the given name (case insensitive)
      Throws:
      IOException
    • zipEntryExists

      public static boolean zipEntryExists(ZipFile file, String name)
    • md5

      public static String md5(String source)
    • sha256

      public static String sha256(String source)
    • getCertCommonName

      public static String getCertCommonName(X509Certificate certificate, boolean useIssuer)
      Returns 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.