|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgenopt.io.FileHandler
public class FileHandler
Object that handles file reading and writing and offers various manipulation and access methods of the file contents.
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
| Field Summary | |
|---|---|
protected java.lang.String[] |
FileContents
the content of the file |
protected static java.lang.String |
FS
System dependent file separator |
private int |
INCREMENT
Increment for array that stores the Strings |
private static java.lang.String |
LS
System dependent line separator |
protected int |
nLines
the number of lines in FileContents (occupied element in FileContents) |
| Constructor Summary | |
|---|---|
FileHandler(java.io.File theFile)
Constructor. |
|
FileHandler(java.lang.String pathAndName)
constructor |
|
FileHandler(java.lang.String[] FileLines)
constructor |
|
FileHandler(java.lang.String path,
java.lang.String name)
constructor |
|
| Method Summary | |
|---|---|
static java.lang.String[] |
addCanonicalPaths(java.lang.String[] str,
java.lang.String userDir)
Adds the canonical path name to the string, unless the string is already a canonical path or is an empty character sequence |
static java.lang.String |
addCanonicalPaths(java.lang.String str,
java.lang.String userDir)
Adds the canonical path name to the string, unless the string is already a canonical path or is an empty character sequence |
private void |
addElement(java.lang.String s)
adds an element to the object |
static void |
appendToFile(java.lang.String fileName,
java.lang.String text)
Appends the text to a file and closes the file again |
static void |
copyFile(java.lang.String sourcePath,
java.lang.String sourceName,
java.lang.String destinationPath,
java.lang.String destinationName)
copies file from source to destination |
static java.lang.String |
cutBegin(java.lang.String s,
java.lang.String prefix)
cuts a suffix from a string. |
static java.lang.String |
cutBeginAndEnd(java.lang.String s,
java.lang.String prefix,
java.lang.String suffix)
cuts a leading and terminating string from a string. |
static java.lang.String |
cutEnd(java.lang.String s,
java.lang.String suffix)
cuts a suffix from a string. |
static java.lang.String |
cutEndLineBreak(java.lang.String line)
cuts a line break ('\n' and/or '\r') from the end of the String |
static boolean |
deleteDirectory(java.io.File path)
Deletes directories, even if they are not empty |
java.lang.String[] |
getFileContentsString()
gets the file contents in a String array where each entry contains the corresponding file line |
int |
getLineNumberWithString(java.lang.String MatchString,
int StartLine)
gets the number of the line where 'MatchString' occurs the first time. |
static int |
getNextDelimiterPosition(java.lang.String Line,
char Delimiter1,
char Delimiter2)
gets the lowest position of two delimiters in 'Line'. |
int |
getNumberOfLines()
gets the number of lines |
static boolean |
isEndOfLine(int b)
checks if the byte is a line feed ('\n') or a carriage return ('\r') |
static void |
makeDirectory(java.lang.String[] path)
creates directories if they do not exist yet |
static java.lang.String |
replaceAll(java.lang.String find,
java.lang.String set,
java.lang.String line)
replaces all occurences of the String 'find' with the String 'set' (even if 'find' appears several times on the same line) |
static java.lang.String[] |
replacePathsByCanonicalPaths(java.lang.String[] str,
java.lang.String userDir)
Replaces all paths with their canonical paths |
static java.lang.String |
replacePathsByCanonicalPaths(java.lang.String str,
java.lang.String userDir)
Replaces all paths with their canonical paths |
boolean |
replaceString(java.lang.String Find,
java.lang.String Set)
replaces all occurrences of the String 'find' with the String 'set' (even if 'find' appears several times on the same line and/or in the same file) |
void |
writeFile(java.lang.String pathAndName)
writes FileContents in a text file |
static void |
writeFile(java.lang.String[] text,
java.lang.String path,
java.lang.String name)
writes a String array in a text file |
void |
writeFile(java.lang.String path,
java.lang.String name)
writes FileContents in a text file |
static void |
writeFile(java.lang.String text,
java.lang.String path,
java.lang.String name)
writes a string to a text file |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.String LS
protected static final java.lang.String FS
private final int INCREMENT
protected java.lang.String[] FileContents
protected int nLines
FileContents)
| Constructor Detail |
|---|
public FileHandler(java.lang.String[] FileLines)
FileLines - where
each element is a line of the file stored in a String
public FileHandler(java.lang.String pathAndName)
throws java.io.IOException
pathAndName - path and name of file
java.io.IOException
public FileHandler(java.lang.String path,
java.lang.String name)
throws java.io.IOException
path - path of file (or null pointer if file is in current
directoryname - name of file
java.io.IOException
public FileHandler(java.io.File theFile)
throws java.io.IOException,
java.io.FileNotFoundException,
java.lang.SecurityException
theFile - the file
java.io.IOException
java.io.FileNotFoundException
java.lang.SecurityException| Method Detail |
|---|
public static void appendToFile(java.lang.String fileName,
java.lang.String text)
throws java.io.IOException
fileName - file path and name where the text has to be appendedtext - text to be written in the file
java.io.IOExceptionprivate void addElement(java.lang.String s)
s - String to be addedpublic static final boolean isEndOfLine(int b)
b - the byte value to be checked
true if b is a line feed or a carriage return
public boolean replaceString(java.lang.String Find,
java.lang.String Set)
Find - String that has to be found and replacedSet - String that has to be set at the position of 'Find'
true if 'Find' has been found, false otherwise
public static java.lang.String[] replacePathsByCanonicalPaths(java.lang.String[] str,
java.lang.String userDir)
throws java.io.IOException
str - The original string
java.io.IOException - If an I/O error occurs, which is possible because the construction of the
canonical pathname may require filesystem queries
public static java.lang.String replacePathsByCanonicalPaths(java.lang.String str,
java.lang.String userDir)
throws java.io.IOException
str - The original string
java.io.IOException - If an I/O error occurs, which is possible because the construction of the
canonical pathname may require filesystem queries
public static java.lang.String[] addCanonicalPaths(java.lang.String[] str,
java.lang.String userDir)
throws java.io.IOException
str - The original strings
java.io.IOException - If an I/O error occurs, which is possible because the construction of the
canonical pathname may require filesystem queries
public static java.lang.String addCanonicalPaths(java.lang.String str,
java.lang.String userDir)
throws java.io.IOException
str - The original string
java.io.IOException - If an I/O error occurs, which is possible because the construction of the
canonical pathname may require filesystem queries
public static java.lang.String replaceAll(java.lang.String find,
java.lang.String set,
java.lang.String line)
find - String that has to be found and replacedset - String that has to be set at the position of 'Find'line - line on which replacement takes place
public int getLineNumberWithString(java.lang.String MatchString,
int StartLine)
MatchString - String that has to be searched forStartLine - number of Line where the search process starts
public static boolean deleteDirectory(java.io.File path)
throws java.lang.SecurityException
path - Name of the directory
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkDelete(java.lang.String) method denies delete access to the file
public static int getNextDelimiterPosition(java.lang.String Line,
char Delimiter1,
char Delimiter2)
Line - Line to search for the delimitersDelimiter1 - First delimiterDelimiter2 - Second delimiter
public int getNumberOfLines()
public java.lang.String[] getFileContentsString()
public static void copyFile(java.lang.String sourcePath,
java.lang.String sourceName,
java.lang.String destinationPath,
java.lang.String destinationName)
throws java.io.IOException
sourcePath - path of source file (or null pointer if file is in current
directory)sourceName - name of source filedestinationPath - path of destination file (or null pointer if file is in current
directory)destinationName - name of destination file
java.io.IOException
public static void makeDirectory(java.lang.String[] path)
throws java.lang.Exception
path - path that has to be created
java.lang.Exception - if a SecurityException occured
public static void writeFile(java.lang.String[] text,
java.lang.String path,
java.lang.String name)
throws java.io.IOException
text - array of text that has to be written into the filepath - path of file (or null pointer if file is in current
directory)name - name of file
java.io.IOException
public static void writeFile(java.lang.String text,
java.lang.String path,
java.lang.String name)
throws java.io.IOException
text - text that has to be written to the filepath - path of file (or null pointer if file is in current
directory)name - name of file
java.io.IOException
public void writeFile(java.lang.String pathAndName)
throws java.io.IOException
pathAndName - path and name of file
java.io.IOException
public void writeFile(java.lang.String path,
java.lang.String name)
throws java.io.IOException
path - path of file (or null pointer if file is in current
directory)name - name of file
java.io.IOException
public static java.lang.String cutBeginAndEnd(java.lang.String s,
java.lang.String prefix,
java.lang.String suffix)
"""abc"" is returned as ""abc" if the
prefix and suffix are specified as: "
s - the stringprefix - the leading stringsuffix - the last string
public static java.lang.String cutBegin(java.lang.String s,
java.lang.String prefix)
s - the stringprefix - the prefix
public static java.lang.String cutEnd(java.lang.String s,
java.lang.String suffix)
s - the stringsuffix - the suffix
public static final java.lang.String cutEndLineBreak(java.lang.String line)
line - the String to be cutted
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||