|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.jomic.tools.FileTools
public final class FileTools
Utility methods to deal with comic files.
| Field Summary | |
|---|---|
static String |
DELETE_DID_NOT_EXIST
|
static String |
DELETE_FAILED
|
static String |
DELETED
|
static String |
FORMAT_PDF
|
static String |
FORMAT_RAR
|
static String |
FORMAT_ZIP
|
static String |
NO_FOLDER_NAME
Value used as folder for files that do not have any folder in their path (for example, "hugo.png"). |
static String |
SORT_NATURAL
Sort mode using natural sort order. |
static String |
SORT_SMART
Sort mode trying to figure out if names are numbered using a moronic naming schema. |
| Method Summary | |
|---|---|
void |
attemptToDeleteAll(File dir,
Logger deleteLogger)
Attempts to recursively delete all files in dir. |
void |
copy(InputStream in,
OutputStream out)
Copy all data from in to out. |
void |
copyAndClose(InputStream in,
OutputStream out)
Copy all data from in to out, and close both streams. |
void |
copyDir(File sourceDir,
File targetDir)
Recursively copy all files and directories in sourceDir to targetDir
. |
void |
copyFile(File source,
File target)
Copy file source to target. |
CopyFileTask[] |
createCopyDirTasks(File sourceDir,
File targetDir)
|
File |
createTempDir(String prefix)
Create a temporary directory (to dump a bundle of temporary files in it later. |
void |
delete(File file)
Same as File.delete(), but throws an IOException if the file can not be deleted. |
String |
deleteOrWarn(File file,
Logger deleteLogger)
Attempt to delete file. |
String |
getAcceptableSuffixText()
|
File |
getAdjustedComicFile(File comicFile)
|
Map |
getFlattenedFolderNames(Map folderNames)
|
Map |
getFolderMap(File folder)
Get a map with all non-empty sub folders in folder as keys and a List
of all files in it as values. |
Map |
getFolderMap(File[] files)
Get a map where the keys are distinct folders in files and the values are the
respective files found in each folder. |
Map |
getFolderMap(File folder,
FileFilter filter)
Get a map with all non-empty sub folders in folder as keys and a List
of all files in it accepted by filter as values. |
Map |
getFolderNames(Map folderMap)
Get a map where the keys are all distinct folder names (without parent path) in folderMap
and the value is a list of all folders having this name. |
File |
getHomeDir()
Get the user's home directory. |
Icon |
getIconFor(File file)
Get icon for file. |
URL |
getImageResource(String name)
Get an image URL from net.sf.jomic.images. |
InputStream |
getImageResourceAsStream(String name)
Get an image InputStream from net.sf.jomic.images. |
String |
getPortableFileName(String suspiciousFileName)
Gets a portable version of suspiciousFileName contains only chars conforming to
the POSIX recommendation on portable file names. |
String |
getRelativePath(File baseDir,
File fileInBaseDir)
|
String[] |
getRelativePaths(File baseDir,
File[] filesInBaseDir)
|
long |
getSize(File fileOrDir)
Recusively get size of all files and directories in fileOrDir. |
String |
getSuffix(File file)
Get the (lower case) last suffix of name (without the "."), for example: "hugo.tar.gz" yields "gz". |
String |
getSuffix(String name)
Get the (lower case) last suffix of name (without the "."), for example: "hugo.tar.gz" yields "gz". |
String |
getWithoutLastSuffix(String fileName)
|
static FileTools |
instance()
|
boolean |
isComic(String name)
|
boolean |
isPdf(String name)
Does name indicate a PDF file? |
boolean |
isRar(String name)
Does name indicate a rar compressed archive? |
boolean |
isValidSortMode(String mode)
Is mode a valid value for property sortMode? |
boolean |
isZip(String name)
Does name indicate a zip compressed archive? |
File[] |
listFilesRecursively(File dir)
Obtain a recursive list of files in dir. |
File[] |
listFilesRecursively(File dir,
FileFilter filter)
Obtain a recursive list of files in dir using filter to decide
which files to include in the result. |
boolean |
mkdirs(File dir)
Same as File.mkdirs() but throws an IOException if the directory
does not yet exist and also cannot be created. |
String |
obtainComicFormat(File comicFile)
Figure out file type by looking at magic bytes. |
String[] |
sort(String[] filePaths,
String mode)
Sort filePaths according to mode. |
void |
writeLines(File targetFile,
String[] lines)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DELETED
public static final String DELETE_DID_NOT_EXIST
public static final String DELETE_FAILED
public static final String FORMAT_PDF
public static final String FORMAT_RAR
public static final String FORMAT_ZIP
public static final String NO_FOLDER_NAME
getFolderMap(File[]),
Constant Field Valuespublic static final String SORT_NATURAL
NaturalCaseInsensitiveOrderComparator,
Constant Field Valuespublic static final String SORT_SMART
| Method Detail |
|---|
public String getAcceptableSuffixText()
public File getAdjustedComicFile(File comicFile)
throws IOException
IOExceptionpublic Map getFlattenedFolderNames(Map folderNames)
public Map getFolderMap(File folder)
folder as keys and a List
of all files in it as values.
public Map getFolderMap(File folder,
FileFilter filter)
folder as keys and a List
of all files in it accepted by filter as values.
public Map getFolderMap(File[] files)
files and the values are the
respective files found in each folder.
public Map getFolderNames(Map folderMap)
folderMap
and the value is a list of all folders having this name.
getFolderMap(File)public File getHomeDir()
public Icon getIconFor(File file)
file.
FileView.getIcon(java.io.File)public URL getImageResource(String name)
IllegalStateException - if the image cannot be foundpublic InputStream getImageResourceAsStream(String name)
IllegalStateException - if the image cannot be foundpublic String getPortableFileName(String suspiciousFileName)
suspiciousFileName contains only chars conforming to
the POSIX recommendation on portable file names. A file name retured by this function is
guaranteed to be creatable on any common file system. This is achieved by replacing all
troublesome characters with a hyphen (-). To make the result look less silly, avoid multiple
hyphens in a row.
public String getRelativePath(File baseDir,
File fileInBaseDir)
public String[] getRelativePaths(File baseDir,
File[] filesInBaseDir)
public long getSize(File fileOrDir)
fileOrDir.
public String getSuffix(File file)
public String getSuffix(String name)
public String getWithoutLastSuffix(String fileName)
public boolean isComic(String name)
public boolean isPdf(String name)
public boolean isRar(String name)
public boolean isValidSortMode(String mode)
mode a valid value for property sortMode?
public boolean isZip(String name)
public static FileTools instance()
public void attemptToDeleteAll(File dir,
Logger deleteLogger)
dir. Every file or directory that
cannot be deleted causes a warning in the log.
public void copy(InputStream in,
OutputStream out)
throws IOException
in to out.
IOException
public void copyAndClose(InputStream in,
OutputStream out)
throws IOException
in to out, and close both streams.
IOException
public void copyDir(File sourceDir,
File targetDir)
throws IOException
sourceDir to targetDir
.
IOException
public void copyFile(File source,
File target)
throws IOException
source to target.
IOException
public CopyFileTask[] createCopyDirTasks(File sourceDir,
File targetDir)
public File createTempDir(String prefix)
throws IOException
attemptToDeleteAll or something similar.
IOExceptionFile.createTempFile(java.lang.String, java.lang.String),
attemptToDeleteAll(File, Logger)
public void delete(File file)
throws IOException
IOException
public String deleteOrWarn(File file,
Logger deleteLogger)
file. If this fails, log a warning to deleteLogger
.
public File[] listFilesRecursively(File dir)
dir.
public File[] listFilesRecursively(File dir,
FileFilter filter)
dir using filter to decide
which files to include in the result.
public boolean mkdirs(File dir)
throws FileNotFoundException
File.mkdirs() but throws an IOException if the directory
does not yet exist and also cannot be created.
FileNotFoundExceptionFile.mkdirs()
public String obtainComicFormat(File comicFile)
throws IOException
IOException - in case the format cannot be determined
public String[] sort(String[] filePaths,
String mode)
filePaths according to mode.
mode - one of: SORT_NATURAL, SORT_SMART
public void writeLines(File targetFile,
String[] lines)
throws IOException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||