com.gubutech.xload
Class XloadCounterFileRename

java.lang.Object
  extended bycom.gubutech.xload.XloadCounterFileRename
All Implemented Interfaces:
XloadFileRename

public class XloadCounterFileRename
extends java.lang.Object
implements XloadFileRename

Class that implements a rename policy that safely renames files to an arbitrary number that increments sequentially by 1. The starting value by default is 10347 but this can be set to a desired value by using the appropriate constructor. This class will preserve file extensions and therefore will allow two or more files to exist in the same directory with the same number but with different extensions making them unique within the directory.

This class will attempt to rename every file to the appropriate name. This means that if there are many targets for a file upload then each file deployment will be given a different file name.

If for some reason a naming clash occurs then this policy will just increment the arbitrary number by 1 and attempt to rename again.

Please note that this method is not guaranteed to produce sequential numbers for files when the files are listed in chronological order.

Since:
1.0

Constructor Summary
XloadCounterFileRename()
          Creates an instance of XloadCounterFileRename using a default starting value of 10347 for the arbitrary number.
XloadCounterFileRename(int sv)
          Creates an instance of XloadCounterFileRename with a given starting value for the arbitrary number.
 
Method Summary
 java.io.File rename(java.io.File file)
          Performs the actual rename of the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XloadCounterFileRename

public XloadCounterFileRename(int sv)
Creates an instance of XloadCounterFileRename with a given starting value for the arbitrary number.

Parameters:
sv - Starting value number.
Since:
1.0

XloadCounterFileRename

public XloadCounterFileRename()
Creates an instance of XloadCounterFileRename using a default starting value of 10347 for the arbitrary number.

Since:
1.0
Method Detail

rename

public java.io.File rename(java.io.File file)
Performs the actual rename of the file. This method will initially set the file argument name to the correct arbitrary number(including original extension) and then attempt to create an empty file on disk safely as a marker. This is then used to write the actual bytes of data to. If Xload cannot create the empty marker file then the arbitrary number is increased by 1 and the process is repeated until a marker file is created. e.g.

file name - name.txt
renamed to - 10347.txt

Specified by:
rename in interface XloadFileRename
Parameters:
file - Initial file object that will be renamed and created.
Returns:
Returns the actual created file on the file system after renaming has taken place.
Throws:
java.lang.SecurityException - Thrown if there is a problem accessing files on the file system with regard to permissions set by the SecurityManager.
Since:
1.0