futils
Class Futil

java.lang.Object
  extended by futils.Futil

public final class Futil
extends java.lang.Object


Field Summary
static java.lang.String[] winImgFileExtensionList
           
 
Method Summary
static int available(java.io.File file)
           
static void binaryCopy(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          copy the input stream into the output stream.
static void binaryCopyFile()
           
static void binaryPrint(java.io.InputStream is)
          Print out a binary input stream
static java.io.File buildFileWithExtension(java.io.File file, java.lang.String type)
          Return a file name for a certain type of files, ensuring the extension is correct.
static void canRead(java.io.File file)
          Figure out if your can read a file....needs a better interface!
static void close(java.io.InputStream is)
           
static void close(java.io.OutputStream os)
           
static void copyFile(java.io.BufferedReader br, java.io.BufferedWriter bw)
          copy and input file to an output file.
static java.io.File copyFileIntoDir(java.io.File jarFile, java.io.File workingDir)
           
static void deleteClassFiles()
           
static boolean deleteDirectory(java.io.File path)
          Recusive deletion of a file or path.
static boolean fileExists(java.lang.String s)
           
static java.lang.String FilterFileNameBug(java.lang.String fname)
          Some versions of windows will create a .* suffix on a file name The following code will strip it:
static byte[] getBytes(java.io.File f)
           
static byte[] getBytes(java.io.InputStream is)
          Suck in all the bytes from the input stream into a buffer and return the buffer after closing the stream; UrlUtils already has a way to get bytes from a URL.
static java.lang.String getExtension(java.io.File file)
          Return a file extension, or null if there is none.
static javax.swing.filechooser.FileFilter getFileFilter(java.lang.String suffix)
           
static java.io.FileInputStream getFileInputStream(java.io.File file)
           
static java.io.FileInputStream getFileInputStream(java.lang.String prompt)
           
static java.io.File[] getFileList(java.lang.String prompt)
           
static java.io.File[] getFileList2(java.lang.String prompt)
           
static java.io.FileOutputStream getFileOutputStream(java.io.File f)
           
static java.io.FileOutputStream getFileOutputStream(java.lang.String prompt)
           
static java.io.FileReader getFileReader(java.lang.String prompt)
           
static java.io.File[] getFiles(java.io.File dir)
           
static java.io.FileWriter getFileWriter()
           
static java.io.File[] getImgFileList(java.lang.String prompt)
          getImgFileList will retrieve a list of files from a directory, filtered to include only files with a common image file extension
static java.io.File getReadDir(java.lang.String title)
          Prompt the user to select a directory.
static java.io.File getReadDirFileJTree(java.lang.String prompt)
           
static java.io.File[] getReadDirs()
          Prompt the user to select directories.
static java.io.File[] getReadDirs(java.lang.String title)
          Prompt the user to select directories.
static java.io.File getReadFile(java.lang.String prompt)
          Return a file instance.
static java.io.File getReadFileAWT(java.lang.String prompt)
           
static java.io.File getReadFileDir(java.lang.String title)
          Return a directory selected by the user.
static java.lang.String getReadFileName()
           
static java.lang.String getReadFileName(java.lang.String prompt)
           
static java.io.File[] getReadFiles(javax.swing.filechooser.FileFilter ff)
          Only allow the user to select read files.
static java.io.File[] getReadFiles(java.lang.String prompt)
           
static java.io.File getReadSwingFile(java.lang.String prompt)
           
static java.net.URL getUrl(java.io.File f)
           
static java.io.File getWriteDirectory(java.lang.String prompt)
          Prompt the user to select a directory.
static java.io.File getWriteFile(java.lang.String prompt)
           
static java.io.File getWriteFileSwing(java.lang.String prompt)
           
static java.io.File JGetReadFile(java.lang.String prompt)
           
static void lowerFileNames(java.io.File thePath)
          Inputs a path to a file, lists all the files in the directory and renames them so that they are lower case.
static void main(java.lang.String[] args)
           
static void makeTocHtml()
          inputs all the files in a directory and outputs a series of HREFS in gui.html as a table of contents.
static java.lang.Object openGz(java.io.File f)
           
static void permission(java.io.File f)
           
static byte[] readBytes(java.io.File f)
          Futil.readBytes inputs a File, f and returns an array of bytes read from the file.
static void readDataFile(java.lang.String fn, double[] data)
           
static void saveCsv(java.io.File writeFile, java.util.Enumeration em)
           
static void saveCsv(java.io.File writeFile, java.lang.Object[] o)
           
static void saveGz(java.io.File writeFile, java.io.Serializable s)
           
static void showFileInfo()
           
static java.io.File sort(java.io.File[] f)
          Sort the list of files in alphabetic order
static void testBinaryCopyFile()
           
static void testCopyFile()
           
static void testFilePermission()
           
static void testGetDirFile()
           
static void testGetFileList2(java.lang.String[] args)
           
static void testGetReadDirs()
           
static void testGetReadFile()
           
static void testGetReadFiles()
           
static void testImageFileList(java.lang.String[] args)
           
static void testReadBytes()
           
static void testTextCopyFile()
           
static boolean writeBytes(java.io.File f, byte[] b)
          Futil.writeBytes inputs a File, f and byte array.
static void writeFilteredHrefFile(java.io.File inputFile, java.lang.String outputName)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

winImgFileExtensionList

public static final java.lang.String[] winImgFileExtensionList
Method Detail

showFileInfo

public static void showFileInfo()

binaryCopyFile

public static void binaryCopyFile()

binaryCopy

public static void binaryCopy(java.io.InputStream inputStream,
                              java.io.OutputStream outputStream)
                       throws java.io.IOException
copy the input stream into the output stream.

Parameters:
inputStream - any input stream
outputStream - any output stream
Throws:
java.io.IOException - on inputStream or outputStream error

binaryPrint

public static void binaryPrint(java.io.InputStream is)
                        throws java.io.IOException
Print out a binary input stream

Parameters:
is - input stream
Throws:
java.io.IOException - on InputStream error

writeBytes

public static boolean writeBytes(java.io.File f,
                                 byte[] b)
Futil.writeBytes inputs a File, f and byte array.

Any failures cause readBytes to return false and a message is printed to the console. Otherwise, writeBytes returns true.

Parameters:
f - file with write access
b - array to be written

readBytes

public static byte[] readBytes(java.io.File f)
Futil.readBytes inputs a File, f and returns an array of bytes read from the file. Any failures cause readBytes to return null. A message is printed to the console.

Parameters:
f -

deleteDirectory

public static boolean deleteDirectory(java.io.File path)
Recusive deletion of a file or path. Danger will Robinson, Take cover Dr. Smith!

Parameters:
path - to delete.
Returns:
true if the directory was delected

copyFile

public static void copyFile(java.io.BufferedReader br,
                            java.io.BufferedWriter bw)
                     throws java.io.IOException
copy and input file to an output file.

Parameters:
br -
Throws:
java.io.IOException

getFileOutputStream

public static java.io.FileOutputStream getFileOutputStream(java.lang.String prompt)

getFileOutputStream

public static java.io.FileOutputStream getFileOutputStream(java.io.File f)

getFileInputStream

public static java.io.FileInputStream getFileInputStream(java.lang.String prompt)

FilterFileNameBug

public static java.lang.String FilterFileNameBug(java.lang.String fname)
Some versions of windows will create a .* suffix on a file name The following code will strip it:

Parameters:
fname -
Returns:

permission

public static void permission(java.io.File f)

testFilePermission

public static void testFilePermission()

available

public static int available(java.io.File file)
Parameters:
file - Open the file
Returns:
-1 if file cannot be opened. Otherwise return the size, in bytes.

close

public static void close(java.io.OutputStream os)

lowerFileNames

public static void lowerFileNames(java.io.File thePath)
Inputs a path to a file, lists all the files in the directory and renames them so that they are lower case.

Parameters:
thePath - the path to file used for processing.

makeTocHtml

public static void makeTocHtml()
inputs all the files in a directory and outputs a series of HREFS in gui.html as a table of contents.


testGetReadFile

public static void testGetReadFile()

getReadFileDir

public static java.io.File getReadFileDir(java.lang.String title)
Return a directory selected by the user. Remember the last place you were by storing in in the Preferences.userRoot

Parameters:
title - titles dialog box
Returns:
User selected File or null.

getReadFile

public static java.io.File getReadFile(java.lang.String prompt)
Return a file instance. Remember the last place you were by storing in in the Preferences.userRoot

Parameters:
prompt - a prompt shown to the user
Returns:
a file instance

getReadSwingFile

public static java.io.File getReadSwingFile(java.lang.String prompt)

getReadFileAWT

public static java.io.File getReadFileAWT(java.lang.String prompt)

JGetReadFile

public static java.io.File JGetReadFile(java.lang.String prompt)

testGetReadDirs

public static void testGetReadDirs()

testGetReadFiles

public static void testGetReadFiles()

getFileFilter

public static javax.swing.filechooser.FileFilter getFileFilter(java.lang.String suffix)

getReadDirs

public static java.io.File[] getReadDirs()
Prompt the user to select directories.

Returns:
the list of directories selected by the user.

deleteClassFiles

public static void deleteClassFiles()

getReadDir

public static java.io.File getReadDir(java.lang.String title)
Prompt the user to select a directory.

Parameters:
title - the title of the directory dialog
Returns:
a read directory

getWriteDirectory

public static java.io.File getWriteDirectory(java.lang.String prompt)
Prompt the user to select a directory. save the result (if non-null) to user preferences.

Parameters:
prompt - the prompt of the directory dialog
Returns:
a read directory

getReadDirs

public static java.io.File[] getReadDirs(java.lang.String title)
Prompt the user to select directories.

Parameters:
title - the title of the directory dialog
Returns:
an array of readable directories

getReadFiles

public static java.io.File[] getReadFiles(javax.swing.filechooser.FileFilter ff)
Only allow the user to select read files.

Parameters:
ff -
Returns:
an array of readable files

getReadFiles

public static java.io.File[] getReadFiles(java.lang.String prompt)

getReadDirFileJTree

public static java.io.File getReadDirFileJTree(java.lang.String prompt)

testCopyFile

public static void testCopyFile()

getWriteFile

public static java.io.File getWriteFile(java.lang.String prompt)
Parameters:
prompt - displayed for the user in a dialog
Returns:
a file instance

getWriteFileSwing

public static java.io.File getWriteFileSwing(java.lang.String prompt)

readDataFile

public static void readDataFile(java.lang.String fn,
                                double[] data)

getFileInputStream

public static java.io.FileInputStream getFileInputStream(java.io.File file)

getFileReader

public static java.io.FileReader getFileReader(java.lang.String prompt)

getFileWriter

public static java.io.FileWriter getFileWriter()

close

public static void close(java.io.InputStream is)

writeFilteredHrefFile

public static void writeFilteredHrefFile(java.io.File inputFile,
                                         java.lang.String outputName)

getReadFileName

public static java.lang.String getReadFileName(java.lang.String prompt)

getReadFileName

public static java.lang.String getReadFileName()

fileExists

public static boolean fileExists(java.lang.String s)

getBytes

public static byte[] getBytes(java.io.File f)

getBytes

public static byte[] getBytes(java.io.InputStream is)
                       throws java.io.IOException
Suck in all the bytes from the input stream into a buffer and return the buffer after closing the stream; UrlUtils already has a way to get bytes from a URL.

Parameters:
is - any input stream of binary data
Returns:
all the bytes at once
Throws:
java.io.IOException - if stream cannot close or read.

testGetDirFile

public static void testGetDirFile()

sort

public static java.io.File sort(java.io.File[] f)
Sort the list of files in alphabetic order

Parameters:
f -
Returns:
first files parent director with "out" appended.

getFiles

public static java.io.File[] getFiles(java.io.File dir)

saveCsv

public static void saveCsv(java.io.File writeFile,
                           java.lang.Object[] o)
                    throws java.io.IOException
Throws:
java.io.IOException

saveCsv

public static void saveCsv(java.io.File writeFile,
                           java.util.Enumeration em)
                    throws java.io.IOException
Throws:
java.io.IOException

saveGz

public static void saveGz(java.io.File writeFile,
                          java.io.Serializable s)
                   throws java.io.IOException
Throws:
java.io.IOException

openGz

public static java.lang.Object openGz(java.io.File f)
                               throws java.io.IOException
Throws:
java.io.IOException

getUrl

public static java.net.URL getUrl(java.io.File f)
                           throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

getExtension

public static java.lang.String getExtension(java.io.File file)
Return a file extension, or null if there is none.

Parameters:
file -
Returns:
a file extension, or null if there is none.

buildFileWithExtension

public static java.io.File buildFileWithExtension(java.io.File file,
                                                  java.lang.String type)
Return a file name for a certain type of files, ensuring the extension is correct.

If there is no extension, it will be added.

If the extension is wrong, it will be replaced.

Parameters:
file -
type - : the extension to use (without dot)
Returns:
a file name for a certain type of files, ensuring the extension is correct.

canRead

public static void canRead(java.io.File file)
Figure out if your can read a file....needs a better interface!

Parameters:
file - The file to test

copyFileIntoDir

public static java.io.File copyFileIntoDir(java.io.File jarFile,
                                           java.io.File workingDir)

testBinaryCopyFile

public static void testBinaryCopyFile()

testReadBytes

public static void testReadBytes()

testTextCopyFile

public static void testTextCopyFile()

getFileList

public static java.io.File[] getFileList(java.lang.String prompt)

getImgFileList

public static java.io.File[] getImgFileList(java.lang.String prompt)
getImgFileList will retrieve a list of files from a directory, filtered to include only files with a common image file extension

Parameters:
prompt - - title prompt of file browser window
Returns:
File[] - a list of files filtered to include only files with a common img extension

testImageFileList

public static void testImageFileList(java.lang.String[] args)

testGetFileList2

public static void testGetFileList2(java.lang.String[] args)

getFileList2

public static java.io.File[] getFileList2(java.lang.String prompt)

main

public static void main(java.lang.String[] args)
                 throws java.io.FileNotFoundException,
                        java.net.MalformedURLException
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException