fileapart
Class chopAndMergeFiles

java.lang.Object
  extended by fileapart.chopAndMergeFiles

public class chopAndMergeFiles
extends java.lang.Object

Author:
Markus Walther (mwthp@web.de)

Field Summary
static java.lang.String CHOP_AND_MERGE_FILES_COPYRIGHT
          Copyright information
static int RET_ALL
          A return status code - All
static int RET_NO
          A return status code - No
static int RET_YES
          A return status code - Yes
 
Constructor Summary
chopAndMergeFiles()
          Sets some internal values, like the size of the internal buffer, and displays the version and copyright information.
 
Method Summary
protected  boolean checkFileOverwrite(java.lang.String filename)
          checks whether a "overwrite file?" dialog is to be launched.
 boolean checkMandatoriesForAssembling()
          Checks if all necessary strings are set.
 boolean checkMandatoriesForChopping()
          Checks whether all mandatory input variables for the chopping of a file are set.
protected  int checkOrFillList(java.io.File[] fileList, boolean create)
          Creates a list of fragment files.
 boolean chopFile(boolean verboseOutput)
          chopFile tries to write all fragment files into the desired fragment file folder.
 void chopTestOutput()
          Displays the current state of the some internal parameters regarding the process of creating fragment files.
protected  boolean createFragFilename(int i)
          Example: FileToChop == "hello.img", FragDestDir == "/home/user/frag".
protected  boolean createFragList()
          creates the internal fragment file list.
 java.lang.String getOSLanguage()
          tries to determine the language of the operating system.
protected  boolean getPos()
          Checks whether the current channel position can be accessed.
 boolean initFileAssembly()
          Performs inital tests and calculations.
 boolean initFileChopping()
          Performs inital tests and calculations.
protected  boolean isFirstFragFile(java.lang.String fileName)
          Checks whether the file name ends with "part.000".
protected  boolean isVoidString(java.lang.String s)
          Checks whether s==null or s is empty.
 int launchOverwriteDialog(java.lang.String fname)
           
 void mergeTestOutput()
           
 void onExit()
          Calls System.exit(0).
 boolean reassembleFile(boolean verboseOutput)
          Reassembles the original file from the given fragment files.
 void setFileDestDir(java.lang.String FileDestDir)
          Sets the folder in which the reassembled (the original) file will be stored.
 void setFileToChop(java.lang.String FileToChop)
          Sets the absolute path of the file to be chopped into fragments.
 void setFirstFragment(java.lang.String FirstFragment)
          Sets the location of the first fragment file
 void setFragDestDir(java.lang.String FragDestDir)
          Sets the folder which is to contain the generated fragment files.
 void setFragSize(long FragSize)
          Sets the maximal fragment file size in bytes.
protected  boolean setOrgFileName(java.io.File firstFragFile)
          Extracts the original file name from the name of the first fragment file.
 void showMessage(java.lang.String message)
          Displays a message to the console.
protected  boolean writeFragFile(int i)
          Writes a single fragment file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RET_NO

public static final int RET_NO
A return status code - No

See Also:
Constant Field Values

RET_YES

public static final int RET_YES
A return status code - Yes

See Also:
Constant Field Values

RET_ALL

public static final int RET_ALL
A return status code - All

See Also:
Constant Field Values

CHOP_AND_MERGE_FILES_COPYRIGHT

public static final java.lang.String CHOP_AND_MERGE_FILES_COPYRIGHT
Copyright information

See Also:
Constant Field Values
Constructor Detail

chopAndMergeFiles

public chopAndMergeFiles()
Sets some internal values, like the size of the internal buffer, and displays the version and copyright information.

Method Detail

onExit

public void onExit()
Calls System.exit(0).


setFileToChop

public void setFileToChop(java.lang.String FileToChop)
Sets the absolute path of the file to be chopped into fragments.

Parameters:
FileToChop - absolute path of the file to be chopped.

setFragDestDir

public void setFragDestDir(java.lang.String FragDestDir)
Sets the folder which is to contain the generated fragment files.

Parameters:
FragDestDir - absolute path to the desired folder.

setFragSize

public void setFragSize(long FragSize)
Sets the maximal fragment file size in bytes.

Parameters:
FragSize - maximal fragment file size in bytes.

checkMandatoriesForChopping

