mirror of
https://github.com/JHUAPL/DistMaker.git
synced 2026-01-10 06:58:06 -05:00
Initial release
This commit is contained in:
66
src/distMaker/node/FileNode.java
Normal file
66
src/distMaker/node/FileNode.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package distMaker.node;
|
||||
|
||||
import glum.io.IoUtil;
|
||||
import glum.net.Credential;
|
||||
import glum.task.Task;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import distMaker.DistUtils;
|
||||
|
||||
public class FileNode implements Node
|
||||
{
|
||||
private URL rootUrl;
|
||||
private String md5sum;
|
||||
private String fileName;
|
||||
private long fileLen;
|
||||
|
||||
public FileNode(URL aRootUrl, String aFileName, String aMd5sum, long aFileLen)
|
||||
{
|
||||
rootUrl = aRootUrl;
|
||||
fileName = aFileName;
|
||||
md5sum = aMd5sum;
|
||||
fileLen = aFileLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsEqual(Node aNode)
|
||||
{
|
||||
FileNode fNode;
|
||||
|
||||
if (aNode instanceof FileNode == false)
|
||||
return false;
|
||||
|
||||
fNode = (FileNode)aNode;
|
||||
if (fNode.md5sum.equals(md5sum) == false)
|
||||
return false;
|
||||
if (fNode.fileName.equals(fileName) == false)
|
||||
return false;
|
||||
if (fNode.fileLen != fileLen)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName()
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transferContentTo(Task aTask, Credential aCredential, File dstPath)
|
||||
{
|
||||
URL srcUrl;
|
||||
File dstFile;
|
||||
|
||||
// Determine the source URL to copy the contents from
|
||||
srcUrl = IoUtil.createURL(rootUrl.toString() + "/" + fileName);
|
||||
|
||||
// Determine the file to transfer the contents to
|
||||
dstFile = new File(dstPath, fileName);
|
||||
|
||||
return DistUtils.downloadFile(aTask, srcUrl, dstFile, aCredential);
|
||||
}
|
||||
}
|
||||
26
src/distMaker/node/Node.java
Normal file
26
src/distMaker/node/Node.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package distMaker.node;
|
||||
|
||||
import glum.net.Credential;
|
||||
import glum.task.Task;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface Node
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns true, if the contents stored in aNode are equal to this Node.
|
||||
*/
|
||||
public boolean areContentsEqual(Node aNode);
|
||||
|
||||
/**
|
||||
* Returns the "file name" associated with this Node
|
||||
*/
|
||||
public String getFileName();
|
||||
|
||||
/**
|
||||
* Method to copy the contents of this node to destPath. The var, destPath, should be a folder.
|
||||
*/
|
||||
boolean transferContentTo(Task aTask, Credential aCredential, File destPath);
|
||||
|
||||
}
|
||||
53
src/distMaker/node/PathNode.java
Normal file
53
src/distMaker/node/PathNode.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package distMaker.node;
|
||||
|
||||
import glum.net.Credential;
|
||||
import glum.task.Task;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class PathNode implements Node
|
||||
{
|
||||
private URL rootUrl;
|
||||
private String fileName;
|
||||
|
||||
public PathNode(URL aRootUrl, String aFileName)
|
||||
{
|
||||
rootUrl = aRootUrl;
|
||||
fileName = aFileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsEqual(Node aNode)
|
||||
{
|
||||
PathNode pNode;
|
||||
|
||||
if (aNode instanceof PathNode == false)
|
||||
return false;
|
||||
|
||||
pNode = (PathNode)aNode;
|
||||
if (pNode.fileName.equals(fileName) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName()
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transferContentTo(Task aTask, Credential aCredential, File dstPath)
|
||||
{
|
||||
File dstDir;
|
||||
|
||||
// Determine the dest folder to create
|
||||
dstDir = new File(dstPath, fileName);
|
||||
|
||||
// Form the directory
|
||||
return dstDir.mkdirs();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user