Class BootstrapUtilities
- java.lang.Object
-
- com.inductiveautomation.ignition.client.launch.BootstrapUtilities
-
public class BootstrapUtilities extends java.lang.Object
Created by carl.gould on 1/29/2015.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BootstrapUtilities.LaunchJarResults
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanDirectory(java.io.File directory)
Cleans a directory without deleting it.static void
copyFile(java.io.File in, java.io.File out)
static long
crc(java.io.File jarFile)
static void
deleteDirectory(java.io.File directory)
Deletes a directory recursively.static long
downloadFile(java.net.URL url, int readTimeout, java.io.File destination)
Downloads the file that exists at the url and saves it to the supplied destination file.static void
forceDelete(java.io.File file)
static java.io.File
getJarParentFolder(java.io.File resourcesDir, LaunchManifest.Module m, LaunchManifest.Jar j)
Given the root of the cache/resources/ folder, returns the correct parent folder for a given jar file, right before the specific CRC subfolders.static java.lang.String
getStringResponse(java.net.URL url, int readTimeout)
static BootstrapUtilities.LaunchJarResults
launchJarCompatible(GatewayAddress target, java.io.File launchJar)
Checks if the supplied launch jar matches in length and crc32 checksum by getting the required length and checksum from the target gateway and comparing against the file.static java.lang.String
md5(java.io.File file)
static java.net.HttpURLConnection
newConnection(java.net.URL url, int readTimeout)
Returns a new "GET" HttpURLConnection with the default connect timeout of 15 seconds and a read timeout based on the supplied value.static java.lang.String
readFileAsString(java.io.File file)
static java.lang.String
sanitize(java.lang.String s)
Sanitizes a string to be compatible with filename / foldername requirements by replacing illegal chars with underscores.static java.io.File
subdir(java.io.File parent, java.lang.String child)
Returns a subdir and tries to create it if necessary.static java.io.File
subfile(java.io.File base, java.lang.String filePath)
static java.io.File
subfile(java.io.File base, java.lang.String... subDirs)
static void
writeStringToFile(java.lang.String string, java.io.File file)
-
-
-
Method Detail
-
subdir
public static java.io.File subdir(java.io.File parent, java.lang.String child) throws java.lang.Exception
Returns a subdir and tries to create it if necessary. Throws an error if the dir can't be created- Throws:
java.lang.Exception
-
getJarParentFolder
public static java.io.File getJarParentFolder(java.io.File resourcesDir, LaunchManifest.Module m, LaunchManifest.Jar j) throws java.lang.Exception
Given the root of the cache/resources/ folder, returns the correct parent folder for a given jar file, right before the specific CRC subfolders.- Throws:
java.lang.Exception
-
sanitize
public static java.lang.String sanitize(java.lang.String s)
Sanitizes a string to be compatible with filename / foldername requirements by replacing illegal chars with underscores.
-
crc
public static long crc(java.io.File jarFile) throws java.io.IOException
- Throws:
java.io.IOException
-
md5
public static java.lang.String md5(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
deleteDirectory
public static void deleteDirectory(java.io.File directory) throws java.io.IOException
Deletes a directory recursively.- Parameters:
directory
- directory to delete- Throws:
java.io.IOException
- in case deletion is unsuccessful
-
cleanDirectory
public static void cleanDirectory(java.io.File directory) throws java.io.IOException
Cleans a directory without deleting it.- Parameters:
directory
- directory to clean- Throws:
java.io.IOException
- in case cleaning is unsuccessful
-
forceDelete
public static void forceDelete(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
subfile
public static java.io.File subfile(java.io.File base, java.lang.String filePath)
-
subfile
public static java.io.File subfile(java.io.File base, java.lang.String... subDirs)
-
copyFile
public static void copyFile(java.io.File in, java.io.File out) throws java.io.IOException
- Throws:
java.io.IOException
-
readFileAsString
public static java.lang.String readFileAsString(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStringToFile
public static void writeStringToFile(java.lang.String string, java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
launchJarCompatible
public static BootstrapUtilities.LaunchJarResults launchJarCompatible(GatewayAddress target, java.io.File launchJar) throws java.io.IOException
Checks if the supplied launch jar matches in length and crc32 checksum by getting the required length and checksum from the target gateway and comparing against the file. A LaunchJarResults is returned which wraps a boolean stating if its matches along with the checksum and length.- Throws:
java.io.IOException
-
getStringResponse
public static java.lang.String getStringResponse(java.net.URL url, int readTimeout) throws java.io.IOException
- Throws:
java.io.IOException
-
downloadFile
public static long downloadFile(java.net.URL url, int readTimeout, java.io.File destination) throws java.io.IOException
Downloads the file that exists at the url and saves it to the supplied destination file. Returns the CRC32 checksum of the file. No locking of the destination file is performed.- Throws:
java.io.IOException
-
newConnection
public static java.net.HttpURLConnection newConnection(java.net.URL url, int readTimeout) throws java.io.IOException
Returns a new "GET" HttpURLConnection with the default connect timeout of 15 seconds and a read timeout based on the supplied value. Be sure to close the connection!- Throws:
java.io.IOException
-
-