com.limegroup.gnutella
Class FileDesc

java.lang.Object
  extended bycom.limegroup.gnutella.FileDesc
All Implemented Interfaces:
AlternateLocationCollector
Direct Known Subclasses:
IncompleteFileDesc

public class FileDesc
extends java.lang.Object
implements AlternateLocationCollector

This class contains data for an individual shared file. It also provides various utility methods for checking against the encapsulated data.

Constructing a FileDesc is usually done in two steps, which allows the caller to avoid holding a lock when hashing a file:

    Set urns=FileDesc.calculateAndCacheURN(file);
    FileDesc fd=new FileDesc(file, urns, index);
 


Constructor Summary
FileDesc(java.io.File file, java.util.Set urns, int index)
          Constructs a new FileDesc instance from the specified File class and the associated urns.
 
Method Summary
 boolean add(AlternateLocation al)
          Implements AlternateLocationCollector interface.
 int addAll(AlternateLocationCollection alc)
          Implements the AlternateLocationCollector interface.
 void addLimeXMLDocument(LimeXMLDocument doc)
          Adds a LimeXMLDocument to this FileDesc.
 void addUrnsForSelf()
          Adds URNs for this' location to the alternate location collection.
static java.util.Set calculateAndCacheURN(java.io.File file)
          Returns the set of URNs for a file to be passed to the FileDesc constructor.
 boolean containsUrn(URN urn)
          Determine whether or not the given URN instance is contained in this FileDesc.
 java.io.InputStream createInputStream()
          Opens an input stream to the File instance for this FileDesc.
 AlternateLocationCollection getAlternateLocationCollection()
           
 int getAltLocsSize()
          Number of alternate locations this collector is holding
 int getAttemptedUploads()
           
 int getCompletedUploads()
           
 java.io.File getFile()
          Returns the File instance for this FileDesc.
 int getHitCount()
           
 int getIndex()
          Returns the index of this file in our file data structure.
 java.util.List getLimeXMLDocuments()
          Returns the LimeXMLDocuments for this FileDesc.
 java.lang.String getName()
          Returns the name of this file.
 java.lang.String getPath()
          Returns the absolute path of the file represented wrapped by this FileDesc.
 URN getSHA1Urn()
          Accessor for the SHA1 URN instance for this collection.
 long getSize()
          Returns the size of the file on disk, in bytes.
 java.util.Set getUrns()
          Returns a new Set instance containing the URNs for the this FileDesc.
 boolean hasAlternateLocations()
          Returns whether or not this AlternateLocationCollector has any alternate locations.
 boolean hasUrns()
          Returns whether or not this FileDesc has any urns.
 int incrementAttemptedUploads()
          Increase & return the new attempted uploads
 int incrementCompletedUploads()
          Increase & return the new completed uploads
 int incrementHitCount()
          Increase & return the new hit count.
 long lastModified()
          Returns the last modification time for the file according to this FileDesc instance.
 boolean remove(AlternateLocation al)
          Removes the specified location from this collection.
 boolean removeLimeXMLDocument(LimeXMLDocument toRemove)
          Removes a LimeXMLDocument from the FileDesc.
 boolean replaceLimeXMLDocument(LimeXMLDocument oldDoc, LimeXMLDocument newDoc)
          Replaces one LimeXMLDocument with another.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileDesc

public FileDesc(java.io.File file,
                java.util.Set urns,
                int index)
Constructs a new FileDesc instance from the specified File class and the associated urns.

Parameters:
file - the File instance to use for constructing the FileDesc
urns - the return value from calculateAndCacheURN(file); an unmodifiable Set of URN's.
index - the index in the FileManager
See Also:
calculateAndCacheURN
Method Detail

calculateAndCacheURN

public static java.util.Set calculateAndCacheURN(java.io.File file)
                                          throws java.io.IOException,
                                                 java.lang.InterruptedException
Returns the set of URNs for a file to be passed to the FileDesc constructor. This is done by looking it up in UrnCache or calculating it from disk. constructor. Updates the UrnCache.

Returns:
an unmodifiable Set of URN. If the calling thread is interrupted while executing this, returns an empty set.
Throws:
NullPointerException - if the file argument is null
IllegalArgumentException - if the file argument denotes a file that is not a file on disk
IOException - if there is an IO error calculating the URN
InterruptedException - if the thread that calculates the URN is interrupted
java.io.IOException
java.lang.InterruptedException

hasUrns

public boolean hasUrns()
Returns whether or not this FileDesc has any urns.

Returns:
true if this FileDesc has urns, false otherwise

getIndex

public int getIndex()
Returns the index of this file in our file data structure.

Returns:
the index of this file in our file data structure

getSize

public long getSize()
Returns the size of the file on disk, in bytes.

