2.14.2: 2010-02-22

net.sf.basedb.clients.migrate
Class FileTransfer

java.lang.Object
  extended by net.sf.basedb.clients.migrate.Manager
      extended by net.sf.basedb.clients.migrate.Transfer
          extended by net.sf.basedb.clients.migrate.SharedItemTransfer
              extended by net.sf.basedb.clients.migrate.CommonItemTransfer
                  extended by net.sf.basedb.clients.migrate.FileTransfer
Direct Known Subclasses:
ImageFileTransfer, UploadFileTransfer

abstract class FileTransfer
extends CommonItemTransfer

This class provides methods to transfer base 1 items that correspond to the File object in BASE 2.

Version:
2.0
Author:
Gregory
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
private static Pattern forbiddenCharacters
           
private static Logger log
          Logger for this class
protected  boolean VERIFY_MD5
          Indicates wether MD5 should be calculated or not.
 
Fields inherited from class net.sf.basedb.clients.migrate.CommonItemTransfer
DESCRIPTION, NAME, REMOVED
 
Fields inherited from class net.sf.basedb.clients.migrate.SharedItemTransfer
GID, GROUP_ACCESS, groupT, ID, OWNER, userT, WORLD_ACCESS
 
Fields inherited from class net.sf.basedb.clients.migrate.Transfer
BASE2, FROM, itemList, LIMIT, LOCAL_MYSQL_TRANSFER, mapIds, progress, properties, QUICK_TRANSFER, selectOffset, sessionControl, TO
 
Constructor Summary
FileTransfer(UserTransfer userT, GroupTransfer groupT)
          Constructs a new FileTransfer.
 
Method Summary
protected  File getExistingFile(User owner, String fileName, String location)
          Returns an existing file if the name and md5sum matches a file already in the database.
protected  String md5sum(File file)
          Calculates MD5sum for a file
protected  String md5sum(String fileLocation)
          Returns the md5sum for a file specified by the fileLocation.
protected static String replaceForbiddenCharacters(String in, String replacement)
          Replaces forbidden characters for file or directory names.
protected  void setCommonItemData(DbControl dc, File file, ResultSet rs)
          Sets common item data for File objects.
protected  void transferFile(File file, String theOldBase1File, String md5)
          Physically transfers a file.
 
Methods inherited from class net.sf.basedb.clients.migrate.CommonItemTransfer
setCommonItemData
 
Methods inherited from class net.sf.basedb.clients.migrate.SharedItemTransfer
chmod, chown, getOwner, setSharedItemData
 
Methods inherited from class net.sf.basedb.clients.migrate.Transfer
cleanUpMemory, commit, createItem, createItem, dependencyFailure, done, getBase2Id, getBatchSize, getCount, getDependencyStatus, getIdMap, getInt, getProperty, initIdMap, isDone, mapId, newDbControl, readRestorePointData, run, run, runUnBatched, saveItem, setup, start, startProgress, writeRestorePointData
 
Methods inherited from class net.sf.basedb.clients.migrate.Manager
getPreparedStatements, prepareStatementFromFile, print, printDate, setPreparedStatements, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERIFY_MD5

protected boolean VERIFY_MD5
Indicates wether MD5 should be calculated or not. This is always true.


log

private static final Logger log
Logger for this class


forbiddenCharacters

private static Pattern forbiddenCharacters
Constructor Detail

FileTransfer

FileTransfer(UserTransfer userT,
             GroupTransfer groupT)
Constructs a new FileTransfer.

Parameters:
userT - A finished UserTransfer
groupT - A finished GroupTransfer
Method Detail

transferFile

protected void transferFile(File file,
                            String theOldBase1File,
                            String md5)
Physically transfers a file. Retries to upload the file three times or until the md5sum is correct.

Parameters:
file - File in BASE 2 used for upload
theOldBase1File - Full path to the base 1 file
md5 - Calculated md5sum of theOldBase1File
See Also:
md5sum(String)

md5sum

protected String md5sum(File file)
Calculates MD5sum for a file

Parameters:
file - java.io.File to calculate the md5sum on
Returns:
md5sum or null if no file exists

md5sum

protected String md5sum(String fileLocation)
Returns the md5sum for a file specified by the fileLocation.

Parameters:
fileLocation - String e.g. "/tmp/file.tif"
Returns:
md5sum or null if no file exists

replaceForbiddenCharacters

protected static String replaceForbiddenCharacters(String in,
                                                   String replacement)
Replaces forbidden characters for file or directory names.


getExistingFile

protected File getExistingFile(User owner,
                               String fileName,
                               String location)
Returns an existing file if the name and md5sum matches a file already in the database.

Parameters:
owner - User that might already have this file.
fileName - Name of the file including suffix. e.g. A123file.txt
location - A complete path to the base 1 file.
Returns:
File or null if a file could not be created. The returned file must be reattached to a DbControl if it is to be updated.

setCommonItemData

protected void setCommonItemData(DbControl dc,
                                 File file,
                                 ResultSet rs)
Sets common item data for File objects.

Parameters:
dc -
file - File for which to set the data
rs - ResultSet containing data for the current file

2.14.2: 2010-02-22