Package org.hl7.fhir.utilities
Class FileUtilities
java.lang.Object
org.hl7.fhir.utilities.FileUtilities
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendBytesToFile(byte[] bytes, String path) static voidatomicDeleteDirectory(String path) Delete a directory atomically by first renaming it to a temp directory in its parent, and then deleting its contents.static voidbytesToFile(byte[] bytes, File f) static voidbytesToFile(byte[] bytes, String path) static StringbytesToString(byte[] bs) static StringbytesToString(byte[] bs, boolean removeBOM) static StringchangeFileExt(String name, String ext) static booleanstatic booleancheckFolderExists(String dir, List<String> errors) static StringcleanFileName(String badFileName) static voidclearDirectory(String folder, String... exemptions) static voidcopyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) static voidcopyDirectory2(String sourceFolder, String destFolder, FileNotifier.FileNotifier2 notifier) static voidstatic voidstatic voidstatic voidcopyFileToDirectory(File source, File destDir) static intcountFilesInDirectory(String dirName) static FilecreateDirectory(String path) static FilecreateDirectoryNC(String path) static FilecreateTempFile(String prefix, String suffix) static voiddeleteAllFiles(String folder, String type) static voidstatic voidstatic Stringstatic byte[]fileToBytes(File file) static byte[]fileToBytes(String srcFile) static byte[]fileToBytesNCS(String srcFile) fileToBytes insists in case correctness to ensure that stuff works across linux and windows, but it's not always appropriate to check case (e.g.static String[]fileToLines(File file) fileToLines(String file) static StringfileToString(File f) static StringfileToString(String src) static StringgetDirectoryForFile(File file) static StringgetDirectoryForFile(String filepath) static StringgetRelativePath(String root, String path) static booleanisEmptyDirectory(File dst) static booleanisIgnorableFile(File file) static voidlinesToFile(File f, String[] lines) static voidlinesToFile(String path, String[] lines) static voidlinesToFile(String path, List<String> lines) listAllFiles(String path, List<String> ignoreList) static voidrenameDirectory(String source, String dest) static byte[]streamToBytes(InputStream input) static byte[]streamToBytesNoClose(InputStream input) static voidstreamToFile(InputStream stream, String filename) static voidstreamToFileNoClose(InputStream stream, String filename) static String[]streamToLines(InputStream stream) static StringstreamToString(InputStream input) static byte[]stringToBytes(String content) static voidstringToFile(String content, File file) static voidstringToFile(String content, String path) static voidstringToFileIfDifferent(String content, String path) static voidstringToFileWithBOM(String content, File file) static voidstringToFileWithBOM(String content, String path) static voidstringToStream(String content, OutputStream stream) static voidvisitFiles(File folder, String extension, FileUtilities.FileVisitor visitor) static voidvisitFiles(String folder, String extension, FileUtilities.FileVisitor visitor)
-
Constructor Details
-
FileUtilities
public FileUtilities()
-
-
Method Details
-
bytesToString
- Throws:
IOException
-
bytesToString
- Throws:
IOException
-
bytesToFile
- Throws:
IOException
-
bytesToFile
- Throws:
IOException
-
appendBytesToFile
- Throws:
IOException
-
stringToStream
- Throws:
IOException
-
stringToBytes
- Throws:
IOException
-
stringToFile
- Throws:
IOException
-
stringToFileIfDifferent
- Throws:
IOException
-
stringToFile
- Throws:
IOException
-
stringToFileWithBOM
- Throws:
IOException
-
stringToFileWithBOM
- Throws:
IOException
-
fileToString
- Throws:
FileNotFoundExceptionIOException
-
fileToString
- Throws:
FileNotFoundExceptionIOException
-
fileToBytes
- Throws:
FileNotFoundExceptionIOException
-
fileToBytes
- Throws:
FileNotFoundExceptionIOException
-
fileToBytesNCS
fileToBytes insists in case correctness to ensure that stuff works across linux and windows, but it's not always appropriate to check case (e.g. validator parameters)- Parameters:
srcFile-- Returns:
- Throws:
FileNotFoundExceptionIOException
-
fileToLines
- Throws:
FileNotFoundExceptionIOException
-
fileToLines
- Throws:
FileNotFoundExceptionIOException
-
streamToLines
- Throws:
FileNotFoundExceptionIOException
-
streamToString
- Throws:
IOException
-
streamToBytes
- Throws:
IOException
-
streamToBytesNoClose
- Throws:
IOException
-
streamToFile
- Throws:
IOException
-
streamToFileNoClose
- Throws:
IOException
-
linesToFile
- Throws:
IOException
-
linesToFile
- Throws:
IOException
-
linesToFile
- Throws:
IOException
-
fileTitle
- Throws:
IOException
-
getDirectoryForFile
- Throws:
IOException
-
getDirectoryForFile
- Throws:
IOException
-
getRelativePath
-
createDirectory
- Throws:
IOException
-
createDirectoryNC
- Throws:
IOException
-
copyFile
- Throws:
IOException
-
copyFile
- Throws:
IOException
-
copyDirectory
public static void copyDirectory(String sourceFolder, String destFolder, FileNotifier notifier) throws IOException, FHIRException - Throws:
IOExceptionFHIRException
-
copyDirectory2
public static void copyDirectory2(String sourceFolder, String destFolder, FileNotifier.FileNotifier2 notifier) throws IOException, FHIRException - Throws:
IOExceptionFHIRException
-
copyFileToDirectory
- Throws:
IOException
-
renameDirectory
- Throws:
FHIRExceptionIOException
-
listAllFiles
- Throws:
IOException
-
atomicDeleteDirectory
Delete a directory atomically by first renaming it to a temp directory in its parent, and then deleting its contents.- Parameters:
path- The directory to delete.- Throws:
IOException
-
visitFiles
public static void visitFiles(String folder, String extension, FileUtilities.FileVisitor visitor) throws FileNotFoundException, IOException - Throws:
FileNotFoundExceptionIOException
-
visitFiles
public static void visitFiles(File folder, String extension, FileUtilities.FileVisitor visitor) throws FileNotFoundException, IOException - Throws:
FileNotFoundExceptionIOException
-
countFilesInDirectory
- Throws:
IOException
-
checkFileExists
public static boolean checkFileExists(String purpose, String dir, String file, List<String> errors) throws IOException - Throws:
IOException
-
checkFolderExists
- Throws:
IOException
-
createTempFile
- Throws:
IOException
-
deleteTempFiles
- Throws:
IOException
-
clearDirectory
- Throws:
IOException
-
deleteAllFiles
- Throws:
IOException
-
changeFileExt
-
isIgnorableFile
-
deleteEmptyFolders
-
cleanFileName
-
copyFiles
- Throws:
IOException
-
isEmptyDirectory
-