com.topcoder.file.split
Class FileJoiner

java.lang.Object
  extended by com.topcoder.file.split.FileJoiner

public class FileJoiner
extends java.lang.Object

This class facilitates rejoining pieces of a file (split files) together to recreate the original file. Methods here provide a means to join multiple files created by a FileSplitter back into one file.

Version:
1.0
Author:
srowen, npe

Constructor Summary
FileJoiner(java.io.File firstSplitFile)
          Creates a FileJoiner from the given first split file.
 
Method Summary
 java.io.File[] getExpectedSplitFiles()
          Returns the split files that are expected by this object, and that will be joined, by parsing the header in the first split file.
 java.io.File getFirstSplitFile()
           
 java.io.File join()
          This method joins smaller files into one large file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileJoiner

public FileJoiner(java.io.File firstSplitFile)

Creates a FileJoiner from the given first split file.

Throws:
java.lang.IllegalArgumentException - if the first split file argument is null
Method Detail

getFirstSplitFile

public java.io.File getFirstSplitFile()
Returns:
first split file used by this object

join

public java.io.File join()
                  throws java.io.IOException,
                         InvalidSplitFileHeaderException

This method joins smaller files into one large file.

It reads metadata about the split files (name of the original file, number of split files, format of their names, etc.) from the first split file given to this FileJoiner object.

A file is created with the same name as the original file (read from the metadata); all the split files are located, and their data is put into the joined file, in order.

If an error occurs while joining the file, this method attempts to delete the partially joined file.

Returns:
joined file
Throws:
InvalidSplitFileHeaderException - if the first split file's header is not valid
java.io.FileNotFoundException - if the given first split file does not exist
java.io.IOException - if an exception occurs while reading/writing file data, or if the join file already exists or is not writable for any reason

getExpectedSplitFiles

public java.io.File[] getExpectedSplitFiles()
                                     throws java.io.IOException,
                                            InvalidSplitFileHeaderException

Returns the split files that are expected by this object, and that will be joined, by parsing the header in the first split file.

Returns:
the split files that are expected by this object
Throws:
InvalidSplitFileHeaderException - if the first split file's header is not valid
java.io.IOException - if an error occurs while trying to determine what split files are expected


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.