public class DirReadBean extends Object
Modifier and Type | Field and Description |
---|---|
private static String |
defaultDirString |
private File |
dirFile
the directory being worked on as a
File . |
private static String |
dirString
The directory being worked on as a
String . |
private static short |
fileIndex
A index refernce to the current file we are dealing with.
|
private static String[] |
fileName
A list of filenames in the current dir.
|
private static String[] |
fileNamePath
A list of filenames path from the current dir.
|
private Hashtable |
fileSizeHash
Holds the Long size info for each file in
fileName[] . |
private static String |
lastErrorMsg
holds a String message of the last error that occured
|
private HashMap |
magMap |
private static short |
numFiles
the number of files in the current
dirFile directory. |
private String |
outText_
This String holds the results of any parsing and filtering that is
performed.
|
private static long |
totalFileSize |
private String |
winampFilename |
Constructor and Description |
---|
DirReadBean() |
Modifier and Type | Method and Description |
---|---|
void |
appendOutText(String s) |
void |
autoFormatFileNames()
Renames files to a more URL friendly format.
|
void |
autoFormatFileNames(String arg)
Formats the files in the directory specified by the passed in String.
|
String |
createWinampList(String urlRoot,
String arg,
boolean recurse)
Reads the passed in directory and produces a winamp playlist for all
mp3 files in the dir.It returns an empty string "" if the file cannot be
created and fills the lastErrorMsg field.
|
static String |
createWinampList(String urlRoot,
String dirToRead,
boolean recurse,
String filename)
Reads the passed in directory and produces a winamp playlist for all
mp3 and ogg files in the dir.
|
boolean |
doesFileExist(String s)
A helper method to abstract the work to find out if a file exists.
|
void |
finalizeOutText() |
String[] |
getArtistsNames() |
File |
getDirFile()
Gets the dirFile we are working on.
|
String |
getDirString() |
String |
getFileContents(String s) |
Long |
getFileSize(String s)
Gets the file size for the file name passed in.
|
Long |
getFileSize(String dirString,
String s)
Gets the file size for the file name passed in form the passed in
dirString directory.
|
static String |
getLastErrorMessage() |
String |
getNextFileName()
Looks up the next file in the indexed list of files being kept by this class.
|
String |
getNextFilePath()
Looks up the next file path in the indexed list of files being kept by this class.
|
Long |
getNextFileSize()
Looks up the next file in the indexed list of files and returns its size.
|
int |
getNumFiles() |
String |
getOutText()
Gets the String holding the current HTML output string.
|
String |
getTitledAuthorList(String fileExtension)
Parse the current directory for files with the spec'd extension and create a
sorted and titled list of Authored entries (mp3 files, pdf magazines etc).
|
String |
getTitledAuthorList(String fileExtension,
String pathPrefix)
Parse the current directory for files with the spec'd extension and create a
sorted and titled list of Authored entries (mp3 files, pdf magazines etc).
|
String |
getTitledAuthorList(String fileExtension,
String pathPrefix,
Vector filesToIgnore)
Parse the current directory for files with the spec'd extension and create a
sorted and titled list of Authored entries (mp3 files, pdf magazines etc).
|
Long |
getTotalFileSize() |
String |
getWinampFilename() |
boolean |
initDir(String s)
Reads the Dir and Inits all required class data.
|
boolean |
initDir(String s,
boolean recurse)
Reads the Dir and Inits all required class data.
|
boolean |
initDir(String s,
String subPath,
boolean recurse)
Reads the Dir and Inits all required class data.
|
private boolean |
initDirFile(String s)
Initisalizes the dirFile field with a new File represented by the passed in
String
|
static void |
initFileIndex() |
static void |
initFileName() |
void |
initOutText() |
static void |
main(String[] args)
For Testing Purposes
|
static String[] |
parseAuthorAndTitleFromFilename(String filename) |
String |
readDir(String arg)
Reads the passed in directory and produces HTML representing the directory.
|
protected void |
setDirFile(File f)
Directly sets the dirFile we are working on.
|
static void |
setDirString(String s)
Sets the String holding the directory this class is working on.
|
protected void |
setOutText(String s)
Sets the String holding the current HTML output string.
|
void |
setWinampFilename(String s) |
String |
spacesToCapsInFileName(String fName)
Removes any space chars ' ' from a filename and Capitalizes the next char.
|
String |
spacesToCapsInFileName(String dirString,
String fName)
Removes any space chars ' ' from a filename and Capitalizes the next char.
|
private static String lastErrorMsg
private static final String defaultDirString
private String outText_
private static String[] fileNamePath
private static short fileIndex
private static short numFiles
dirFile
directory.private Hashtable fileSizeHash
fileName[]
.private static long totalFileSize
private String winampFilename
public DirReadBean()
public static void setDirString(String s)
protected void setOutText(String s)
public String getOutText()
protected void setDirFile(File f)
The preferred way of setting this is with the initDirFile
method.
f
- the File to set dirFile to.initDirFile(String)
public File getDirFile()
private boolean initDirFile(String s)
public int getNumFiles()
public boolean initDir(String s)
s
- is the dir to init.public boolean initDir(String s, boolean recurse)
s
- is the dir to init.recurse
- specifies if it should recurse for files.public boolean initDir(String s, String subPath, boolean recurse)
s
- is the dir to init.subPath
- is the dir path to prepend to the filenames.recurse
- specifies if it should recurse for files.public void initOutText()
public static void initFileName()
public static void initFileIndex()
public void appendOutText(String s)
public void finalizeOutText()
public String getDirString()
public static String getLastErrorMessage()
public Long getTotalFileSize()
public Long getFileSize(String dirString, String s)
dirString
- the string representation of the directory.s
- the string representation of the filename to lookup.public Long getFileSize(String s)
It looks up the values in this classes Hash of the filenames... soi the readDir method or the initDir methodMUST be called before this method to ensure that the hash is initialized with the current directory info.
See also the getFileSize(String, String) method that takes the dir as well so you don't have to call readDir first
s
- the string representation of the filename to lookup.public boolean doesFileExist(String s)
s
- the string representing the file name to look for.public String getNextFileName()
public String getNextFilePath()
public Long getNextFileSize()
public String getFileContents(String s)
public String spacesToCapsInFileName(String dirString, String fName)
NOTE: The file is expected to be in the current working directorydirectory
dirString
- the directory to look in for the file name (no trailing /).fName
- a string representing the file to perform the action.public String spacesToCapsInFileName(String fName)
NOTE: The file is expected to be in the current working directorydirectory
fName
- a string representing the file to perform the actionpublic void autoFormatFileNames()
It goes through each file in the current working directory and renames it using the spacesToCapsInFileName method of renaming.
spacesToCapsInFileName(String)
,
dirFile
public void autoFormatFileNames(String arg)
This method takes a string representing the directory to use as the basis for all formatting and then performs the formatting as specified by the autoFormatFileNames() method.
WARNING: This method WRITES to the directory. It actually changes the names of the files.
arg
- a string representation of thre directory to parse.autoFormatFileNames()
public String[] getArtistsNames()
public String getWinampFilename()
public void setWinampFilename(String s)
public String getTitledAuthorList(String fileExtension, String pathPrefix, Vector filesToIgnore)
The filenames must be in the format "Author_Title.extension" for this method to create a decent list. It groups all files withthe same author into a titled group.
fileExtension
- the file extension to use as the filter for this list
(without the leading period...
example: for tbg_doc.pdf pass in pdf)filesToIgnore
- the filenames (without the extension) to not processpublic String getTitledAuthorList(String fileExtension)
The filenames must be in the format "Author_Title.extension" for this method to create a decent list. It groups all files withthe same author into a titled group.
fileExtension
- the file extension to use as the filter for this list
(without the leading period...
example: for tbg_doc.pdf pass in pdf)public String getTitledAuthorList(String fileExtension, String pathPrefix)
The filenames must be in the format "Author_Title.extension" for this method to create a decent list. It groups all files withthe same author into a titled group.
fileExtension
- the file extension to use as the filter for this list
(without the leading period...
example: for tbg_doc.pdf pass in pdf)pathPrefix
- is the path to prefix each href withpublic String readDir(String arg)
It initializes all the current directory variables for this class so other helper methods that work on a current directory have valid variables. It prepares the HTML represerntation of the directory and returns it and also places it in the outText_ variable.
arg
- the String representation of the directory to read.public static String[] parseAuthorAndTitleFromFilename(String filename)
public static String createWinampList(String urlRoot, String dirToRead, boolean recurse, String filename)
urlRoot
- the String representation of url to prepend to all the
files found. If an empty or null is sent it creates a
file:// url.dirToRead
- the String representation of the directory to read.recurse
- flags if the dir should be recursedthe
- name of the file to save.public String createWinampList(String urlRoot, String arg, boolean recurse)
urlRoot
- the String representation of url to prepend to all the
files found. If an empty or null is sent it creates a
file:// url.arg
- the String representation of the directory to read.recurse
- flags if the dir should be recursedWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses