marytts.util.io
Class FileUtils

java.lang.Object
  extended by marytts.util.io.FileUtils

public class FileUtils
extends java.lang.Object

A collection of public static utility methods, doing file operations.

Author:
schroed

Constructor Summary
FileUtils()
           
 
Method Summary
static void changeFileExtensions(java.lang.String folder, java.lang.String oldExt, java.lang.String newExt)
           
static void close(java.io.Closeable... closeables)
          Close closeables.
static void close(java.sql.PreparedStatement ps, java.sql.ResultSet... rs)
          Close a PreparedStatement and a series of result sets.
static void close(java.net.Socket socket, java.io.Closeable... closeables)
           
static void copy(java.io.File source, java.io.File dest)
           
static void copy(java.lang.String sourceFile, java.lang.String destinationFile)
           
static void copyFolder(java.lang.String sourceFolder, java.lang.String targetFolder)
           
static void copyFolder(java.lang.String sourceFolder, java.lang.String targetFolder, boolean bForceDeleteTarget)
           
static void copyFolderRecursive(java.lang.String sourceFolder, java.lang.String targetFolder, boolean bForceDeleteTarget)
           
static void createDirectory(java.lang.String trainingBaseFolder)
           
static void delete(java.lang.String file)
           
static void delete(java.lang.String[] files)
           
static void delete(java.lang.String[] files, boolean bDisplayInfo)
           
static void delete(java.lang.String file, boolean bDisplayInfo)
           
static boolean exists(java.lang.String file)
           
static byte[] getFileAsBytes(java.io.File file)
           
static byte[] getFileAsBytes(java.lang.String filename)
           
static java.lang.String getFileAsString(java.io.File file, java.lang.String encoding)
          Deprecated. use FileUtils.readFileToString(File, String) instead
static java.lang.String[] getFileList(java.lang.String directory, java.lang.String extension)
           
static java.lang.String[] getFileList(java.lang.String directory, java.lang.String extension, boolean recurse)
           
static java.lang.String getFileName(java.lang.String fileNameWithPath)
          Given a file name with path it return the file name
static java.lang.String[] getFileNameList(java.lang.String directory, java.lang.String extension)
           
static java.lang.String[] getFileNameList(java.lang.String directory, java.lang.String extension, boolean recurse)
           
static java.lang.String getReaderAsString(java.io.Reader reader)
           
static java.lang.String getStreamAsString(java.io.InputStream inputStream, java.lang.String encoding)
           
static boolean isDirectory(java.lang.String dirName)
           
static java.lang.String[] listBasenames(java.io.File directory, java.lang.String suffix)
          List the basenames of all files in directory that end in suffix, without that suffix.
static java.util.Collection<java.io.File> listFiles(java.io.File directory, java.io.FilenameFilter filter, boolean recurse)
           
static java.io.File[] listFilesAsArray(java.io.File directory, java.io.FilenameFilter filter, boolean recurse)
           
static void main(java.lang.String[] args)
           
static int[] readFromBinaryFile(java.lang.String filename)
           
static void rename(java.lang.String existingFile, java.lang.String newFilename)
           
static void writeBinaryFile(double[] x, java.io.DataOutputStream d)
           
static void writeBinaryFile(double[] x, java.lang.String filename)
           
static void writeBinaryFile(float[] x, java.io.DataOutputStream d)
           
static void writeBinaryFile(float[] x, java.lang.String filename)
           
static void writeBinaryFile(int[] x, java.io.DataOutputStream d)
           
static void writeBinaryFile(int[] x, java.lang.String filename)
           
static void writeBinaryFile(short[] x, java.io.DataOutputStream d)
           
static void writeBinaryFile(short[] x, java.lang.String filename)
           
static void writeTextFile(Allophone[] phns, java.lang.String textFile)
           
static void writeTextFile(double[][] x, java.lang.String filename)
           
static void writeTextFile(double[] x, java.lang.String filename)
           
static void writeTextFile(float[] x, java.lang.String filename)
           
static void writeTextFile(int[] x, java.lang.String filename)
           
static void writeTextFile(java.lang.String[][] textInRows, java.lang.String textFile)
           
static void writeTextFile(java.lang.String[] textInRows, java.lang.String textFile)
           
static void writeTextFile(java.util.Vector<java.lang.String> textInRows, java.lang.String textFile)
           
