Joshua
open source statistical hierarchical phrase-based machine translation system
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
joshua.util.FileUtility Class Reference
Collaboration diagram for joshua.util.FileUtility:
[legend]

List of all members.

Static Public Member Functions

static BufferedWriter getWriteFileStream (String filename) throws IOException
static boolean deleteRecursively (File f)
static FileOutputStream writeBytes (int[] data, String filename) throws IOException
static void writeBytes (int[] data, OutputStream out) throws IOException
static void copyFile (String srFile, String dtFile) throws IOException
static void copyFile (File srFile, File dtFile) throws IOException
static boolean deleteFile (String fileName)
static String dirname (String fileName)
static void createFolderIfNotExisting (String folderName)
static void closeCloseableIfNotNull (Closeable fileWriter)
static String getWorkingDirectory ()
static void handleExceptions (Exception e)
static String getFileAsString (File file)
static List< String > getLines (File file, boolean keepDuplicates)
static Scanner getScanner (File inputFile, String encoding)
static Scanner getScanner (File inputFile)
static String getFirstLineInFile (File inputFile)

Static Public Attributes

static String DEFAULT_ENCODING = "UTF-8"

Static Private Attributes

static final Charset FILE_ENCODING = Charset.forName(DEFAULT_ENCODING)

Detailed Description

utility functions for file operations

Author:
Zhifei Li, zhife.nosp@m.i.wo.nosp@m.rk@gm.nosp@m.ail..nosp@m.com
wren ng thornton wren@.nosp@m.user.nosp@m.s.sou.nosp@m.rcef.nosp@m.orge..nosp@m.net
Since:
28 February 2009

Member Function Documentation

static void joshua.util.FileUtility.closeCloseableIfNotNull ( Closeable  fileWriter) [static]
static void joshua.util.FileUtility.copyFile ( String  srFile,
String  dtFile 
) throws IOException [static]
static void joshua.util.FileUtility.copyFile ( File  srFile,
File  dtFile 
) throws IOException [static]
static void joshua.util.FileUtility.createFolderIfNotExisting ( String  folderName) [static]
static boolean joshua.util.FileUtility.deleteFile ( String  fileName) [static]
static boolean joshua.util.FileUtility.deleteRecursively ( File  f) [static]

Recursively delete the specified file or directory.

Parameters:
fFile or directory to delete
Returns:
true if the specified file or directory was deleted, false otherwise
static String joshua.util.FileUtility.dirname ( String  fileName) [static]

Returns the base directory of the file. For example, dirname('/usr/local/bin/emacs') -> '/usr/local/bin'

Here is the caller graph for this function:

static String joshua.util.FileUtility.getFileAsString ( File  file) [static]

Convenience method to get a full file as a String

Parameters:
file
Returns:
The file as a String. Lines are separated by newline character.

Here is the call graph for this function:

static String joshua.util.FileUtility.getFirstLineInFile ( File  inputFile) [static]

Here is the call graph for this function:

static List<String> joshua.util.FileUtility.getLines ( File  file,
boolean  keepDuplicates 
) [static]

This method returns a List of String. Each element of the list corresponds to a line from the input file. The boolean keepDuplicates in the input determines if duplicate lines are allowed in the output LinkedList or not.

Here is the call graph for this function:

Here is the caller graph for this function:

static Scanner joshua.util.FileUtility.getScanner ( File  inputFile,
String  encoding 
) [static]

Returns a Scanner of the inputFile using a specific encoding

Parameters:
inputFile
Returns:
: Scanner

Here is the call graph for this function:

Here is the caller graph for this function:

static Scanner joshua.util.FileUtility.getScanner ( File  inputFile) [static]

Returns a Scanner of the inputFile using default encoding

Parameters:
inputFile
Returns:
: Scanner

Here is the call graph for this function:

static String joshua.util.FileUtility.getWorkingDirectory ( ) [static]

Returns the directory were the program has been started, the base directory you will implicitly get when specifying no full path when e.g. opening a file

Returns:
static BufferedWriter joshua.util.FileUtility.getWriteFileStream ( String  filename) throws IOException [static]

Warning, will truncate/overwrite existing files

Here is the caller graph for this function:

static void joshua.util.FileUtility.handleExceptions ( Exception  e) [static]

Method to handle standard IO xceptions. catch (Exception e) {Utility.handleIO_exception(e);}

Here is the caller graph for this function:

static FileOutputStream joshua.util.FileUtility.writeBytes ( int[]  data,
String  filename 
) throws IOException [static]

Writes data from the integer array to disk as raw bytes, overwriting the old file if present.

Parameters:
dataThe integer array to write to disk.
filenameThe filename where the data should be written.
Exceptions:
IOException
Returns:
the FileOutputStream on which the bytes were written
static void joshua.util.FileUtility.writeBytes ( int[]  data,
OutputStream  out 
) throws IOException [static]

Writes data from the integer array to disk as raw bytes.

Parameters:
dataThe integer array to write to disk.
outThe output stream where the data should be written.
Exceptions:
IOException

Member Data Documentation

String joshua.util.FileUtility.DEFAULT_ENCODING = "UTF-8" [static]
final Charset joshua.util.FileUtility.FILE_ENCODING = Charset.forName(DEFAULT_ENCODING) [static, private]