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 voidappendToFile(String filename, String content, String csn) static voidappendUTF8ToFile(String filename, String content) static voidcleanupDirContents(Path path) The contents of the specified folder are deleted recursively.static voidcopyCompletely(InputStream input, OutputStream output) static voidcopyCompletely(InputStream input, OutputStream output, long maxBytes) static voidcopyDirectoryRecursively(File sourceLocation, File targetLocation) static voiddeleteOnExit(Iterator<Path> pathsToBeErasedOnExit, int millisMaxWait) static voiddeleteRecursively(Path path) The specified folder will be deleted.static StringgetBaseName(String path) static StringgetExtension(String path) static StringgetFileChecksum(MessageDigest digest, File file) static StringgetFileMd5Checksum(File file) static StringgetMimeType(String fileName) static StringgetNameIncrement(String path) static StringgetSourceFragment(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 StringreadFileCompletely(String filename, String csn) static StringreadStreamCompletely(InputStream input, String csn) static StringreadUTF8FileCompletely(File file) static StringreadUTF8FileCompletely(String filename) static StringreadUTF8FileCompletely(Path path) static StringreadUTF8ResourceCompletely(String resourceName, ClassLoader cl) Read a resource from classloader as a complete UTF8 filestatic Stringstatic voidreplaceStrings(InputStream is, OutputStream os, String[][] replacements, String encoding) static voidreplaceStringsInTextFile(String filename, String[][] replacements, String encoding) static voidstatic voidwriteToFile(File file, String content, String csn) static voidwriteToFile(String filename, String content, String csn) static voidwriteToFile(Path path, String content, String csn) static voidwriteUTF8ToFile(File file, String content) static voidwriteUTF8ToFile(String filename, String content) static voidwriteUTF8ToFile(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, ifkeepIndentAsTabsis 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
-