public class FileUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileUtils.SOMDescriptionFileFilter |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
COMMENT_INDICATOR |
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
appendDirectorySeparator(java.lang.String dir)
Appends the
File.separator to a path if the given path is a directory |
static void |
clearOutputDir(java.lang.String outputDir) |
static void |
close(java.io.Closeable f) |
static java.lang.String |
consumeHeaderComments(java.io.BufferedReader br)
Reads (and discards) all comment lines (indicated by "#") at the beginning of a file.
|
static void |
copyFile(java.lang.String source,
java.lang.String destination) |
static void |
copyFileSafe(java.io.File destinationFileName,
java.io.File sourceFileName) |
static void |
copyFileSafe(java.lang.String destinationFileName,
java.lang.String sourceFileName) |
static void |
copyResource(java.lang.String destinationDirectory,
java.lang.String sourceDirectory,
java.lang.String fileName) |
static java.lang.String |
extractSOMLibDataPrefix(java.lang.String filename) |
static java.lang.String |
extractSOMLibInputPrefix(java.lang.String filename)
Extracts the prefix from a SOM description filename so that the corresponding other two description files can be
found
|
static boolean |
fileStartsWith(java.lang.String fileName,
java.lang.String match) |
static java.lang.String[] |
findAllSOMLibFiles(com.martiansoftware.jsap.JSAPResult config,
java.lang.String optNameInputs,
java.lang.String optNameInputDir,
java.lang.String extensionToFind,
java.lang.String extensionToCheck) |
static java.util.LinkedList<java.io.File> |
getAllFilesInRoot(java.io.File root)
Finds all files matching any of the given extensions, in any subdirecotry of the given root path
|
static java.util.LinkedList<java.io.File> |
getAllFilesInRoot(java.io.File root,
java.lang.String... extensions)
Finds all files matching any of the given extensions, in any subdirecotry of the given root path
|
private static java.util.LinkedList<java.io.File> |
getAllFilesInRoot(java.util.LinkedList<java.io.File> fileList,
java.io.File root,
java.io.FileFilter fileFilter) |
static java.io.InputStream |
getInputStream(java.lang.String fileType,
java.io.File file) |
static java.io.InputStream |
getInputStream(java.lang.String fileType,
java.lang.String fileName) |
static java.lang.String |
getPathFrom(java.lang.String unitDescriptionFileName) |
static java.lang.String |
getPathPrefix(java.lang.String fDir)
returns the given path, if needed appended by a
File.separator |
static java.lang.String |
getSuffix(java.lang.String suffix,
boolean gzipped)
Computes the suffix (extension) of a file name, with or without .gz
|
static void |
gunzip(java.lang.String source) |
static void |
gunzip(java.lang.String source,
java.lang.String destination) |
static boolean |
isURL(java.lang.String potentialURL)
Checks whether the given String is a valid URL or not
|
static int |
lineCount(java.lang.String filename) |
static java.io.BufferedReader |
openFile(java.lang.String fileType,
java.io.File file)
Opens a file specified by argument
file and returns a BufferedReader . |
static java.io.BufferedReader |
openFile(java.lang.String fileType,
java.lang.String fileName)
Opens a file specified by argument
fileName and returns a BufferedReader . |
static java.io.PrintWriter |
openFileForWriting(java.lang.String fileType,
java.lang.String fileName) |
static java.io.PrintWriter |
openFileForWriting(java.lang.String fileType,
java.lang.String fileName,
boolean gzipped) |
static java.lang.String |
prepareOutputDir(java.lang.String dir)
Deprecated.
use
appendDirectorySeparator(String) instead |
static java.lang.String |
readFileContents(java.io.File file)
Reads the complete contents of the given file.
|
static java.lang.String |
readFileContents(java.lang.String filename)
Reads the complete contents of the file denoted by the given filename.
|
static java.lang.String |
readFromFile(java.lang.String fileName) |
static java.lang.String |
readFromFile(java.lang.String resourcePath,
java.lang.String fileName) |
static java.lang.String |
readFromReader(java.io.Reader reader) |
static java.lang.String |
readFromStream(java.io.InputStream in) |
static java.lang.String[] |
readLines(java.lang.String filename) |
static java.util.ArrayList<java.lang.String> |
readLinesAsList(java.lang.String filename) |
static java.util.HashMap<java.lang.String,java.lang.String> |
readSOMLibFileHeaders(java.io.BufferedReader br,
java.lang.String fileType)
Reads the headers of a SOMLib File, and stores the values in a map.
|
static void |
saveImageToFile(java.lang.String fileName,
java.awt.image.BufferedImage buim) |
static java.lang.String |
stripPathPrefix(java.lang.String fileName) |
static void |
writeFile(java.lang.String fileName,
java.lang.String data) |
static void |
writeToFile(java.lang.String content,
java.lang.String pathname) |
private static final java.lang.String COMMENT_INDICATOR
public static java.io.BufferedReader openFile(java.lang.String fileType, java.lang.String fileName) throws java.io.FileNotFoundException
fileName
and returns a BufferedReader
. This method
opens both, uncompressed and gzipped files transparent to the calling function. If the specified file is not
found, the suffix .gz is appended. If this name is again not found, a FileNotFoundException
is
thrown.fileType
- the type of the file to open.fileName
- the name of the file to open.BufferedReader
to the requested file.java.io.FileNotFoundException
- if the file with the given name is not found.public static java.io.BufferedReader openFile(java.lang.String fileType, java.io.File file) throws java.io.FileNotFoundException
file
and returns a BufferedReader
. This method opens
both, uncompressed and gzipped files transparent to the calling function. If the specified file is not found, the
suffix .gz is appended. If this name is again not found, a FileNotFoundException
is thrown.fileType
- the type of the file to open.file
- the file to open.BufferedReader
to the requested file.java.io.FileNotFoundException
- if the file is not found.public static java.io.InputStream getInputStream(java.lang.String fileType, java.lang.String fileName) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.io.InputStream getInputStream(java.lang.String fileType, java.io.File file) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.io.PrintWriter openFileForWriting(java.lang.String fileType, java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static java.io.PrintWriter openFileForWriting(java.lang.String fileType, java.lang.String fileName, boolean gzipped) throws java.io.IOException
java.io.IOException
public static java.lang.String extractSOMLibInputPrefix(java.lang.String filename)
public static java.lang.String extractSOMLibDataPrefix(java.lang.String filename)
public static java.util.HashMap<java.lang.String,java.lang.String> readSOMLibFileHeaders(java.io.BufferedReader br, java.lang.String fileType) throws java.io.IOException
java.io.IOException
public static java.lang.String[] findAllSOMLibFiles(com.martiansoftware.jsap.JSAPResult config, java.lang.String optNameInputs, java.lang.String optNameInputDir, java.lang.String extensionToFind, java.lang.String extensionToCheck)
public static java.lang.String stripPathPrefix(java.lang.String fileName)
public static void copyFile(java.lang.String source, java.lang.String destination) throws java.io.FileNotFoundException, java.io.IOException, SOMToolboxException
java.io.FileNotFoundException
java.io.IOException
SOMToolboxException
public static void copyFileSafe(java.io.File destinationFileName, java.io.File sourceFileName)
public static void copyFileSafe(java.lang.String destinationFileName, java.lang.String sourceFileName)
public static void copyResource(java.lang.String destinationDirectory, java.lang.String sourceDirectory, java.lang.String fileName)
public static boolean fileStartsWith(java.lang.String fileName, java.lang.String match) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public static java.lang.String[] readLines(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.util.ArrayList<java.lang.String> readLinesAsList(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public static java.lang.String readFileContents(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
readFileContents(File)
.java.io.FileNotFoundException
java.io.IOException
public static java.lang.String readFileContents(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String readFromStream(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static java.lang.String readFromReader(java.io.Reader reader) throws java.io.IOException
java.io.IOException
public static java.lang.String readFromFile(java.lang.String resourcePath, java.lang.String fileName) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public static java.lang.String readFromFile(java.lang.String fileName) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
@Deprecated public static java.lang.String prepareOutputDir(java.lang.String dir)
appendDirectorySeparator(String)
insteadpublic static java.lang.String appendDirectorySeparator(java.lang.String dir)
File.separator
to a path if the given path is a directorypublic static void clearOutputDir(java.lang.String outputDir)
public static void writeToFile(java.lang.String content, java.lang.String pathname) throws java.io.IOException
java.io.IOException
public static java.lang.String getPathFrom(java.lang.String unitDescriptionFileName)
public static void saveImageToFile(java.lang.String fileName, java.awt.image.BufferedImage buim) throws SOMToolboxException
SOMToolboxException
public static void writeFile(java.lang.String fileName, java.lang.String data) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public static boolean isURL(java.lang.String potentialURL)
public static java.lang.String consumeHeaderComments(java.io.BufferedReader br) throws java.io.IOException
java.io.IOException
public static java.lang.String getPathPrefix(java.lang.String fDir)
File.separator
public static java.lang.String getSuffix(java.lang.String suffix, boolean gzipped)
public static java.util.LinkedList<java.io.File> getAllFilesInRoot(java.io.File root)
public static java.util.LinkedList<java.io.File> getAllFilesInRoot(java.io.File root, java.lang.String... extensions)
private static java.util.LinkedList<java.io.File> getAllFilesInRoot(java.util.LinkedList<java.io.File> fileList, java.io.File root, java.io.FileFilter fileFilter)
public static void gunzip(java.lang.String source) throws SOMToolboxException
SOMToolboxException
public static void gunzip(java.lang.String source, java.lang.String destination)
public static void close(java.io.Closeable f)
public static int lineCount(java.lang.String filename) throws java.io.IOException
java.io.IOException