futils
Class Futil

java.lang.Object
  extended by futils.Futil

public final class Futil
extends java.lang.Object

The Futil class contains a number of methods for manipulating files.

Version:
2.0
Author:
Douglas Lyon

Method Summary
static int available(java.io.File file)
           
static void binaryCopyFile()
           
static void binaryCopyFile(java.io.FileInputStream fis, java.io.FileOutputStream fos)
          copy the file input stream into the file output stream.
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 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 java.lang.String getCurrentDirectory()
           
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.lang.String[] getFileNames(java.lang.String pathname)
           
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.FileWriter getFileWriter()
           
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 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 getWriteFile(java.lang.String prompt)
           
static java.io.File getWriteFileSwing(java.lang.String prompt)
           
static boolean isSwing()
          check the state of the isSwing property.
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 void permission(java.io.File f)
           
static void print(byte[] b)
           
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 setLastSelectedFile(java.io.File f)
           
static void setLookAndFeel()
           
static void setSwing(boolean b)
          Use to set if swing is used for open dialog boxes.
static void showFileInfo()
           
static java.io.File sort(java.io.File[] f)
          Sort the list of files in alphabetic order
static void testCopyFile()
           
static void testFilePermission()
           
static void testGetDirFile()
           
static void testGetReadDirs()
           
static void testGetReadFile()
           
static void testGetReadFiles()
           
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
 

Method Detail

showFileInfo

public static void showFileInfo()

binaryCopyFile

public static void binaryCopyFile()

binaryCopyFile

public static void binaryCopyFile(java.io.FileInputStream fis,
                                  java.io.FileOutputStream fos)
                           throws java.io.IOException
copy the file input stream into the file output stream.

Throws:
java.io.IOException

print

public static void print(byte[] b)

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.


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.


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.

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)

isSwing

public static boolean isSwing()
check the state of the isSwing property. If false, AWT will be used, instead (mostly).

Returns:
true if swing

setSwing

public static void setSwing(boolean b)
Use to set if swing is used for open dialog boxes.

Parameters:
b -

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:


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 -
Returns:
a file instance

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.

main

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

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

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)

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)

setLookAndFeel

public static void setLookAndFeel()

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.

getCurrentDirectory

public static java.lang.String getCurrentDirectory()

setLastSelectedFile

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

getFileNames

public static java.lang.String[] getFileNames(java.lang.String pathname)