com.threerings.getdown.data
Class Resource

java.lang.Object
  extended by com.threerings.getdown.data.Resource

public class Resource
extends Object

Models a single file resource used by an Application.


Constructor Summary
Resource(String path, URL remote, File local, boolean unpack)
          Creates a resource with the supplied remote URL and local path.
 
Method Summary
 void clearMarker()
          Removes any "validated" marker file associated with this resource.
static String computeDigest(File target, MessageDigest md, ProgressObserver obs)
          Computes the MD5 hash of the supplied file.
 String computeDigest(MessageDigest md, ProgressObserver obs)
          Computes the MD5 hash of this resource's underlying file.
 boolean equals(Object other)
          If our path is equal, we are equal.
 void erase()
          Wipes this resource file along with any "validated" marker file that may be associated with it.
 File getLocal()
          Returns the local location of this resource.
 String getPath()
          Returns the path associated with this resource.
 URL getRemote()
          Returns the remote location of this resource.
 int hashCode()
          We hash on our path.
 boolean isMarkedValid()
          Returns true if this resource has an associated "validated" marker file.
 void markAsValid()
          Creates a "validated" marker file for this resource to indicate that its MD5 hash has been computed and compared with the value in the digest file.
 boolean shouldUnpack()
          Returns true if this resource should be unpacked as a part of the validation process.
 String toString()
          Returns a string representation of this instance.
 boolean unpack()
          Unpacks this resource file into the directory that contains it.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Resource

public Resource(String path,
                URL remote,
                File local,
                boolean unpack)
Creates a resource with the supplied remote URL and local path.

Method Detail

getPath

public String getPath()
Returns the path associated with this resource.


getLocal

public File getLocal()
Returns the local location of this resource.


getRemote

public URL getRemote()
Returns the remote location of this resource.


shouldUnpack

public boolean shouldUnpack()
Returns true if this resource should be unpacked as a part of the validation process.


computeDigest

public String computeDigest(MessageDigest md,
                            ProgressObserver obs)
                     throws IOException
Computes the MD5 hash of this resource's underlying file. Note: This is both CPU and I/O intensive.

Throws:
IOException

isMarkedValid

public boolean isMarkedValid()
Returns true if this resource has an associated "validated" marker file.


markAsValid

public void markAsValid()
                 throws IOException
Creates a "validated" marker file for this resource to indicate that its MD5 hash has been computed and compared with the value in the digest file.

Throws:
IOException - if we fail to create the marker file.

clearMarker

public void clearMarker()
Removes any "validated" marker file associated with this resource.


unpack

public boolean unpack()
Unpacks this resource file into the directory that contains it. Returns false if an error occurs while unpacking it.


erase

public void erase()
Wipes this resource file along with any "validated" marker file that may be associated with it.


equals

public boolean equals(Object other)
If our path is equal, we are equal.

Overrides:
equals in class Object

hashCode

public int hashCode()
We hash on our path.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of this instance.

Overrides:
toString in class Object

computeDigest

public static String computeDigest(File target,
                                   MessageDigest md,
                                   ProgressObserver obs)
                            throws IOException
Computes the MD5 hash of the supplied file.

Throws:
IOException


Copyright © 2013. All Rights Reserved.