Package de.hsh.graja.util
Class FileUtils
- java.lang.Object
-
- de.hsh.graja.util.FileUtils
-
public class FileUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileUtils.MaxBytesExceededException
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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
readUTF8StreamCompletely(InputStream input)
static void
replaceStrings(InputStream is, OutputStream os, String[][] replacements, String encoding)
static void
replaceStringsInTextFile(String filename, String[][] replacements, String encoding)
static void
touch(File file)
static List<File>
walkDir(Path path, String extension, String[] ignorePatterns)
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)
-
-
-
Method Detail
-
writeUTF8ToFile
public static void writeUTF8ToFile(Path path, String content) throws IOException
- Throws:
IOException
-
writeUTF8ToFile
public static void writeUTF8ToFile(File file, String content) throws IOException
- Throws:
IOException
-
writeUTF8ToFile
public static void writeUTF8ToFile(String filename, String content) throws IOException
- Throws:
IOException
-
appendUTF8ToFile
public static void appendUTF8ToFile(String filename, String content) throws IOException
- Throws:
IOException
-
writeToFile
public static void writeToFile(Path path, String content, String csn) throws IOException
- Throws:
IOException
-
writeToFile
public static void writeToFile(File file, String content, String csn) throws IOException
- Throws:
IOException
-
writeToFile
public static void writeToFile(String filename, String content, String csn) throws IOException
- Throws:
IOException
-
appendToFile
public static void appendToFile(String filename, String content, String csn) throws IOException
- Throws:
IOException
-
readUTF8FileCompletely
public static String readUTF8FileCompletely(Path path) throws IOException
- Throws:
IOException
-
readUTF8FileCompletely
public static String readUTF8FileCompletely(File file) throws IOException
- Throws:
IOException
-
readUTF8FileCompletely
public static String readUTF8FileCompletely(String filename) throws IOException
- Throws:
IOException
-
readUTF8StreamCompletely
public static String readUTF8StreamCompletely(InputStream input) throws IOException
- Throws:
IOException
-
readStreamCompletely
public static String readStreamCompletely(InputStream input, String csn) throws IOException
- Throws:
IOException
-
readFileCompletely
public static String readFileCompletely(String filename, String csn) throws IOException
- 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
public static void copyCompletely(InputStream input, OutputStream output) throws IOException
- Throws:
IOException
-
copyCompletely
public static void copyCompletely(InputStream input, OutputStream output, long maxBytes) throws IOException, FileUtils.MaxBytesExceededException
-
touch
public static void touch(File file) throws IOException
- Throws:
IOException
-
walkDir
public static List<File> walkDir(Path path, String extension, String[] ignorePatterns) throws IOException
- Throws:
IOException
-
deleteRecursively
public static void deleteRecursively(Path path) throws IOException
The specified folder will be deleted.- Parameters:
path
- pathname- Throws:
IOException
-
cleanupDirContents
public static void cleanupDirContents(Path path) throws IOException
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
-
getFileMd5Checksum
public static String getFileMd5Checksum(File file) throws IOException
- Throws:
IOException
-
getFileChecksum
public static String getFileChecksum(MessageDigest digest, File file) throws IOException
- Throws:
IOException
-
-