|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectat.tuwien.ifs.somtoolbox.util.FileUtils
public class FileUtils
This class bundles file-related utilities.
Nested Class Summary | |
---|---|
static class |
FileUtils.SOMDescriptionFileFilter
|
Field Summary | |
---|---|
private static String |
COMMENT_INDICATOR
|
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
clearOutputDir(String outputDir)
|
static void |
close(Closeable f)
|
static String |
consumeHeaderComments(BufferedReader br)
Reads (and discards) all comment lines (indicated by "#") at the beginning of a file. |
static void |
copyFile(String source,
String destination)
|
static void |
copyFileSafe(File destinationFileName,
File sourceFileName)
|
static void |
copyFileSafe(String destinationFileName,
String sourceFileName)
|
static void |
copyResource(String destinationDirectory,
String sourceDirectory,
String fileName)
|
static String |
extractSOMLibDataPrefix(String filename)
|
static String |
extractSOMLibInputPrefix(String filename)
Extracts the prefix from a SOM description filename so that the corresponding other two description files can be found |
static boolean |
fileStartsWith(String fileName,
String match)
|
static String[] |
findAllSOMLibFiles(com.martiansoftware.jsap.JSAPResult config,
String optNameInputs,
String optNameInputDir,
String extensionToFind,
String extensionToCheck)
|
static LinkedList<File> |
getAllFilesInRoot(File root,
String... extensions)
Finds all files matching any of the given extensions, in any subdirecotry of the given root path |
private static LinkedList<File> |
getAllFilesInRoot(LinkedList<File> fileList,
File root,
FileFilter fileFilter)
|
static InputStream |
getInputStream(String fileType,
File file)
|
static InputStream |
getInputStream(String fileType,
String fileName)
|
static String |
getPathFrom(String unitDescriptionFileName)
|
static String |
getPathPrefix(String fDir)
returns the given path, if needed appended by a File.separator |
static String |
getSuffix(String suffix,
boolean gzipped)
Computes the suffix (extension) of a file name, with or without .gz |
static void |
gunzip(String source)
|
static void |
gunzip(String source,
String destination)
|
static boolean |
isURL(String potentialURL)
Checks whether the given String is a valid URL or not |
static BufferedReader |
openFile(String fileType,
File file)
Opens a file specified by argument file and returns a BufferedReader . |
static BufferedReader |
openFile(String fileType,
String fileName)
Opens a file specified by argument fileName and returns a BufferedReader . |
static PrintWriter |
openFileForWriting(String fileType,
String fileName)
|
static PrintWriter |
openFileForWriting(String fileType,
String fileName,
boolean gzipped)
|
static String |
prepareOutputDir(String dir)
|
static String |
readFileContents(File file)
Reads the complete contents of the given file. |
static String |
readFileContents(String filename)
Reads the complete contents of the file denoted by the given filename. |
static String |
readFromFile(String fileName)
|
static String |
readFromFile(String resourcePath,
String fileName)
|
static String[] |
readLines(String filename)
|
static ArrayList<String> |
readLinesAsList(String filename)
|
static HashMap<String,String> |
readSOMLibFileHeaders(BufferedReader br,
String fileType)
Reads the headers of a SOMLib File, and stores the values in a map. |
static void |
saveImageToFile(String fileName,
BufferedImage buim)
|
static String |
stripPathPrefix(String fileName)
|
static void |
writeFile(String fileName,
String data)
|
static void |
writeToFile(String content,
String pathname)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String COMMENT_INDICATOR
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static BufferedReader openFile(String fileType, String fileName) throws 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.
FileNotFoundException
- if the file with the given name is not found.public static BufferedReader openFile(String fileType, File file) throws 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.
FileNotFoundException
- if the file is not found.public static InputStream getInputStream(String fileType, String fileName) throws FileNotFoundException
FileNotFoundException
public static InputStream getInputStream(String fileType, File file) throws FileNotFoundException
FileNotFoundException
public static PrintWriter openFileForWriting(String fileType, String fileName) throws IOException
IOException
public static PrintWriter openFileForWriting(String fileType, String fileName, boolean gzipped) throws IOException
IOException
public static String extractSOMLibInputPrefix(String filename)
public static String extractSOMLibDataPrefix(String filename)
public static HashMap<String,String> readSOMLibFileHeaders(BufferedReader br, String fileType) throws IOException
IOException
public static String[] findAllSOMLibFiles(com.martiansoftware.jsap.JSAPResult config, String optNameInputs, String optNameInputDir, String extensionToFind, String extensionToCheck)
public static String stripPathPrefix(String fileName)
public static void copyFile(String source, String destination) throws FileNotFoundException, IOException, SOMToolboxException
FileNotFoundException
IOException
SOMToolboxException
public static void copyFileSafe(File destinationFileName, File sourceFileName)
public static void copyFileSafe(String destinationFileName, String sourceFileName)
public static void copyResource(String destinationDirectory, String sourceDirectory, String fileName)
public static boolean fileStartsWith(String fileName, String match) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static String[] readLines(String filename) throws IOException
IOException
public static ArrayList<String> readLinesAsList(String filename) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static String readFileContents(String filename) throws FileNotFoundException, IOException
readFileContents(File)
.
FileNotFoundException
IOException
public static String readFileContents(File file) throws IOException
IOException
public static String readFromFile(String resourcePath, String fileName) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static String readFromFile(String fileName) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static String prepareOutputDir(String dir)
public static void clearOutputDir(String outputDir)
public static void writeToFile(String content, String pathname) throws IOException
IOException
public static String getPathFrom(String unitDescriptionFileName)
public static void saveImageToFile(String fileName, BufferedImage buim) throws SOMToolboxException
SOMToolboxException
public static void writeFile(String fileName, String data) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static boolean isURL(String potentialURL)
public static String consumeHeaderComments(BufferedReader br) throws IOException
IOException
public static String getPathPrefix(String fDir)
File.separator
public static String getSuffix(String suffix, boolean gzipped)
public static LinkedList<File> getAllFilesInRoot(File root, String... extensions)
private static LinkedList<File> getAllFilesInRoot(LinkedList<File> fileList, File root, FileFilter fileFilter)
public static void gunzip(String source) throws SOMToolboxException
SOMToolboxException
public static void gunzip(String source, String destination)
public static void close(Closeable f)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |