Package de.hsh.graja.util
Class FileUtils
java.lang.Object
de.hsh.graja.util.FileUtils
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendToFile
(String filename, String content, String csn) static void
appendUTF8ToFile
(String filename, String content) static void
cleanupDirContents
(Path path) The contents of the specified folder are deleted recursively.static void
copyCompletely
(InputStream input, OutputStream output) static void
copyCompletely
(InputStream input, OutputStream output, long maxBytes) static void
copyDirectoryRecursively
(File sourceLocation, File targetLocation) static void
deleteOnExit
(Iterator<Path> pathsToBeErasedOnExit, int millisMaxWait) static void
deleteRecursively
(Path path) The specified folder will be deleted.static String
getBaseName
(String path) static String
getExtension
(String path) static String
getFileChecksum
(MessageDigest digest, File file) static String
getFileMd5Checksum
(File file) static String
getMimeType
(String fileName) static String
getNameIncrement
(String path) static String
getSourceFragment
(File file, int beginLine, int endLine, int maxLinesToPrint, int maxColumnsToPrint, boolean keepIndentAsTabs, int beginLineHighlight, int endLineHighlight) Get source code fragment from the input and put it in a string.static String
readFileCompletely
(String filename, String csn) static String
readStreamCompletely
(InputStream input, String csn) static String
readUTF8FileCompletely
(File file) static String
readUTF8FileCompletely
(String filename) static String
readUTF8FileCompletely
(Path path) static String
readUTF8ResourceCompletely
(String resourceName, ClassLoader cl) Read a resource from classloader as a complete UTF8 filestatic String
static void
replaceStrings
(InputStream is, OutputStream os, String[][] replacements, String encoding) static void
replaceStringsInTextFile
(String filename, String[][] replacements, String encoding) static void
static void
writeToFile
(File file, String content, String csn) static void
writeToFile
(String filename, String content, String csn) static void
writeToFile
(Path path, String content, String csn) static void
writeUTF8ToFile
(File file, String content) static void
writeUTF8ToFile
(String filename, String content) static void
writeUTF8ToFile
(Path path, String content)
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
writeUTF8ToFile
- Throws:
IOException
-
writeUTF8ToFile
- Throws:
IOException
-
writeUTF8ToFile
- Throws:
IOException
-
appendUTF8ToFile
- Throws:
IOException
-
writeToFile
- Throws:
IOException
-
writeToFile
- Throws:
IOException
-
writeToFile
- Throws:
IOException
-
appendToFile
- Throws:
IOException
-
readUTF8FileCompletely
- Throws:
IOException
-
readUTF8FileCompletely
- Throws:
IOException
-
readUTF8FileCompletely
- Throws:
IOException
-
readUTF8StreamCompletely
- Throws:
IOException
-
readStreamCompletely
- Throws:
IOException
-
readFileCompletely
- Throws:
IOException
-
getSourceFragment
public static String getSourceFragment(File file, int beginLine, int endLine, int maxLinesToPrint, int maxColumnsToPrint, boolean keepIndentAsTabs, int beginLineHighlight, int endLineHighlight) Get source code fragment from the input and put it in a string. The result looks like this:
003 : import java.io.File; 004 : import java.io.FileNotFoundException; 005 : import java.util.Formatter; 006 : import java.util.Scanner; 007 : 008 : public class Helper { ...
Tabs in the source are not replaced by spaces, ifkeepIndentAsTabs
is true. The input file is treated as UTF8. If 0 <beginLineHighlight
<=endLineHighlight
, then the respective region is highlighted. -
copyCompletely
- Throws:
IOException
-
copyCompletely
public static void copyCompletely(InputStream input, OutputStream output, long maxBytes) throws IOException, FileUtils.MaxBytesExceededException -
touch
- Throws:
IOException
-
walkDir
public static List<File> walkDir(Path path, String extension, String[] ignorePatterns) throws IOException - Throws:
IOException
-
deleteRecursively
The specified folder will be deleted.- Parameters:
path
- pathname- Throws:
IOException
-
cleanupDirContents
The contents of the specified folder are deleted recursively. The folder itself will survive.- Parameters:
path
-- Throws:
IOException
-
copyDirectoryRecursively
public static void copyDirectoryRecursively(File sourceLocation, File targetLocation) throws IOException - Throws:
IOException
-
readUTF8ResourceCompletely
public static String readUTF8ResourceCompletely(String resourceName, ClassLoader cl) throws IOException Read a resource from classloader as a complete UTF8 file- Parameters:
resourceName
-cl
-- Returns:
- the content of the resource
- Throws:
IOException
-
replaceStrings
public static void replaceStrings(InputStream is, OutputStream os, String[][] replacements, String encoding) throws IOException - Throws:
IOException
-
replaceStringsInTextFile
public static void replaceStringsInTextFile(String filename, String[][] replacements, String encoding) throws IOException - Throws:
IOException
-
getExtension
-
getBaseName
-
getNameIncrement
-
getMimeType
-
getFileMd5Checksum
- Throws:
IOException
-
getFileChecksum
- Throws:
IOException
-
deleteOnExit
-