Class FileManager

java.lang.Object
llnl.gnem.core.util.FileUtil.FileManager

public class FileManager extends Object
User: matzel Date: Oct 1, 2004 Time: 10:20:24 AM
  • Constructor Details

    • FileManager

      public FileManager()
  • Method Details

    • getInstance

      public static FileManager getInstance()
    • copy

      public static void copy(File srcFile, File destFile) throws IOException
      copy one file to another
      Parameters:
      srcFile -
      destFile -
      Throws:
      IOException
    • concatenate

      public static void concatenate(Vector<File> filelist, File outfile) throws IOException
      derived from http://java.sun.com/docs/books/tutorial/essential/io/catstreams.html use to concatenate a series of input stream objects The SequenceInputStream creates a single input stream from multiple input sources. Concatenate, uses SequenceInputStream to implement a concatenation utility that sequentially concatenates files together in the order they are listed.
      Parameters:
      filelist - - a vector of Files to concatenate
      outfile - - the outputfile to write the concatenated set
      Throws:
      IOException
    • readBuffer

      public String readBuffer(String filename) throws IOException
      Read input from a file line by line
      Parameters:
      filename -
      Returns:
      Throws:
      IOException
    • openFile

      public static File[] openFile()
      Use JFileChooser to open a File using a generic statement
    • openFile

      public static File[] openFile(String type, File directory, Component component)
      Use a JFileChooser to open a File
      Parameters:
      type - - the suffix type of file to open (e.g. "", "txt", "sac"...)
      directory - - a File object pointing to the directory to start the search in
      component - the Graphical Component used to call this procedure (e.g. "JFrame ...")
      Returns:
      the opened File Note for a generic case use openFile("", null, null)
    • openFile

      public static File[] openFile(String type, File directory, Component component, String dialogtitle)
      Use a JFileChooser to open a File
      Parameters:
      type - - the suffix type of file to open (e.g. "", "txt", "sac"...)
      directory - - a File object pointing to the directory to start the search in
      component - the Graphical Component used to call this procedure (e.g. "JFrame ...")
      dialogtitle -
      Returns:
      the opened File Note for a generic case use openFile("", null, null)
    • selectDirectory

      public static File selectDirectory()
    • selectDirectory

      public static File selectDirectory(File starting_directory, Component component)
    • selectDirectory

      public static File selectDirectory(File starting_directory, Component component, String dialogtitle)
    • saveFile

      public static File saveFile(File defaultfile, Component component)
      use JFileChooser to save a file
      Parameters:
      defaultfile - - if not null- the working directory to save the file
      component - - the Graphical Component used to call this procedure (e.g. "JFrame ...")
      Returns:
      the File
    • saveFile

      public static File saveFile(File defaultfile, Component component, String dialogtitle)
      use JFileChooser to save a file
      Parameters:
      defaultfile - - if not null- the working directory to save the file
      component - - the Graphical Component used to call this procedure (e.g. "JFrame ...")
      Returns:
      the File
    • makeDirectory

      public static File makeDirectory(File reference, String subdirectory)
      utility for making subdirectories
      Parameters:
      reference - - references the parent directory - if reference is a file it's parent will be the parent directory
      subdirectory - - the String denoting the desired subdirectory
      Returns:
      the subdirectory or null if unable to create it. Note if the directory already exists this will return null
    • mkdirs

      public static File mkdirs(String newPathString)
      Make all subdirectories given by a String Path
      Parameters:
      newPathString -
      Returns:
      the File if created usage: e.g. String newPath = path + File.separator + year + File.separator + jday + File.separator + hour; FileManager.mkdirs(newPath);
    • mkdirs

      public static File mkdirs(File newPath)
      Make all subdirectories for a File if they do not already exist
      Parameters:
      newPath -
      Returns:
      the File if created
    • writeTextFile

      public static void writeTextFile(File file, StringBuffer stringbuffer)
      Parameters:
      file -
      stringbuffer -
    • writeTextFile

      public static void writeTextFile(File file, Vector<String> textrowvector)
      Write a Text File Given a vector of String objects Each Vector element is treated as a separate line of the file
      Parameters:
      file - : the File to be written
      textrowvector - : the vector of text strings to be written
    • getBufferedWriter

      public static BufferedWriter getBufferedWriter(File file) throws IOException
      Utility to create a BufferedWriter for a text file
      Parameters:
      file - the File being written to
      Returns:
      a BufferedWriter for writing to the File
      Throws:
      IOException
    • getBufferedReader

      public static BufferedReader getBufferedReader(File file) throws IOException
      Utility to create a BufferedReader for a text file
      Parameters:
      file - the File being read
      Returns:
      a BufferedReader for writing to the File
      Throws:
      IOException
    • getBufferedWriter

      public static BufferedWriter getBufferedWriter(File directory, String filename) throws IOException
      Utility to create a BufferedWriter for a text file
      Returns:
      a BufferedWriter for writing to the File
      Throws:
      IOException
    • write

      public static void write(BufferedWriter out, String string)
      Utility to write a String to a text file
      Parameters:
      out - - the BufferedWriter
      string - - the String to be written
    • writeLine

      public static void writeLine(BufferedWriter out, String string)
    • createTextRowVector

      public static Vector<String> createTextRowVector(File file)
      create a Vector object including all the lines of a text file This will return a Vector of Strings - each line of the text file
      Parameters:
      file -
      Returns:
      a Vector of all the lines of the text file
    • createTextRowCollection

      public static ArrayList<String> createTextRowCollection(File file)
      create an ArrayList including all the lines of a text file This will return a Vector of Strings - each line of the text file
      Parameters:
      file -
      Returns:
      an ArrayList of all the lines of the text file
    • readLineStringTokens

      public static Vector<String> readLineStringTokens(RandomAccessFile file) throws IOException
      Converts the next line in a RandomAccessFile into a Vector of String tokens e.g. ("this is a line") TO Vector("this", "is", "a", "line")
      Parameters:
      file - a RandomAccessfile
      Returns:
      the Vector of the String tokens for the "next" line in the RandomAccessFile
      Throws:
      IOException
    • skipLines

      public static String skipLines(RandomAccessFile file, int linesToSkip) throws IOException
      skip a specific number of lines in a RandomAccessFile
      Parameters:
      file - - the RandomAccessFile
      linesToSkip - - an integer number of lines to skip
      Returns:
      - the RandomAccessFile readline() String result for the last line
      Throws:
      IOException
    • getStringTokens

      public static Vector<String> getStringTokens(String string)
    • stripSuffix

      public static String stripSuffix(File file)
      This code strips the suffix from a file name
    • convertIntArrayToString

      public static String convertIntArrayToString(DataInputStream is) throws IOException
      Read an integer array from a DataInputStream and convert it to a String Used for parsing MATLAB character output written using fwrite(fid, nchars, 'int') fwrite(fid, chararray, 'int')
      Parameters:
      is - the DataInputStream
      Returns:
      the String representation of the integer array
      Throws:
      IOException
    • writeStringAsIntArray

      public static void writeStringAsIntArray(String string, DataOutputStream os)
      Write a String as an integer array to a DataOutputStream Used for writing files that are readable by MATLAB using nchars = fread(fid, 1, 'int') matlabstring = fread(fid, nchars, 'int char')
      Parameters:
      string - the original string
      os - the DataOutputStream
    • listdirectory

      public static ArrayList<String> listdirectory(String regex, File directory)
      List the files in a directory - limited by regex characters if defined
      Parameters:
      regex -
      directory -
      Returns: