Package com.inductiveautomation.rm.base
Class RMFileUtils
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMFileUtils
-
public class RMFileUtils extends java.lang.Object
Utility methods for file.
-
-
Constructor Summary
Constructors Constructor Description RMFileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.File
copyFile(java.io.File aSource, java.io.File aDest)
Copies a file from one location to another.static java.io.File
copyFileSafe(java.io.File in, java.io.File out)
Copies a file from one location to another with exception suppression.static boolean
deleteDeep(java.io.File aFile)
Deletes a directory.static java.io.File
getAppDataDir(java.lang.String aName, boolean doCreate)
Returns the AppData or Application Support directory file.static byte[]
getBytes(java.io.File aFile)
Returns bytes for a file.static java.io.File
getDirectory(java.io.File aParent, java.lang.String aChild, boolean create)
Returns a child directory for a parent directory, creating if necessary.static java.io.File
getFile(java.lang.Object aSource)
Returns a File object from a source, if one can be divined.static java.lang.String
getFileExtension(java.io.File aFile)
Returns the file name for a file.static java.lang.String
getFileName(java.io.File aFile)
Returns the file name for a file.static java.lang.String
getFileNameSimple(java.io.File aFile)
Returns the file name for a file.static java.lang.String
getPath(java.io.File aFile)
Returns the path for a file.static java.io.File
getTempDir()
Returns the temp directory.static java.io.File
getTempFile(java.lang.String aName)
Creates a file in the temp directory.static java.io.File
getUniqueFile(java.io.File aFile)
Returns a unique non-existent file for given file.static java.io.File
getUnpackDestination(java.io.File aFile, java.io.File aDestFile)
Returns the file that given packed file would be saved to using the unpack method.static java.io.File
getUserHomeDir(java.lang.String aName, boolean doCreate)
Returns a file for named directory in the user's home directory (with option to create).static boolean
isFileType(java.io.File aFile, java.lang.String... theTypes)
Returns whether file is given type.static void
openFile(java.io.File aFile)
Tries to open the given file name with the platform reader.static void
openFile(java.lang.String aName)
Tries to open the given file name with the platform reader.static void
unzip(java.io.File aFile)
Unzips the given file into the destination file.static void
writeBytes(java.io.File aFile, byte[] theBytes)
Writes the given bytes (within the specified range) to the given file.static void
writeBytesSafely(java.io.File aFile, byte[] theBytes)
Writes the given bytes (within the specified range) to the given file, with an option for doing it "safely".
-
-
-
Method Detail
-
getFile
public static java.io.File getFile(java.lang.Object aSource)
Returns a File object from a source, if one can be divined.
-
getPath
public static java.lang.String getPath(java.io.File aFile)
Returns the path for a file.
-
getFileName
public static java.lang.String getFileName(java.io.File aFile)
Returns the file name for a file.
-
getFileNameSimple
public static java.lang.String getFileNameSimple(java.io.File aFile)
Returns the file name for a file.
-
getFileExtension
public static java.lang.String getFileExtension(java.io.File aFile)
Returns the file name for a file.
-
isFileType
public static boolean isFileType(java.io.File aFile, java.lang.String... theTypes)
Returns whether file is given type.
-
getDirectory
public static java.io.File getDirectory(java.io.File aParent, java.lang.String aChild, boolean create)
Returns a child directory for a parent directory, creating if necessary.
-
openFile
public static void openFile(java.io.File aFile)
Tries to open the given file name with the platform reader.
-
openFile
public static void openFile(java.lang.String aName)
Tries to open the given file name with the platform reader.
-
getBytes
public static byte[] getBytes(java.io.File aFile)
Returns bytes for a file.
-
writeBytes
public static void writeBytes(@Nonnull java.io.File aFile, @Nullable byte[] theBytes) throws java.io.IOException
Writes the given bytes (within the specified range) to the given file.- Throws:
java.io.IOException
-
writeBytesSafely
public static void writeBytesSafely(java.io.File aFile, byte[] theBytes) throws java.io.IOException
Writes the given bytes (within the specified range) to the given file, with an option for doing it "safely".- Throws:
java.io.IOException
-
getTempDir
public static java.io.File getTempDir()
Returns the temp directory.
-
getTempFile
public static java.io.File getTempFile(java.lang.String aName)
Creates a file in the temp directory.
-
getUserHomeDir
public static java.io.File getUserHomeDir(java.lang.String aName, boolean doCreate)
Returns a file for named directory in the user's home directory (with option to create).
-
getAppDataDir
public static java.io.File getAppDataDir(java.lang.String aName, boolean doCreate)
Returns the AppData or Application Support directory file.
-
copyFile
public static java.io.File copyFile(java.io.File aSource, java.io.File aDest) throws java.io.IOException
Copies a file from one location to another.- Throws:
java.io.IOException
-
copyFileSafe
public static java.io.File copyFileSafe(java.io.File in, java.io.File out)
Copies a file from one location to another with exception suppression.
-
deleteDeep
public static boolean deleteDeep(java.io.File aFile)
Deletes a directory.
-
unzip
public static void unzip(java.io.File aFile)
Unzips the given file into the destination file.
-
getUnpackDestination
public static java.io.File getUnpackDestination(java.io.File aFile, java.io.File aDestFile)
Returns the file that given packed file would be saved to using the unpack method.
-
getUniqueFile
public static java.io.File getUniqueFile(java.io.File aFile)
Returns a unique non-existent file for given file.
-
-