static void writeToTextFile(double[] array, java.lang.String textFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

close

public static void close(java.net.Socket socket,
                         java.io.Closeable... closeables)

close

public static void close(java.sql.PreparedStatement ps,
                         java.sql.ResultSet... rs)
Close a PreparedStatement and a series of result sets. Use this in a finally clause. While closing the PreparedStatement supposedly closes it's resultsets, i was told that some buggy implementations don't. Exists because PreparedStatement and ResultŜet are only closeable on jdk 1.7


close

public static void close(java.io.Closeable... closeables)
Close closeables. Use this in a finally clause.

Parameters:
Closeables - closeables to close.

listBasenames

public static java.lang.String[] listBasenames(java.io.File directory,
                                               java.lang.String suffix)
List the basenames of all files in directory that end in suffix, without that suffix. For example, if suffix is ".wav", return the names of all .wav files in the directory, but without the .wav extension. The file names are sorted in alphabetical order, according to java's string search.

Parameters:
directory -
suffix -
Returns:

getFileAsString

@Deprecated
public static java.lang.String getFileAsString(java.io.File file,
                                                          java.lang.String encoding)
                                        throws java.io.IOException
Deprecated. use FileUtils.readFileToString(File, String) instead

Read a file into a string, using the given encoding, and return that string.

Parameters:
file -
encoding -
Returns:
Throws:
java.io.IOException

getStreamAsString

public static java.lang.String getStreamAsString(java.io.InputStream inputStream,
                                                 java.lang.String encoding)
                                          throws java.io.IOException
Throws:
java.io.IOException

getReaderAsString

public static java.lang.String getReaderAsString(java.io.Reader reader)
                                          throws java.io.IOException
Throws:
java.io.IOException

getFileAsBytes

public static byte[] getFileAsBytes(java.lang.String filename)
                             throws java.io.IOException
Throws:
java.io.IOException

getFileAsBytes

public static byte[] getFileAsBytes(java.io.File file)
                             throws java.io.IOException
Throws:
java.io.IOException

writeToTextFile

public static void writeToTextFile(double[] array,
                                   java.lang.String textFile)

writeBinaryFile

public static void writeBinaryFile(short[] x,
                                   java.lang.String filename)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(short[] x,
                                   java.io.DataOutputStream d)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(float[] x,
                                   java.lang.String filename)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(float[] x,
                                   java.io.DataOutputStream d)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(double[] x,
                                   java.lang.String filename)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(double[] x,
                                   java.io.DataOutputStream d)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(int[] x,
                                   java.lang.String filename)
                            throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(int[] x,
                                   java.io.DataOutputStream d)
                            throws java.io.IOException
Throws:
java.io.IOException

readFromBinaryFile

public static int[] readFromBinaryFile(java.lang.String filename)
                                throws java.io.IOException
Throws:
java.io.IOException

exists

public static boolean exists(java.lang.String file)

delete

public static void delete(java.lang.String file,
                          boolean bDisplayInfo)

delete

public static void delete(java.lang.String file)

delete

public static void delete(java.lang.String[] files,
                          boolean bDisplayInfo)

delete

public static void delete(java.lang.String[] files)

copy

public static void copy(java.lang.String sourceFile,
                        java.lang.String destinationFile)
                 throws java.io.IOException
Throws:
java.io.IOException

copy

public static void copy(java.io.File source,
                        java.io.File dest)
                 throws java.io.IOException
Throws:
java.io.IOException

copyFolder

public static void copyFolder(java.lang.String sourceFolder,
                              java.lang.String targetFolder)
                       throws java.io.IOException
Throws:
java.io.IOException

copyFolder

public static void copyFolder(java.lang.String sourceFolder,
                              java.lang.String targetFolder,
                              boolean bForceDeleteTarget)
                       throws java.io.IOException
Throws:
java.io.IOException

copyFolderRecursive

public static void copyFolderRecursive(java.lang.String sourceFolder,
                                       java.lang.String targetFolder,
                                       boolean bForceDeleteTarget)
                                throws java.io.IOException
Throws:
java.io.IOException

createDirectory

public static void createDirectory(java.lang.String trainingBaseFolder)

isDirectory

public static boolean isDirectory(java.lang.String dirName)

rename

public static void rename(java.lang.String existingFile,
                          java.lang.String newFilename)

changeFileExtensions

public static void changeFileExtensions(java.lang.String folder,
                                        java.lang.String oldExt,
                                        java.lang.String newExt)

getFileName

public static java.lang.String getFileName(java.lang.String fileNameWithPath)
Given a file name with path it return the file name

Parameters:
fileNameWithPath -
Returns:

getFileNameList

public static java.lang.String[] getFileNameList(java.lang.String directory,
                                                 java.lang.String extension)

getFileNameList

public static java.lang.String[] getFileNameList(java.lang.String directory,
                                                 java.lang.String extension,
                                                 boolean recurse)

getFileList

public static java.lang.String[] getFileList(java.lang.String directory,
                                             java.lang.String extension)

getFileList

public static java.lang.String[] getFileList(java.lang.String directory,
                                             java.lang.String extension,
                                             boolean recurse)

listFilesAsArray

public static java.io.File[] listFilesAsArray(java.io.File directory,
                                              java.io.FilenameFilter filter,
                                              boolean recurse)

listFiles

public static java.util.Collection<java.io.File> listFiles(java.io.File directory,
                                                           java.io.FilenameFilter filter,
                                                           boolean recurse)

writeTextFile

public static void writeTextFile(Allophone[] phns,
                                 java.lang.String textFile)

writeTextFile

public static void writeTextFile(java.lang.String[][] textInRows,
                                 java.lang.String textFile)

writeTextFile

public static void writeTextFile(java.lang.String[] textInRows,
                                 java.lang.String textFile)

writeTextFile

public static void writeTextFile(java.util.Vector<java.lang.String> textInRows,
                                 java.lang.String textFile)

writeTextFile

public static void writeTextFile(float[] x,
                                 java.lang.String filename)

writeTextFile

public static void writeTextFile(double[] x,
                                 java.lang.String filename)

writeTextFile

public static void writeTextFile(double[][] x,
                                 java.lang.String filename)

writeTextFile

public static void writeTextFile(int[] x,
                                 java.lang.String filename)

main

public static void main(java.lang.String[] args)
                 throws javax.sound.sampled.UnsupportedAudioFileException,
                        java.io.IOException
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException