jpiv2
Class FileHandling

java.lang.Object
  extended by jpiv2.FileHandling

public final class FileHandling
extends java.lang.Object

A collection of convenience methods for file handling. All methods are declared 'static', so it is not necessary to create an object to use this methods.


Constructor Summary
FileHandling()
           
 
Method Summary
static void copyFile(java.lang.String source, java.lang.String dest)
          Copy a file byte by byte.
static java.lang.Object deSerialize(java.lang.String pathname)
          Restores an object from a file.
static java.text.DecimalFormat getCounterFormat(int number)
          Get a decimal format for integer counters.
static java.lang.String getFileExtension(java.io.File f)
          Extracts the file extension from a java.io.File object.
static java.lang.String getFileExtension(java.lang.String filename)
          Extracts the file extension from a String object.
static java.lang.String getFileSeparator()
          Get the system dependent file separator.
static java.lang.String getJarDir()
          Get the absolute path to the directory of this jar-archive.
static void ncView(java.lang.String pathname)
          Dumps the variable definition of any netCDF file to standard output.
static double[][] readArrayFromFile(java.lang.String pathname)
          Reads whitespace delimited table data from an ascii or unicode file.
static double[][] readNetCdfFile(java.lang.String pathname)
          Reads netCDF files that have the format proposed by C.
static java.lang.String readTextFile(java.lang.String pathname)
          Reads a file.
static void serialize(java.lang.String pathname, java.lang.Object obj)
          Serializes an object to a file.
static java.lang.String stripExtension(java.lang.String path)
          Removes the characters after the last occurence of a "." in path inclusive the ".".
static java.lang.String stripFilename(java.io.File f)
          Get the body of a filename.
static java.lang.String stripFilename(java.lang.String path)
          Get the body of a filename.
static void writeArrayToFile(double[][] array, java.lang.String pathname, java.text.DecimalFormat df, java.lang.String header)
          Writes an array whitespace delimited to a file.
static void writeArrayToFile(int[] array, java.lang.String pathname, java.text.DecimalFormat df)
          Writes an array whitespace delimited to a file.
static void writeTextFile(java.lang.String pathname, java.lang.String s)
          Writes a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHandling

public FileHandling()
Method Detail

serialize

public static void serialize(java.lang.String pathname,
                             java.lang.Object obj)
                      throws java.io.IOException
Serializes an object to a file.

Parameters:
pathname - Pathname for saving the object.
obj - Any object.
Throws:
java.io.IOException - In case the file can not be written.

deSerialize

public static java.lang.Object deSerialize(java.lang.String pathname)
                                    throws java.io.IOException,
                                           java.io.FileNotFoundException,
                                           java.lang.ClassNotFoundException
Restores an object from a file.

Parameters:
pathname - Pathname of the object.
Returns:
obj Any object.
Throws:
java.io.IOException - In case the file can not be read.
java.io.FileNotFoundException - In case the file could not be found.
java.lang.ClassNotFoundException - In case the object can not be de-serialized. This can happen after updates or when the file was edited elsewhere.

getCounterFormat

public static java.text.DecimalFormat getCounterFormat(int number)
Get a decimal format for integer counters. Constructs a decimal format based on a string that has as many zeros as 'number' has digits. The number 156 for example will lead to a decimal format based on the string '000'. This method is useful if you want to enumerate something with the least number of leading zeros.

Parameters:
number - The maximum value of your enumeration.
Returns:
The number format.

getFileExtension

public static java.lang.String getFileExtension(java.io.File f)
Extracts the file extension from a java.io.File object.

Parameters:
f - The java.io.File object.
Returns:
The file extension or null if there is no extension.

getFileExtension

public static java.lang.String getFileExtension(java.lang.String filename)
Extracts the file extension from a String object.

Parameters:
filename - The java.io.File object.
Returns:
The file extension or null if there is no extension.

stripFilename

public static java.lang.String stripFilename(java.io.File f)
Get the body of a filename.

Parameters:
f - The file.
Returns:
The name of this file without an extension and path.

stripExtension

public static java.lang.String stripExtension(java.lang.String path)
Removes the characters after the last occurence of a "." in path inclusive the ".".

Parameters:
path - A string representing a complete file name inclusive filename extension.
Returns:
The same string with the filename extension removed.

stripFilename

public static java.lang.String stripFilename(java.lang.String path)
Get the body of a filename.

Parameters:
path - The complete filename.
Returns:
The name of this file without an extension and path.

writeArrayToFile

public static void writeArrayToFile(double[][] array,
                                    java.lang.String pathname,
                                    java.text.DecimalFormat df,
                                    java.lang.String header)
                             throws java.io.IOException
Writes an array whitespace delimited to a file.

Parameters:
array - A two dimensional array.
pathname - The full pathname of a destination file.
df - A DecimalFormat for formatting the output.
header - A file header.
Throws:
java.io.IOException - In case the file can not be created.

writeArrayToFile

public static void writeArrayToFile(int[] array,
                                    java.lang.String pathname,
                                    java.text.DecimalFormat df)
                             throws java.io.IOException
Writes an array whitespace delimited to a file.

Parameters:
array - A two dimensional array.
pathname - The full pathname of a destination file.
df - A DecimalFormat for formatting the output.
Throws:
java.io.IOException - in case the file can not be created.

readArrayFromFile

public static double[][] readArrayFromFile(java.lang.String pathname)
                                    throws java.io.IOException
Reads whitespace delimited table data from an ascii or unicode file. This method ignores header lines that contain Tecplot keywords. There is a limit of 25 columns.

Parameters:
pathname - The absolute path of a file containing a whitespace delimited table.
Returns:
A two dimensional double array containing the data of the table.
Throws:
java.io.IOException - in case no file can be created from pathname

readNetCdfFile

public static double[][] readNetCdfFile(java.lang.String pathname)
                                 throws java.io.IOException
Reads netCDF files that have the format proposed by C. Willert (http://www.meol.cnrs.fr/LML/EuroPIV2/Pages/netcdf.htm)

Parameters:
pathname - The netCDF file name.
Returns:
A double array that contains the pivData in column notation (x, y, dx, dy, flag).
Throws:
java.io.IOException - If the specified file can not be found.

ncView

public static void ncView(java.lang.String pathname)
Dumps the variable definition of any netCDF file to standard output.

Parameters:
pathname - The filename of the netCDF file.

readTextFile

public static java.lang.String readTextFile(java.lang.String pathname)
Reads a file.

Parameters:
pathname - The absolute pathname of the file.
Returns:
The UTF-8 encoded file content or null in case of an exception.

writeTextFile

public static void writeTextFile(java.lang.String pathname,
                                 java.lang.String s)
                          throws java.io.IOException
Writes a file.

Parameters:
pathname - The absolute pathname of the file.
s - The string to be written.
Throws:
java.io.IOException - In case the file can not be written.

copyFile

public static void copyFile(java.lang.String source,
                            java.lang.String dest)
Copy a file byte by byte.

Parameters:
source - Complete path of the source file.
dest - Complete path of the destination file.

getFileSeparator

public static java.lang.String getFileSeparator()
Get the system dependent file separator.

Returns:
The file separator.

getJarDir

public static java.lang.String getJarDir()
Get the absolute path to the directory of this jar-archive.

Returns:
The pathname.