public boolean checkMandatoriesForChopping()
Checks whether all mandatory input variables for the chopping of a file are set. E.g. the file to chop, the folder for holding the generated fragments and the maximal size of a fragment file. This routine does not check any validity of the given variables, but only proofs their existence.

Returns:
true, if the variables are set, false otherwise.

initFileChopping

public boolean initFileChopping()
Performs inital tests and calculations. Use this method after having collected all mandatory data from the GUI. Called by chopFile.

Returns:
true, if the necessary input variables are correctly set, otherwise false.

getPos

protected boolean getPos()
Checks whether the current channel position can be accessed.

Returns:
the boolean result.

chopTestOutput

public void chopTestOutput()
Displays the current state of the some internal parameters regarding the process of creating fragment files.


createFragFilename

protected boolean createFragFilename(int i)
Example: FileToChop == "hello.img", FragDestDir == "/home/user/frag". Then the first fragment file will be named "/home/user/frag/hello.img.part000".

Returns:
true if the name creation succeeded, otherwise false.

writeFragFile

protected boolean writeFragFile(int i)
Writes a single fragment file.

Parameters:
i - number of the fragment file.
Returns:
true, if the file could be written, otherwise false.

chopFile

public boolean chopFile(boolean verboseOutput)
chopFile tries to write all fragment files into the desired fragment file folder. It also checks whether the neccessary inputs are sufficient

Parameters:
verboseOutput - If you set this to true, you'll get inormation about some internal settings.
Returns:
true, if the file has successfully been chopped into fragments, otherwise false.

setFileDestDir

public void setFileDestDir(java.lang.String FileDestDir)
Sets the folder in which the reassembled (the original) file will be stored.

Parameters:
FileDestDir - The folder in which the reassembled (the original) file will be stored.

setFirstFragment

public void setFirstFragment(java.lang.String FirstFragment)
Sets the location of the first fragment file

Parameters:
FirstFragment - absolute path to the first fragment file

checkMandatoriesForAssembling

public boolean checkMandatoriesForAssembling()
Checks if all necessary strings are set. E.g. the first fragment file name and the name of the destination folder.

Returns:
true if so, otherwise false.

isFirstFragFile

protected boolean isFirstFragFile(java.lang.String fileName)
Checks whether the file name ends with "part.000".

Parameters:
fileName - the file to check
Returns:
true, if it matches the criteria, otherwise false.

setOrgFileName

protected boolean setOrgFileName(java.io.File firstFragFile)
Extracts the original file name from the name of the first fragment file.

Parameters:
firstFragFile - the name of the first fragment file
Returns:
true if the file name could be extracted, otherwise false.

checkOrFillList

protected int checkOrFillList(java.io.File[] fileList,
                              boolean create)
Creates a list of fragment files. Call this method twice, first to get the count of matching files, and a second time to fill the list.

Parameters:
fileList - file list.
create - false: get the number of matching files, true: fill the list
Returns:
true if the list could be created, otherwise false.

createFragList

protected boolean createFragList()
creates the internal fragment file list.

Returns:
true if successful, otherwise false.

initFileAssembly

public boolean initFileAssembly()
Performs inital tests and calculations. Use this method after having collected all mandatory data from the GUI. Called by reassembleFile.

Returns:
true, if the necessary input variables are correctly set, otherwise false.

reassembleFile

public boolean reassembleFile(boolean verboseOutput)
Reassembles the original file from the given fragment files.

Parameters:
verboseOutput - set this parameter to true if you want to get additional information.
Returns:
true if the reassembly succeeded, otherwise false.

mergeTestOutput

public void mergeTestOutput()

showMessage

public void showMessage(java.lang.String message)
Displays a message to the console.

Parameters:
message - the message to be displayed.

getOSLanguage

public java.lang.String getOSLanguage()
tries to determine the language of the operating system.

Returns:
a string which contains information about the language.

isVoidString

protected boolean isVoidString(java.lang.String s)
Checks whether s==null or s is empty.

Parameters:
s - string to check.
Returns:
false if s is not null and not empty, otherwise true.

checkFileOverwrite

protected boolean checkFileOverwrite(java.lang.String filename)
checks whether a "overwrite file?" dialog is to be launched.

Parameters:
filename -
Returns:
true if the file should be overwritten, otherwise false.

launchOverwriteDialog

public int launchOverwriteDialog(java.lang.String fname)