public class SecureFiles extends Object
Utilties to provide the following to applications:
Uses Java new I/O and Guava Files where possible
Modifier and Type | Method and Description |
---|---|
static File |
createTemporaryDirectory()
Atomically create a temporary directory that will be removed when the JVM exits
|
static File |
createTemporaryFilename(String prefix,
String suffix,
File dir)
Create a temporary filename but do not create the actual file
|
static void |
rename(File oldFile,
File newFile)
Rename oldFile to newFile
|
static void |
secureDelete(File file)
Delete a file with an overwrite of all of the data.
|
static void |
slowSecureDelete(File file)
Delete a file with an overwrite of all of the data.
|
static File |
verifyOrCreateDirectory(File directory) |
static File |
verifyOrCreateDirectory(File parentDirectory,
String childDirectory) |
static File |
verifyOrCreateFile(File parentDirectory,
String filename)
Use atomic file operations to create a file with all parent directories in place
|
static void |
writeFile(InputStream inputStream,
File destFile)
Securely write a file to the file system.
|
static void |
writeFile(InputStream inputStream,
File tempFile,
File destFile)
Securely write a file to the file system using temporary file then renaming to the destination
|
public static void secureDelete(File file) throws IOException
file
- The file to secure deleteIOException
- if the operation fails for any reasonpublic static void slowSecureDelete(File file) throws IOException
file
- The file to secure deleteIOException
- if the operation fails for any reasonpublic static File verifyOrCreateDirectory(File directory)
directory
- The directory to verify or createIllegalStateException
- If the file could not be createdpublic static File verifyOrCreateDirectory(File parentDirectory, String childDirectory)
parentDirectory
- The parent directorychildDirectory
- The child directory (will be created if absent)IllegalStateException
- If the file could not be createdpublic static File verifyOrCreateFile(File parentDirectory, String filename)
Use atomic file operations to create a file with all parent directories in place
parentDirectory
- The parent directoryfilename
- The filenameIllegalStateException
- If the file could not be createdpublic static File createTemporaryDirectory() throws IOException
Atomically create a temporary directory that will be removed when the JVM exits
IOException
- If something goes wrongpublic static File createTemporaryFilename(String prefix, String suffix, File dir) throws IOException
IOException
public static void writeFile(InputStream inputStream, File tempFile, File destFile) throws IOException
IOException
public static void writeFile(InputStream inputStream, File destFile) throws IOException
IOException
public static void rename(File oldFile, File newFile) throws IOException
oldFile
- newFile
- IOException
Copyright © 2015–2018. All rights reserved.