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