com.limegroup.gnutella.downloader
Class IncompleteFileManager

java.lang.Object
  extended bycom.limegroup.gnutella.downloader.IncompleteFileManager
All Implemented Interfaces:
java.io.Serializable

public class IncompleteFileManager
extends java.lang.Object
implements java.io.Serializable

A repository of temporary filenames. Gives out file names for temporary files, ensuring that two duplicate files always get the same name. This enables smart resumes across hosts. Also keeps track of the blocks downloaded, for smart downloading purposes. Thread safe.

See Also:
Serialized Form

Field Summary
static java.lang.String PREVIEW_PREFIX
          The prefix added to preview copies of incomplete files.
 
Constructor Summary
IncompleteFileManager()
           
 
Method Summary
 void addEntry(java.io.File incompleteFile, VerifyingFile vf)
          Associates the incompleteFile with the VerifyingFile vf.
 java.util.Set getAllCompletedHashes(java.io.File incompleteFile)
          Returns any known hashes of the complete file associated with the given incomplete file, i.e., the hashes of incompleteFile when the download is complete.
 int getBlockSize(java.io.File incompleteFile)
           
 URN getCompletedHash(java.io.File incompleteFile)
          Returns the hash of the complete file associated with the given incomplete file, i.e., the hash of incompleteFile when the download is complete.
static java.lang.String getCompletedName(java.io.File incompleteFile)
          Returns the name of the complete file associated with the given incomplete file, i.e., what incompleteFile will be renamed to when the download completes (without path information).
static long getCompletedSize(java.io.File incompleteFile)
          Returns the size of the complete file associated with the given incomplete file, i.e., the number of bytes in the file when the download completes.
 VerifyingFile getEntry(java.io.File incompleteFile)
           
 java.io.File getFile(RemoteFileDesc rfd)
          Returns the fully-qualified temporary download file for the given file/location pair.
 java.io.File getFileForUrn(URN urn)
          Returns the file associated with the specified URN.
 boolean purge(boolean initialPurge)
          Deletes incomplete files more than INCOMPLETE_PURGE_TIME days old from disk.
 void registerAllIncompleteFiles()
          Notifies file manager about all incomplete files.
 void removeEntry(java.io.File incompleteFile)
          Removes the block and hash information for the given incomplete file.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PREVIEW_PREFIX

public static final java.lang.String PREVIEW_PREFIX
The prefix added to preview copies of incomplete files.

See Also:
Constant Field Values
Constructor Detail

IncompleteFileManager

public IncompleteFileManager()
Method Detail

purge

public boolean purge(boolean initialPurge)
Deletes incomplete files more than INCOMPLETE_PURGE_TIME days old from disk. Then removes entries in this for which there is no file on disk.

Parameters:
initialPurge - true iff this was just read from disk, i.e., if this is being called from readSnapshot() instead of getFiles(). Hashes will only be purged if initialPurge==true.
Returns:
true iff any entries were purged

getFile

public java.io.File getFile(RemoteFileDesc rfd)
Returns the fully-qualified temporary download file for the given file/location pair. The location of the file is determined by the INCOMPLETE_DIRECTORY property. For example, getFile("test.txt", 1999) may return "C:\Program Files\LimeWire\Incomplete\T-1999-Test.txt". The disk is not modified.

This method gives duplicate files the same temporary file, which is critical for resume and swarmed downloads. That is, for all rfd_i and rfd_j

      similar(rfd_i, rfd_j) <==> getFile(rfd_i).equals(getFile(rfd_j))


getFileForUrn

public java.io.File getFileForUrn(URN urn)
Returns the file associated with the specified URN. If no file matches, returns null.

Returns:
the file associated with the URN, or null if none.

removeEntry

public void removeEntry(java.io.File incompleteFile)
Removes the block and hash information for the given incomplete file. Typically this is called after incompleteFile has been deleted.

Parameters:
incompleteFile - a temporary file returned by getFile

addEntry

public void addEntry(java.io.File incompleteFile,
                     VerifyingFile vf)
Associates the incompleteFile with the VerifyingFile vf. Notifies FileManager about a new Incomplete File.


getEntry

public VerifyingFile getEntry(java.io.File incompleteFile)

getBlockSize

public int getBlockSize(java.io.File incompleteFile)

registerAllIncompleteFiles

public void registerAllIncompleteFiles()
Notifies file manager about all incomplete files.


getCompletedName

public static java.lang.String getCompletedName(java.io.File incompleteFile)
                                         throws java.lang.IllegalArgumentException
Returns the name of the complete file associated with the given incomplete file, i.e., what incompleteFile will be renamed to when the download completes (without path information). Slow; runs in linear time with respect to the number of hashes in this.

Parameters:
incompleteFile - a file returned by getFile
Returns:
the complete file name, without path
Throws:
java.lang.IllegalArgumentException - incompleteFile was not the return value from getFile

getCompletedSize

public static long getCompletedSize(java.io.File incompleteFile)
                             throws java.lang.IllegalArgumentException
Returns the size of the complete file associated with the given incomplete file, i.e., the number of bytes in the file when the download completes.

Parameters:
incompleteFile - a file returned by getFile
Returns:
the complete file size
Throws:
java.lang.IllegalArgumentException - incompleteFile was not returned by getFile

getCompletedHash

public URN getCompletedHash(java.io.File incompleteFile)
Returns the hash of the complete file associated with the given incomplete file, i.e., the hash of incompleteFile when the download is complete.

Parameters:
incompleteFile - a file returned by getFile
Returns:
a SHA1 hash, or null if unknown

getAllCompletedHashes

public java.util.Set getAllCompletedHashes(java.io.File incompleteFile)
Returns any known hashes of the complete file associated with the given incomplete file, i.e., the hashes of incompleteFile when the download is complete.

Parameters:
incompleteFile - a file returned by getFile
Returns:
a set of known hashes

toString

public java.lang.String toString()