Package org.hl7.fhir.utilities
Class FileUtilities
- java.lang.Object
-
- org.hl7.fhir.utilities.FileUtilities
-
public class FileUtilities extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFileUtilities.FileVisitor
-
Constructor Summary
Constructors Constructor Description FileUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 booleancheckFileExists(String purpose, String dir, String file, List<String> errors)static 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 voidcopyFile(File sourceFile, File destFile)static voidcopyFile(String source, String dest)static voidcopyFiles(String source, String dest, String... extensions)static 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 voiddeleteEmptyFolders(File df)static voiddeleteTempFiles()static StringfileTitle(String file)static 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)static List<String>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 booleanisIgnorableFile(File file)static voidlinesToFile(File f, String[] lines)static voidlinesToFile(String path, String[] lines)static voidlinesToFile(String path, List<String> lines)static List<String>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 StringstreamToString(InputStream input)static byte[]stringToBytes(String content)static voidstringToFile(String content, File file)static voidstringToFile(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 Detail
-
FileUtilities
public FileUtilities()
-
-
Method Detail
-
bytesToString
public static String bytesToString(byte[] bs) throws IOException
- Throws:
IOException
-
bytesToString
public static String bytesToString(byte[] bs, boolean removeBOM) throws IOException
- Throws:
IOException
-
bytesToFile
public static void bytesToFile(byte[] bytes, String path) throws IOException
- Throws:
IOException
-
bytesToFile
public static void bytesToFile(byte[] bytes, File f) throws IOException
- Throws:
IOException
-
appendBytesToFile
public static void appendBytesToFile(byte[] bytes, String path) throws IOException
- Throws:
IOException
-
stringToStream
public static void stringToStream(String content, OutputStream stream) throws IOException
- Throws:
IOException
-
stringToBytes
public static byte[] stringToBytes(String content) throws IOException
- Throws:
IOException
-
stringToFile
public static void stringToFile(String content, String path) throws IOException
- Throws:
IOException
-
stringToFile
public static void stringToFile(String content, File file) throws IOException
- Throws:
IOException
-
stringToFileWithBOM
public static void stringToFileWithBOM(String content, File file) throws IOException
- Throws:
IOException
-
stringToFileWithBOM
public static void stringToFileWithBOM(String content, String path) throws IOException
- Throws:
IOException
-
fileToString
public static String fileToString(File f) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fileToString
public static String fileToString(String src) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fileToBytes
public static byte[] fileToBytes(String srcFile) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fileToBytes
public static byte[] fileToBytes(File file) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fileToBytesNCS
public static byte[] fileToBytesNCS(String srcFile) throws FileNotFoundException, IOException
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
public static List<String> fileToLines(String file) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fileToLines
public static String[] fileToLines(File file) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
streamToString
public static String streamToString(InputStream input) throws IOException
- Throws:
IOException
-
streamToBytes
public static byte[] streamToBytes(InputStream input) throws IOException
- Throws:
IOException
-
streamToBytesNoClose
public static byte[] streamToBytesNoClose(InputStream input) throws IOException
- Throws:
IOException
-
streamToFile
public static void streamToFile(InputStream stream, String filename) throws IOException
- Throws:
IOException
-
streamToFileNoClose
public static void streamToFileNoClose(InputStream stream, String filename) throws IOException
- Throws:
IOException
-
linesToFile
public static void linesToFile(File f, String[] lines) throws IOException
- Throws:
IOException
-
linesToFile
public static void linesToFile(String path, String[] lines) throws IOException
- Throws:
IOException
-
linesToFile
public static void linesToFile(String path, List<String> lines) throws IOException
- Throws:
IOException
-
fileTitle
public static String fileTitle(String file) throws IOException
- Throws:
IOException
-
getDirectoryForFile
public static String getDirectoryForFile(String filepath) throws IOException
- Throws:
IOException
-
getDirectoryForFile
public static String getDirectoryForFile(File file) throws IOException
- Throws:
IOException
-
getRelativePath
public static String getRelativePath(String root, String path)
-
createDirectory
public static File createDirectory(String path) throws IOException
- Throws:
IOException
-
createDirectoryNC
public static File createDirectoryNC(String path) throws IOException
- Throws:
IOException
-
copyFile
public static void copyFile(File sourceFile, File destFile) throws IOException
- Throws:
IOException
-
copyFile
public static void copyFile(String source, String dest) throws IOException
- 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
public static void copyFileToDirectory(File source, File destDir) throws IOException
- Throws:
IOException
-
renameDirectory
public static void renameDirectory(String source, String dest) throws FHIRException, IOException
- Throws:
FHIRExceptionIOException
-
listAllFiles
public static List<String> listAllFiles(String path, List<String> ignoreList) throws IOException
- Throws:
IOException
-
atomicDeleteDirectory
public static void atomicDeleteDirectory(String path) throws IOException
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
public static int countFilesInDirectory(String dirName) throws IOException
- Throws:
IOException
-
checkFileExists
public static boolean checkFileExists(String purpose, String dir, String file, List<String> errors) throws IOException
- Throws:
IOException
-
checkFolderExists
public static boolean checkFolderExists(String dir, List<String> errors) throws IOException
- Throws:
IOException
-
createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
- Throws:
IOException
-
deleteTempFiles
public static void deleteTempFiles() throws IOException
- Throws:
IOException
-
clearDirectory
public static void clearDirectory(String folder, String... exemptions) throws IOException
- Throws:
IOException
-
deleteAllFiles
public static void deleteAllFiles(String folder, String type) throws IOException
- Throws:
IOException
-
changeFileExt
public static String changeFileExt(String name, String ext)
-
isIgnorableFile
public static boolean isIgnorableFile(File file)
-
deleteEmptyFolders
public static void deleteEmptyFolders(File df)
-
cleanFileName
public static String cleanFileName(String badFileName)
-
copyFiles
public static void copyFiles(String source, String dest, String... extensions) throws IOException
- Throws:
IOException
-
-