Returns:
the size of the file on disk, in bytes

getName

public java.lang.String getName()
Returns the name of this file.

Returns:
the name of this file

lastModified

public long lastModified()
Returns the last modification time for the file according to this FileDesc instance.

Returns:
the modification time for the file

getSHA1Urn

public URN getSHA1Urn()
Description copied from interface: AlternateLocationCollector
Accessor for the SHA1 URN instance for this collection.

Specified by:
getSHA1Urn in interface AlternateLocationCollector
Returns:
the SHA1 URN for this collection

getFile

public java.io.File getFile()
Returns the File instance for this FileDesc.

Returns:
the File instance for this FileDesc

getUrns

public java.util.Set getUrns()
Returns a new Set instance containing the URNs for the this FileDesc. The Set instance returned is immutable.

Returns:
a new Set of URNs for this FileDesc

getPath

public java.lang.String getPath()
Returns the absolute path of the file represented wrapped by this FileDesc.

Returns:
the absolute path of the file

addLimeXMLDocument

public void addLimeXMLDocument(LimeXMLDocument doc)
Adds a LimeXMLDocument to this FileDesc.


replaceLimeXMLDocument

public boolean replaceLimeXMLDocument(LimeXMLDocument oldDoc,
                                      LimeXMLDocument newDoc)
Replaces one LimeXMLDocument with another.


removeLimeXMLDocument

public boolean removeLimeXMLDocument(LimeXMLDocument toRemove)
Removes a LimeXMLDocument from the FileDesc.


getLimeXMLDocuments

public java.util.List getLimeXMLDocuments()
Returns the LimeXMLDocuments for this FileDesc.


getAlternateLocationCollection

public AlternateLocationCollection getAlternateLocationCollection()
Returns:
the AlternateLocationCollection for this FileDesc instance, which can be empty, or null if it is not initialized

addUrnsForSelf

public void addUrnsForSelf()
Adds URNs for this' location to the alternate location collection. This should be called whenever the address changes.


add

public boolean add(AlternateLocation al)
Implements AlternateLocationCollector interface.

Specified by:
add in interface AlternateLocationCollector
Throws:
NullPointerException - if the argument is null
IllegalArgumentException - if the alternate location has a different SHA1 than this file, or if its sha1 is null

remove

public boolean remove(AlternateLocation al)
Description copied from interface: AlternateLocationCollector
Removes the specified location from this collection.

Specified by:
remove in interface AlternateLocationCollector
Throws:
NullPointerException - if the argument is null
IllegalArgumentException - if the alternate location has a different SHA1 than this file, or if its sha1 is null

addAll

public int addAll(AlternateLocationCollection alc)
Implements the AlternateLocationCollector interface. Adds the specified AlternateLocationCollection to this collection.

Specified by:
addAll in interface AlternateLocationCollector
Parameters:
alc - the AlternateLocationCollection to add
Throws:
NullPointerException - if alc is null
IllegalArgumentException - if the SHA1 of the collection to add does not match the collection of this

hasAlternateLocations

public boolean hasAlternateLocations()
Description copied from interface: AlternateLocationCollector
Returns whether or not this AlternateLocationCollector has any alternate locations.

Specified by:
hasAlternateLocations in interface AlternateLocationCollector
Returns:
true if this AlternateLocationCollector has 1 or more alternate locations, false otherwise

getAltLocsSize

public int getAltLocsSize()
Description copied from interface: AlternateLocationCollector
Number of alternate locations this collector is holding

Specified by:
getAltLocsSize in interface AlternateLocationCollector

containsUrn

public boolean containsUrn(URN urn)
Determine whether or not the given URN instance is contained in this FileDesc.

Parameters:
urn - the URN instance to check for
Returns:
true if the URN is a valid URN for this file, false otherwise

incrementHitCount

public int incrementHitCount()
Increase & return the new hit count.

Returns:
the new hit count

getHitCount

public int getHitCount()
Returns:
the current hit count

incrementAttemptedUploads

public int incrementAttemptedUploads()
Increase & return the new attempted uploads

Returns:
the new attempted upload count

getAttemptedUploads

public int getAttemptedUploads()
Returns:
the current attempted uploads

incrementCompletedUploads

public int incrementCompletedUploads()
Increase & return the new completed uploads

Returns:
the new completed upload count

getCompletedUploads

public int getCompletedUploads()
Returns:
the current completed uploads

createInputStream

public java.io.InputStream createInputStream()
                                      throws java.io.FileNotFoundException
Opens an input stream to the File instance for this FileDesc.

Returns:
an InputStream to the File instance
Throws:
FileNotFoundException - if the file represented by the File instance could not be found
java.io.FileNotFoundException

toString

public java.lang.String toString()