|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.File
com.antelmann.io.MyFile
public class MyFile
A specialized File class that provides some additional functionality. MyFile adds no members to class File, only methods.
| Field Summary |
|---|
| Fields inherited from class java.io.File |
|---|
pathSeparator, pathSeparatorChar, separator, separatorChar |
| Constructor Summary | |
|---|---|
MyFile(File file)
|
|
MyFile(File parent,
String child)
|
|
MyFile(String pathname)
|
|
MyFile(String parent,
String child)
|
|
MyFile(URI uri)
|
|
| Method Summary | |
|---|---|
void |
append(File file)
appends the content of the given file to this file |
void |
clear()
deletes the content of the file |
boolean |
compareContent(File file)
returns true only if both files have the exact same content |
boolean |
compareContent(long beginIndexThisFile,
File otherFile,
long beginIndexOtherFile,
long maxBytes)
returns true only if both files have the exact same content beginning at beginIndex and up to maxBytes number of bytes. |
MyFile |
compress(boolean deleteOriginal)
compresses the file using gzip to a file named by adding the type gz to the original name. |
void |
compressTo(File file)
writes a gzip compressed file that can be uncompressed to its original form using uncompressTo(File). |
void |
copyTo(File destinationFile)
copies this file to the given destination file. |
void |
copyTo(File destinationFile,
byte[] searchPattern,
byte[] replacePattern)
copies this file to the given destination file while searchPattern is replaced with replacePattern |
int |
count(byte[] pattern)
returns how many times the given byte pattern occurs within the file |
static MyFile |
createTempDir(String prefix,
String suffix)
creates a new empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name. |
static MyFile |
createTempDir(String prefix,
String suffix,
File dir)
creates a new empty directory in the given dir, using the given prefix and suffix to generate its name. |
void |
decrypt(String password)
uses a com.antelmann.util.CipherKey |
String |
digestMD5()
returns a digest that can be used to verity the content of a file |
String |
digestSHA1()
returns a digest that can be used to verity the content of a file |
void |
directoryCompare(File dir,
PrintStream ps)
compares this directory with the given one and prints results to the given stream |
void |
directoryCompare(File dir,
PrintStream ps,
Monitor monitor)
|
void |
encrypt(String password)
uses a com.antelmann.util.CipherKey |
MyFile |
ensureExtension(String extension)
returns a file that has the given file extension based on this file. |
String |
fileCompareText(File file)
returns a text describing as to how this file compares to the given file |
String |
fileCompareText(long beginIndexThisFile,
File otherFile,
long beginIndexOtherFile,
long maxBytes)
returns a text describing as to how this file compares to the given file |
byte[] |
getContentAsBytes()
returns the entire file content as a byte array. |
String |
getContentAsString()
returns the entire file content as a String (using default encoding). |
String |
getContentAsString(String charsetName)
returns the entire file content as a String. |
String |
getContentAsUTF8()
|
String |
getFileExtension()
returns the lower-case file type denoted by its file extension. |
MyFile |
getFileRelativeTo(File dir)
returns the file as a relative reference from the given directory. |
static String[] |
getFileTypes(File[] file)
returns the different file extensions that occur in the given array |
String |
getNameWithoutExtension()
returns the file name without the type extension |
static MyFile |
getWorkingDir()
|
boolean |
hasParent(File dir)
returns true only if this MyFile is in the given dir (or sub-dir) |
long |
indexOf(byte[] pattern)
returns the index of the beginning of the given pattern within the file (beginning the search at beginIndex) or -1 |
long |
indexOf(byte[] pattern,
int beginIndex)
returns the index of the beginning of the given pattern within the file (beginning the search at beginIndex) or -1 |
int |
indexOf(String pattern)
returns the index within the content of this file of the first occurrence of the specified pattern; -1 is returned if pattern is not found. |
long |
length()
in case of a directory, the combined size of all files within the tree is returned; otherwise the file size. |
MyFile[] |
listFilesInTree()
returns all files including those in subdirectories recursively |
MyFile[] |
listFilesInTree(FileFilter filter)
|
MyFile[] |
listFilesInTree(FilenameFilter filter)
|
File[] |
listSubDirs()
assuming the current MyFile is a directory, all sub-directories are returned. |
Object |
loadObject()
calls loadObject(false) |
Object |
loadObject(boolean useDeserialization)
loads a single object from the file into memory and returns it. |
Properties |
loadProperties()
|
Enumeration |
objectEnumerator()
returns an Enumeration over the objects contained in this binary file with serialized objects written with an ObjectOutputStream |
Enumeration |
objectEnumerator(boolean useDeserialization)
returns an Enumeration over the objects contained in this binary file with serialized objects written with an ObjectOutputStream. |
Enumeration |
objectEnumerator(boolean useDeserialization,
Logger exceptionLogger)
convenience method |
boolean |
removeTree(boolean includingThisRoot)
If the MyFile at hand is a directory, this method attempts to delete the entire subtree; therefore use it with caution! |
void |
replace(byte[] searchPattern,
byte[] replacePattern)
searches for the first pattern and replaces all occurrences with the second pattern. |
void |
replace(String searchPattern,
String replacePattern)
searches for the first pattern and replaces all occurrences with the second pattern (no regular expressions used). |
void |
storeProperties(Properties props,
String comment)
|
MyFile[] |
synchronizeDir(File destinationDir)
Assuming the current MyFile is a directory, this method synchronizes it with the destination directory by writing all files into the destination directory that exist in the origin directory. |
MyFile[] |
synchronizeDir(File destinationDir,
FileFilter filter)
synchronizes only those files that are accepted by the filter |
MyFile[] |
synchronizeDir(File destinationDir,
FileFilter filter,
Logger logger,
Monitor monitor)
|
MyFile[] |
synchronizeDir(File destinationDir,
Logger logger)
This method allows for intermediate feedback through the logger; otherwise it's the same as the other synchronizeDir() method. |
MyFile[] |
synchronizeDir(File destinationDir,
Logger logger,
Monitor monitor)
This method allows for intermediate feedback and interactive stopping; otherwise it's the same as the other synchronizeDir() method. |
boolean |
touch()
returns setLastModified(System.currentTimeMillis())
after possibly creating the file if it didn't exist before. |
void |
uncompress(boolean deleteCompressedFile)
assuming the file is a *.gz file, it will be uncompressed to the same file w/o the gz extension. |
void |
uncompressTo(File file)
restores a gzip compressed file written with compressTo(File). |
void |
unzipTo(File directory)
calls unzipTo(directory, true) |
void |
unzipTo(File directory,
boolean overwriteExistingFiles)
|
void |
unzipTo(File directory,
boolean overwriteExistingFiles,
Monitor monitor)
|
void |
unzipTo(File directory,
FileFilter filter,
Monitor monitor)
allows to react individually per file on whether to unzip it or nor |
void |
writeBytes(byte[] bytes,
boolean append)
writes the given bytes directly to the file and flushes; if append is false, all previous content will be overwritten. |
void |
writeln()
appends a platform specific linebreak into a text file |
void |
writeObject(Object obj,
boolean append)
serializes the given object, writes it to the file and flushes. |
boolean |
writeStackTrace(Thread t,
Throwable e,
boolean append)
prints the stack trace of the given Throwable to a PrintWriter. |
void |
writeStackTrace(Throwable t,
boolean append)
prints the stack trace of the given Throwable |
void |
writeText(String text,
boolean append)
writes the given text to the file and flushes; if append is false, all previous content will be overwritten. |
void |
writeUTF8(String text,
boolean append)
writes the given text encoded as UTF8 |
void |
zipTo(File file)
zips either this file this directory three to the given file |
void |
zipTo(File file,
FileFilter filter,
String comment,
Monitor monitor)
only the file parameter must not be null |
void |
zipTo(File file,
String comment,
Monitor monitor)
|
| Methods inherited from class java.io.File |
|---|
canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MyFile(File file)
public MyFile(String pathname)
public MyFile(String parent,
String child)
public MyFile(File parent,
String child)
public MyFile(URI uri)
| Method Detail |
|---|
public boolean touch()
throws IOException
setLastModified(System.currentTimeMillis())
after possibly creating the file if it didn't exist before.
IOException
public void clear()
throws IOException
IOExceptionpublic static MyFile getWorkingDir()
public long length()
length in class File
public String digestMD5()
throws IOException
IOExceptionData.digestMD5(java.io.InputStream),
Strings.hexString(byte...)
public String digestSHA1()
throws IOException
IOExceptionData.digestSHA1(java.io.InputStream),
Strings.hexString(byte...)
public static MyFile createTempDir(String prefix,
String suffix)
throws IOException
IOExceptionFile.createTempFile(String, String, File)
public static MyFile createTempDir(String prefix,
String suffix,
File dir)
throws IOException
IOExceptionFile.createTempFile(String, String, File)public MyFile ensureExtension(String extension)
extension - a file extension (without the dot), i.e. "txt" for "*.txt"-files
public String getFileExtension()
public String getNameWithoutExtension()
public boolean hasParent(File dir)
public MyFile getFileRelativeTo(File dir)
public File[] listSubDirs()
public MyFile[] listFilesInTree()
public MyFile[] listFilesInTree(FileFilter filter)
public MyFile[] listFilesInTree(FilenameFilter filter)
public void copyTo(File destinationFile)
throws IOException
IOException
public void copyTo(File destinationFile,
byte[] searchPattern,
byte[] replacePattern)
throws IOException
IOException
public boolean compareContent(File file)
throws IOException
IOException
public boolean compareContent(long beginIndexThisFile,
File otherFile,
long beginIndexOtherFile,
long maxBytes)
throws IOException
maxBytes - if 0, the entire content is compared to EOF
IOException
public String fileCompareText(File file)
throws IOException
IOException
public String fileCompareText(long beginIndexThisFile,
File otherFile,
long beginIndexOtherFile,
long maxBytes)
throws IOException
IOException
public void directoryCompare(File dir,
PrintStream ps)
throws IOException
IOException
public void directoryCompare(File dir,
PrintStream ps,
Monitor monitor)
throws IOException
IOException
public MyFile[] synchronizeDir(File destinationDir)
throws IOException
The procedure follows the follwing rules:
IllegalArgumentException - if either the current MyFile or the given
destination are not directories
IOException
public MyFile[] synchronizeDir(File destinationDir,
FileFilter filter)
throws IOException
IOException
public MyFile[] synchronizeDir(File destinationDir,
Logger logger)
throws IOException
This method allows e.g. GUIs to display status messages by implementing
a special LogWriter.
The given logger may be null, otherwise its usage is as follows:
IOExceptionsynchronizeDir(File),
Backup
public MyFile[] synchronizeDir(File destinationDir,
Logger logger,
Monitor monitor)
throws IOException
This method allows monitoring threads to abort the synchronization by disabling the given monitor during processing. The monitor/logger may be null; monitor checks occur for each directory and after each copy operation - right after the logger was called to log the operation.
IOExceptionsynchronizeDir(File, Logger),
Backup
public MyFile[] synchronizeDir(File destinationDir,
FileFilter filter,
Logger logger,
Monitor monitor)
throws IOException
IOExceptionpublic boolean removeTree(boolean includingThisRoot)
If the MyFile is not a directory, false is returned immediately (nothing gets deleted). If it is a directory but it is not empty, it will attempt to first delete all content recursively and then again the top directory. The method makes an effort to delete every file/directory; if the removal of a file or directory fails, it still tries to delete the rest.
includingThisRoot - if true, this directory is deleted along with the sub-tree
public int indexOf(String pattern)
throws IOException,
OutOfMemoryError
OutOfMemoryError - if the file doesn't fit into memory
IOException
public long indexOf(byte[] pattern)
throws IOException
IOException
public long indexOf(byte[] pattern,
int beginIndex)
throws IOException
IOException
public int count(byte[] pattern)
throws IOException
IOException
public void replace(String searchPattern,
String replacePattern)
throws IOException,
OutOfMemoryError
OutOfMemoryError - if the file doesn't fit into memory
IOException
public void replace(byte[] searchPattern,
byte[] replacePattern)
throws IOException
IOException
public String getContentAsString()
throws IOException,
OutOfMemoryError
OutOfMemoryError - if the file doesn't fit into memory
IOExceptiongetContentAsBytes()
public String getContentAsString(String charsetName)
throws IOException,
OutOfMemoryError
OutOfMemoryError - if the file doesn't fit into memory
IOExceptiongetContentAsBytes()
public byte[] getContentAsBytes()
throws IOException,
OutOfMemoryError
OutOfMemoryError - if the file doesn't fit into memory
IOExceptiongetContentAsString()
public void append(File file)
throws IOException
IOException
public void writeText(String text,
boolean append)
throws IOException
IOExceptionwriteObject(Object, boolean)
public void writeln()
throws IOException
IOException
public void writeBytes(byte[] bytes,
boolean append)
throws IOException
IOExceptionwriteObject(Object, boolean)
public void writeObject(Object obj,
boolean append)
throws IOException
IOExceptionwriteText(String, boolean),
writeBytes(byte[], boolean),
Data.serialize(java.lang.Object)
public void writeStackTrace(Throwable t,
boolean append)
throws FileNotFoundException
FileNotFoundException
public boolean writeStackTrace(Thread t,
Throwable e,
boolean append)
throws FileNotFoundException
FileNotFoundException
public void writeUTF8(String text,
boolean append)
throws IOException
IOException
public String getContentAsUTF8()
throws IOException
IOException
public void compressTo(File file)
throws IOException
uncompressTo(File).
IOExceptionuncompressTo(File)
public void uncompress(boolean deleteCompressedFile)
throws IOException,
IllegalArgumentException
IOException
IllegalArgumentException
public void uncompressTo(File file)
throws IOException
compressTo(File).
IOExceptioncompressTo(File)
public MyFile compress(boolean deleteOriginal)
throws IOException
deleteOriginal - if true, the uncompressed original file will be deleted
IOException
public Object loadObject()
throws IOException,
ClassNotFoundException
loadObject(false)
IOException
ClassNotFoundException
public Object loadObject(boolean useDeserialization)
throws IOException,
ClassNotFoundException
useDeserialization - if true, this method attepts deserialization on byte arrays
IOException
ClassNotFoundException
public Properties loadProperties()
throws IOException
IOException
public void storeProperties(Properties props,
String comment)
throws IOException
IOException
public void encrypt(String password)
throws IOException
IOException
public void decrypt(String password)
throws IOException
IOException
public Enumeration objectEnumerator()
throws IOException
IOExceptionwriteObject(Object, boolean),
ObjectEnumerator
public Enumeration objectEnumerator(boolean useDeserialization)
throws IOException
useDeserialization - specifies whether - in case the object to be returned
is a byte[] - automatic deserialization should be used.
If the deserialization fails, a byte[] is always
returned if present.
IOExceptionwriteObject(Object, boolean),
Data.deserialize(byte[]),
ObjectEnumerator
public Enumeration objectEnumerator(boolean useDeserialization,
Logger exceptionLogger)
throws IOException
IOExceptionObjectEnumerator
public void zipTo(File file)
throws IOException
IOException
public void zipTo(File file,
String comment,
Monitor monitor)
throws IOException
IOException
public void zipTo(File file,
FileFilter filter,
String comment,
Monitor monitor)
throws IOException
IOException
public void unzipTo(File directory)
throws IOException
unzipTo(directory, true)
IOException
public void unzipTo(File directory,
boolean overwriteExistingFiles)
throws IOException
IOException
public void unzipTo(File directory,
boolean overwriteExistingFiles,
Monitor monitor)
throws IOException
IOException
public void unzipTo(File directory,
FileFilter filter,
Monitor monitor)
throws IOException
IOExceptionpublic static String[] getFileTypes(File[] file)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||