Apply formatting
[proteocache.git] / engine / compbio / engine / archive / ArchivedJob.java
1 package compbio.engine.archive;
2
3 import java.io.FileOutputStream;
4 import java.io.IOException;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.nio.channels.Channels;
8 import java.nio.channels.ReadableByteChannel;
9 import java.nio.file.Paths;
10 import java.nio.file.Files;
11 import java.util.List;
12
13 import compbio.engine.ProteoCachePropertyHelperManager;
14 import compbio.util.PropertyHelper;
15
16 public class ArchivedJob {
17         String path;
18         String id;
19         String jobfilename;
20         int filesize;
21         List<String> files;
22         private static final PropertyHelper ph = ProteoCachePropertyHelperManager.getPropertyHelper();
23
24         public ArchivedJob(String id) {
25                 this.id = id;
26                 jobfilename = id + ".tar.gz";
27         }
28
29         public boolean copyArchiveFromWeb(String webpath) throws IOException, MalformedURLException {
30                 URL website = new URL(webpath);
31                 ReadableByteChannel rbc = Channels.newChannel(website.openStream());
32                 FileOutputStream fos = new FileOutputStream(path);
33                 fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
34                 fos.close();
35                 return true;
36         }
37
38         public String prepareJobArchiveToWeb() throws IOException {
39                 String resultpath = ph.getProperty("archive.web.dir");
40                 String thefile = ph.getProperty("archive.path") + '/' + jobfilename;
41                 String finalpath = ProteoCachePropertyHelperManager.getLocalPath() + resultpath + '/' + jobfilename;
42                 if (Files.isReadable(Paths.get(finalpath))) {
43                         Files.delete(Paths.get(finalpath));
44                 }
45                 if (Files.isReadable(Paths.get(thefile))) {
46                         Files.copy(Paths.get(thefile), Paths.get(finalpath));
47                         return resultpath + '/' + jobfilename;
48                 }
49                 return null;
50         }
51
52         public boolean copyArchiveLocaly(String localpath) throws IOException {
53                 Files.copy(Paths.get(localpath), Paths.get(path));
54                 return true;
55         }
56
57         public void setArchivePath(String path) {
58                 this.path = path;
59         }
60
61         public int getSize() {
62                 return filesize;
63         }
64
65         public List<String> unpack() {
66                 if (null != files) {
67
68                 }
69                 return files;
70         }
71 }