net.sourceforge.geeboss.util
Class FileUtil

java.lang.Object
  extended by net.sourceforge.geeboss.util.FileUtil

public class FileUtil
extends java.lang.Object

Utility methods for files

Author:
Frederic BORRY

Field Summary
static int OP_ABORTED
          FileShop constant: Operation was aborted
static int OP_FAILED
          FileShop constant: Operation failed
static int OP_SUCCESSFULL
          FileShop constant: Operation was successfull
 
Method Summary
static void copy(java.io.FileInputStream inputStream, java.io.FileOutputStream outputStream)
          Copy one file to another
static void copy(java.lang.String src, java.lang.String dest)
          Copy one file to another
static boolean copyManifestFiles(java.lang.String toPath)
          Copys java.exe.manifest and javaw.exe.manifest to the java.home/bin/ directory, if not yet copyd.
static void copyStreams(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Copy one stream to another
static boolean exists(java.lang.String path)
          Check if the given Path points to an existing file.
static boolean exportUserSettings()
          Open a FileDialog for the user to choose where to export the "user.xml"
static java.lang.String fileToString(java.io.File file)
          Read a file into a String using ISO-8859-1 encoding
static java.lang.String fileToString(java.io.File file, java.lang.String encoding)
          Read a file into a String
static java.lang.String getContent(java.io.InputStream inS)
          Read the contents from an InputStream into a String.
static java.lang.String getContent(java.net.URL url)
          Read the contents from an URL into a String.
static java.lang.String getFilePath(int style)
          Get a path to a file from the user
static java.lang.String getFilePath(int style, java.lang.String path)
          Get a path to a file from the user
static java.lang.String getFilePath(java.lang.String[] formats, int style)
          Get the FilePath from the user
static java.lang.String getFilePath(java.lang.String[] formats, java.lang.String fileName, int style, java.lang.String path)
          Get a path to a file from the user
static java.lang.String getSavePath(java.lang.String fileName, java.lang.String format)
          Get the FilePath from the user to save the file
static int importUserSettings()
          Open a FileDialog for the user to choose from which file the settings should be imported
static boolean isMediumWriteable(java.io.File file)
          Test if the medium from where Geeboss is executed is writeable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OP_ABORTED

public static final int OP_ABORTED
FileShop constant: Operation was aborted

See Also:
Constant Field Values

OP_FAILED

public static final int OP_FAILED
FileShop constant: Operation failed

See Also:
Constant Field Values

OP_SUCCESSFULL

public static final int OP_SUCCESSFULL
FileShop constant: Operation was successfull

See Also:
Constant Field Values
Method Detail

copyStreams

public static void copyStreams(java.io.InputStream inputStream,
                               java.io.OutputStream outputStream)
                        throws java.io.IOException
Copy one stream to another

Parameters:
inputStream - the source stream
outputStream - the destination stream
Throws:
java.io.IOException - In case of an IO Error

copy

public static void copy(java.io.FileInputStream inputStream,
                        java.io.FileOutputStream outputStream)
                 throws java.io.IOException
Copy one file to another

Parameters:
inputStream - the source stream
outputStream - the destination stream
Throws:
java.io.IOException - In case of an IO Error

copy

public static void copy(java.lang.String src,
                        java.lang.String dest)
                 throws java.io.IOException
Copy one file to another

Parameters:
src - The path of the sourcefile
dest - The path of the destinationfile
Throws:
java.io.IOException - In case of an IO Error

fileToString

public static java.lang.String fileToString(java.io.File file)
                                     throws java.io.FileNotFoundException,
                                            java.io.IOException
Read a file into a String using ISO-8859-1 encoding

Parameters:
file - the file to read
Returns:
the String with the file content
Throws:
java.io.FileNotFoundException
java.io.IOException

fileToString

public static java.lang.String fileToString(java.io.File file,
                                            java.lang.String encoding)
                                     throws java.io.FileNotFoundException,
                                            java.io.IOException
Read a file into a String

Parameters:
file - the file to read
Returns:
the String with the file content
Throws:
java.io.FileNotFoundException
java.io.IOException

copyManifestFiles

public static boolean copyManifestFiles(java.lang.String toPath)
Copys java.exe.manifest and javaw.exe.manifest to the java.home/bin/ directory, if not yet copyd. These files enable WinXP Look & Feel on Windows XP operating systems.

Parameters:
toPath - Path to copy to
Returns:
true if the manifest files have been copied

exists

public static boolean exists(java.lang.String path)
Check if the given Path points to an existing file.

Parameters:
path - The path to check.
Returns:
boolean true if the File exists

exportUserSettings

public static boolean exportUserSettings()
                                  throws java.io.IOException
Open a FileDialog for the user to choose where to export the "user.xml"

Returns:
boolean true if the user has not canceld the dialog
Throws:
java.io.IOException - If an IO Error occurs

getContent

public static java.lang.String getContent(java.io.InputStream inS)
Read the contents from an InputStream into a String.

Parameters:
inS - Any InputStream (e.g. from an URL)
Returns:
String A new String from the byte array

getContent

public static java.lang.String getContent(java.net.URL url)
                                   throws java.io.IOException
Read the contents from an URL into a String.

Parameters:
url - Any valid URL that is online
Returns:
String A new String from the contents of the URL
Throws:
java.io.IOException - If an error occurs

getFilePath

public static java.lang.String getFilePath(int style)
Get a path to a file from the user

Parameters:
style - Either SWT.OPEN or SWT.SAVE
Returns:
String The file path

getFilePath

public static java.lang.String getFilePath(int style,
                                           java.lang.String path)
Get a path to a file from the user

Parameters:
style - Either SWT.OPEN or SWT.SAVE
path - If not NULL browser into given directory
Returns:
String The file path

getFilePath

public static java.lang.String getFilePath(java.lang.String[] formats,
                                           int style)
Get the FilePath from the user

Parameters:
formats - Preselected formats
style - The style of the FontDialog
Returns:
String FilePath

getFilePath

public static java.lang.String getFilePath(java.lang.String[] formats,
                                           java.lang.String fileName,
                                           int style,
                                           java.lang.String path)
Get a path to a file from the user

Parameters:
formats - List of selectable file extensions
fileName - The preselected filename for the dialog
style - Either SWT.OPEN or SWT.SAVE
path - If not NULL browser into given directory
Returns:
String The file path

getSavePath

public static java.lang.String getSavePath(java.lang.String fileName,
                                           java.lang.String format)
Get the FilePath from the user to save the file

Parameters:
fileName - Preselected filename
format - Format of the file to save
Returns:
String Save path

importUserSettings

public static int importUserSettings()
                              throws java.io.IOException
Open a FileDialog for the user to choose from which file the settings should be imported

Returns:
int Either OP_SUCCESSFULL, OP_FAILED or OP_ABORTED as result of the operation
Throws:
java.io.IOException - If an IO Error occurs

isMediumWriteable

public static boolean isMediumWriteable(java.io.File file)
Test if the medium from where Geeboss is executed is writeable

Parameters:
file - A file to write
Returns:
true if the medium is writeable


Copyright (c) 2005 The Geeboss team (http://geeboss.sourceforge.net). All Rights Reserved.