com.bbn.openmap.util
Class FileUtils

java.lang.Object
  extended by com.bbn.openmap.util.FileUtils

public class FileUtils
extends java.lang.Object


Field Summary
protected static java.util.logging.Logger logger
           
 
Constructor Summary
FileUtils()
           
 
Method Summary
static void copy(java.io.File fromFile, java.io.File toFile, int bufSize)
          Copy a file to another location, byte-wise.
static void deleteFile(java.io.File file)
          Delete a file or a directory, including its content.
static javax.swing.JFileChooser getChooser(java.lang.String title)
           
static java.lang.String getFilePathToOpenFromUser(java.lang.String title)
           
static java.lang.String getFilePathToOpenFromUser(java.lang.String title, javax.swing.filechooser.FileFilter ff)
           
static java.lang.String getFilePathToSaveFromUser(java.lang.String title)
           
static java.lang.String getPathToOpenFromUser(java.lang.String title, javax.swing.filechooser.FileFilter ff, int fileSelectionMode, java.lang.String acceptButtonText)
           
static java.lang.String handleResponse(javax.swing.JFileChooser chooser, int state)
           
static void openZipFile(java.lang.String zipFileName, java.io.File toDir, boolean deleteAfter)
          Unpack a zip file.
static void saveZipFile(java.lang.String zipFileName, java.io.File toBeZipped)
          Create a zip file containing the given File.
static void saveZipFile(java.lang.String zipFileName, java.util.List<java.io.File> toBeZipped)
          Create a zip file containing the files in the list.
protected static void unzip(java.util.zip.ZipInputStream zin, java.io.File f)
           
static void writeZipEntry(java.io.File toBeZipped, java.util.zip.ZipOutputStream zoStream, int prefixTrimLength)
          Writes a file to the jar stream.
protected static void writeZipEntry(java.io.File fromFile, java.util.zip.ZipOutputStream zoStream, java.lang.String entryName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger
Constructor Detail

FileUtils

public FileUtils()
Method Detail

getFilePathToSaveFromUser

public static java.lang.String getFilePathToSaveFromUser(java.lang.String title)

getFilePathToOpenFromUser

public static java.lang.String getFilePathToOpenFromUser(java.lang.String title)

getFilePathToOpenFromUser

public static java.lang.String getFilePathToOpenFromUser(java.lang.String title,
                                                         javax.swing.filechooser.FileFilter ff)

getPathToOpenFromUser

public static java.lang.String getPathToOpenFromUser(java.lang.String title,
                                                     javax.swing.filechooser.FileFilter ff,
                                                     int fileSelectionMode,
                                                     java.lang.String acceptButtonText)

getChooser

public static javax.swing.JFileChooser getChooser(java.lang.String title)

handleResponse

public static java.lang.String handleResponse(javax.swing.JFileChooser chooser,
                                              int state)

copy

public static void copy(java.io.File fromFile,
                        java.io.File toFile,
                        int bufSize)
                 throws java.io.IOException
Copy a file to another location, byte-wise.

Parameters:
fromFile - the File to copy from.
toFile - the File to copy to.
bufSize - the byte size of the transfer buffer.
Throws:
java.io.IOException - Thrown if anything goes wrong.

deleteFile

public static void deleteFile(java.io.File file)
                       throws java.io.IOException
Delete a file or a directory, including its content.

Parameters:
file - file to delete
Throws:
java.io.IOException - if there's a problem

saveZipFile

public static void saveZipFile(java.lang.String zipFileName,
                               java.io.File toBeZipped)
                        throws java.io.IOException,
                               java.io.FileNotFoundException
Create a zip file containing the given File.

Parameters:
zipFileName - The path to the zip file. If it doesn't end in .zip, .zip will be added to it.
toBeZipped - The Path of the file/directory to be zipped.
Throws:
java.io.IOException - if there's a problem
java.io.FileNotFoundException - if there's a problem

saveZipFile

public static void saveZipFile(java.lang.String zipFileName,
                               java.util.List<java.io.File> toBeZipped)
                        throws java.io.IOException,
                               java.io.FileNotFoundException
Create a zip file containing the files in the list. The entries will not have their parent's file names in their path, they are stored with the given file at the root of the zip/jar.

Parameters:
zipFileName - The path to the zip/jar file.
toBeZipped - The List of files to be placed in the zip/jar.
Throws:
java.io.IOException - if there's a problem
java.io.FileNotFoundException - if there's a problem

writeZipEntry

public static void writeZipEntry(java.io.File toBeZipped,
                                 java.util.zip.ZipOutputStream zoStream,
                                 int prefixTrimLength)
                          throws java.io.IOException
Writes a file to the jar stream.

Parameters:
toBeZipped - the file to be written
zoStream - the stream to write it to, prepared for the ZipFile/JarFile
prefixTrimLength - The number of characters to trim off the absolute path of the file to be zipped. Can be useful to adjust this to adjust the directory depth of the entry for when it is unpacked. If less than 0, only the file name will be used.
Throws:
java.io.IOException - if there's a problem

writeZipEntry

protected static void writeZipEntry(java.io.File fromFile,
                                    java.util.zip.ZipOutputStream zoStream,
                                    java.lang.String entryName)
                             throws java.io.IOException
Throws:
java.io.IOException

openZipFile

public static void openZipFile(java.lang.String zipFileName,
                               java.io.File toDir,
                               boolean deleteAfter)
Unpack a zip file.

Parameters:
zipFileName - The path name of the zip file to unpack.
toDir - the directory to put the unpacked files in.
deleteAfter - flag to delete the zip file when complete.

unzip

protected static void unzip(java.util.zip.ZipInputStream zin,
                            java.io.File f)
                     throws java.io.IOException
Throws:
java.io.IOException


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details