Initial release

This commit is contained in:
Norberto Lopez
2013-04-17 04:10:03 +00:00
parent 35a729ab64
commit 97379e13a2
3 changed files with 145 additions and 0 deletions

View 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);
}
}

View 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);
}

View 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();
}
}