Package llnl.gnem.core.util.FileUtil
Class FileManager
java.lang.Object
llnl.gnem.core.util.FileUtil.FileManager
User: matzel Date: Oct 1, 2004 Time: 10:20:24 AM
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconcatenate(Vector<File> filelist, File outfile) 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.static StringRead 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')static voidcopy one file to anothercreateTextRowCollection(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 filecreateTextRowVector(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 filestatic BufferedReadergetBufferedReader(File file) Utility to create a BufferedReader for a text filestatic BufferedWritergetBufferedWriter(File file) Utility to create a BufferedWriter for a text filestatic BufferedWritergetBufferedWriter(File directory, String filename) Utility to create a BufferedWriter for a text filestatic FileManagergetStringTokens(String string) listdirectory(String regex, File directory) List the files in a directory - limited by regex characters if definedstatic FilemakeDirectory(File reference, String subdirectory) utility for making subdirectoriesstatic FileMake all subdirectories for a File if they do not already existstatic FileMake all subdirectories given by a String Pathstatic File[]openFile()Use JFileChooser to open a File using a generic statementstatic File[]Use a JFileChooser to open a Filestatic File[]Use a JFileChooser to open a FilereadBuffer(String filename) Read input from a file line by lineConverts the next line in a RandomAccessFile into a Vector of String tokens e.g.static Fileuse JFileChooser to save a filestatic Fileuse JFileChooser to save a filestatic Filestatic FileselectDirectory(File starting_directory, Component component) static FileselectDirectory(File starting_directory, Component component, String dialogtitle) static StringskipLines(RandomAccessFile file, int linesToSkip) skip a specific number of lines in a RandomAccessFilestatic StringstripSuffix(File file) This code strips the suffix from a file namestatic voidwrite(BufferedWriter out, String string) Utility to write a String to a text filestatic voidwriteLine(BufferedWriter out, String string) static voidwriteStringAsIntArray(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')static voidwriteTextFile(File file, StringBuffer stringbuffer) static voidwriteTextFile(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
-
Constructor Details
-
FileManager
public FileManager()
-
-
Method Details
-
getInstance
-
copy
copy one file to another- Parameters:
srcFile-destFile-- Throws:
IOException
-
concatenate
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 concatenateoutfile- - the outputfile to write the concatenated set- Throws:
IOException
-
readBuffer
Read input from a file line by line- Parameters:
filename-- Returns:
- Throws:
IOException
-
openFile
Use JFileChooser to open a File using a generic statement -
openFile
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 incomponent- 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
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 incomponent- 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
-
selectDirectory
-
selectDirectory
-
saveFile
use JFileChooser to save a file- Parameters:
defaultfile- - if not null- the working directory to save the filecomponent- - the Graphical Component used to call this procedure (e.g. "JFrame ...")- Returns:
- the File
-
saveFile
use JFileChooser to save a file- Parameters:
defaultfile- - if not null- the working directory to save the filecomponent- - the Graphical Component used to call this procedure (e.g. "JFrame ...")- Returns:
- the File
-
makeDirectory
utility for making subdirectories- Parameters:
reference- - references the parent directory - if reference is a file it's parent will be the parent directorysubdirectory- - 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
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
Make all subdirectories for a File if they do not already exist- Parameters:
newPath-- Returns:
- the File if created
-
writeTextFile
- Parameters:
file-stringbuffer-
-
writeTextFile
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 writtentextrowvector- : the vector of text strings to be written
-
getBufferedWriter
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
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
Utility to create a BufferedWriter for a text file- Returns:
- a BufferedWriter for writing to the File
- Throws:
IOException
-
write
Utility to write a String to a text file- Parameters:
out- - the BufferedWriterstring- - the String to be written
-
writeLine
-
createTextRowVector
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
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
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
skip a specific number of lines in a RandomAccessFile- Parameters:
file- - the RandomAccessFilelinesToSkip- - an integer number of lines to skip- Returns:
- - the RandomAccessFile readline() String result for the last line
- Throws:
IOException
-
getStringTokens
-
stripSuffix
This code strips the suffix from a file name -
convertIntArrayToString
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
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 stringos- the DataOutputStream
-
listdirectory
List the files in a directory - limited by regex characters if defined- Parameters:
regex-directory-- Returns:
-