|
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 | |
|---|---|
static Filter<File> |
DIRECTORIES_ONLY
|
static Filter<File> |
FILES_ONLY
|
| Fields inherited from class java.io.File |
|---|
pathSeparator, pathSeparatorChar, separator, separatorChar |
| Fields inherited from interface com.antelmann.calendar.Timed |
|---|
COMPARATOR, DATE_EXTRACTOR |
| Constructor Summary | |
|---|---|
MyFile(File file)
|
|
MyFile(File parent,
String child)
|
|
MyFile(String pathname)
|
|
MyFile(String parent,
String child)
|
|
MyFile(URI uri)
|
|
| Method Summary | |
|---|---|
Appendable |
append(char c)
|
Appendable |
append(CharSequence csq)
|
Appendable |
append(CharSequence csq,
int start,
int end)
|
void |
append(File file)
appends the content of the given file to this file |
static FileFilter |
asFileFilter(Filter<? super File> filter)
|
static Filter<File> |
asFilter(FileFilter filter)
|
Iterable<String> |
asLineIterable()
|
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 |
int |
countLines()
|
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(char[] password)
uses a 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)
|
long |
dirSize()
in case of a directory, the combined size of all files within the tree is returned; otherwise an IllegalArgumentException is thrown. |
void |
encrypt(char[] password)
uses a CipherKey |
MyFile |
ensureExtension(String extension)
returns a file that has the given (lower case) 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 |
String |
getCharset()
null by default; the platform default encoding will be used |
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()
|
Image |
getDisplayIcon()
returns an image that is suitable for use as an icon for this instance. |
Image |
getDisplayImage()
returns an image that represents a visual representation of this instance. |
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 |
ImageIcon |
getIcon()
|
AbstractIterator<String> |
getLineIterator()
|
AbstractIterator<String> |
getLineIterator(String charset)
iterates over the lines of this file using a BufferedReader |
String |
getNameWithoutExtension()
returns the file name without the type extension |
File |
getRandomFile(boolean includeSubdirectories)
|
File |
getRandomFile(FileFilter filter,
boolean includeSubdirectories)
|
static MyFile |
getTempDir()
|
long |
getTime()
|
String |
getTypeDescription()
|
static MyFile |
getUserHomeDir()
|
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,
long 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. |
boolean |
isEmpty()
|
static boolean |
isValidWindowsFilename(String name)
this method can only test for general eligibility; it cannot guarantee that the filename is actually valid for a given windows file system. |
Iterator<MyFile> |
iterateFilesInTree(Filter<? super File> filter)
|
MyFile[] |
listFilesInTree()
returns all files including those in subdirectories recursively |
MyFile[] |
listFilesInTree(FileFilter filter)
|
MyFile[] |
listFilesInTree(FilenameFilter filter)
|
MyFile[] |
listFilesInTree(Filter<? super MyFile> 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()
|
ObjectEnumerator |
objectEnumerator()
returns an Enumeration over the objects contained in this binary file with serialized objects written with an ObjectOutputStream |
ObjectEnumerator |
objectEnumerator(boolean useDeserialization)
returns an Enumeration over the objects contained in this binary file with serialized objects written with an ObjectOutputStream. |
ObjectEnumerator |
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 |
setCharset(String charset)
|
void |
storeProperties(Properties props,
String comment)
|
static String |
stripToWindowsFilename(String str)
|
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)
This method allows for intermediate feedback and interactive stopping; otherwise it's the same as the other synchronizeDir() method. |
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)
|
void |
writeText(String text,
String encoding,
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 |
|---|
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toString, toURI, toURL |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static Filter<File> DIRECTORIES_ONLY
public static Filter<File> FILES_ONLY
| 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 String getCharset()
public void setCharset(String charset)
public boolean touch()
throws IOException
setLastModified(System.currentTimeMillis())
after possibly creating the file if it didn't exist before.
IOExceptionFile.setLastModified(long)
public void clear()
throws IOException
IOExceptionpublic boolean isEmpty()
public static MyFile getWorkingDir()
public static MyFile getTempDir()
public static MyFile getUserHomeDir()
public long dirSize()
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 Iterator<MyFile> iterateFilesInTree(Filter<? super File> filter)
public MyFile[] listFilesInTree()
public MyFile[] listFilesInTree(Filter<? super MyFile> filter)
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
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),
Backuppublic 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
IOExceptionindexOf(byte[])
public long indexOf(byte[] pattern)
throws IOException
IOException
public long indexOf(byte[] pattern,
long beginIndex)
throws IOException
IOException
public int countLines()
throws IOException
IOExceptiongetLineIterator(String)
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 Iterable<String> asLineIterable()
throws FileNotFoundException,
UnsupportedEncodingException
FileNotFoundException
UnsupportedEncodingException
public AbstractIterator<String> getLineIterator()
throws FileNotFoundException,
UnsupportedEncodingException
FileNotFoundException
UnsupportedEncodingException
public AbstractIterator<String> getLineIterator(String charset)
throws FileNotFoundException,
UnsupportedEncodingException
FileNotFoundException
UnsupportedEncodingExceptioncountLines()
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 Appendable append(CharSequence csq)
throws IOException
append in interface AppendableIOException
public Appendable append(CharSequence csq,
int start,
int end)
throws IOException
append in interface AppendableIOException
public Appendable append(char c)
throws IOException
append in interface AppendableIOException
public void writeText(String text,
boolean append)
throws IOException
IOException
public void writeText(String text,
String encoding,
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(char[] password)
throws IOException
CipherKey
IOException
public void decrypt(char[] password)
throws IOException
CipherKey
IOException
public ObjectEnumerator objectEnumerator()
throws IOException
IOExceptionwriteObject(Object, boolean),
ObjectEnumerator
public ObjectEnumerator 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 ObjectEnumerator 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 String getTypeDescription()
public ImageIcon getIcon()
public Image getDisplayImage()
throws IOException
Imageable
getDisplayImage in interface ImageableIOException
public Image getDisplayIcon()
throws IOException
Imageable
getDisplayIcon in interface ImageableIOExceptionpublic File getRandomFile(boolean includeSubdirectories)
public File getRandomFile(FileFilter filter,
boolean includeSubdirectories)
public long getTime()
getTime in interface Timedpublic static FileFilter asFileFilter(Filter<? super File> filter)
public static Filter<File> asFilter(FileFilter filter)
public static String[] getFileTypes(File[] file)
public static boolean isValidWindowsFilename(String name)
public static String stripToWindowsFilename(String str)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||