|
1 |
| package org.proteomecommons.tranche.util; |
|
2 |
| |
|
3 |
| import java.io.BufferedOutputStream; |
|
4 |
| import java.io.File; |
|
5 |
| import java.io.FileOutputStream; |
|
6 |
| import org.apache.tools.tar.TarEntry; |
|
7 |
| import org.apache.tools.tar.TarOutputStream; |
|
8 |
| import org.proteomecommons.tranche.flatfile.DataBlockUtil; |
|
9 |
| import org.proteomecommons.tranche.flatfile.DataDirectoryConfiguration; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| public class MigrateOldData { |
|
16 |
| |
|
17 |
0
| public static void main(String[] args) throws Exception {
|
|
18 |
| |
|
19 |
0
| if (args.length < 3) {
|
|
20 |
0
| System.out.println("Usage: <zip dir> <old data dir> <new data dir> ");
|
|
21 |
0
| return;
|
|
22 |
| } |
|
23 |
| |
|
24 |
0
| File zipDirectory = new File(args[0]);
|
|
25 |
0
| File oldDataDirectory = new File(args[1]);
|
|
26 |
0
| System.out.println("ZIP Dir: "+zipDirectory);
|
|
27 |
0
| System.out.println("OLD Data Dir: "+oldDataDirectory);
|
|
28 |
| |
|
29 |
| |
|
30 |
0
| DataBlockUtil dbu = new DataBlockUtil();
|
|
31 |
| |
|
32 |
| |
|
33 |
0
| for (int i=2;i<args.length;i++) {
|
|
34 |
0
| DataDirectoryConfiguration ddc = new DataDirectoryConfiguration(args[i], Long.MAX_VALUE);
|
|
35 |
0
| dbu.add(ddc);
|
|
36 |
0
| System.out.println("Loading DDC: "+args[i]);
|
|
37 |
| } |
|
38 |
| |
|
39 |
| |
|
40 |
0
| File[] firstLevel = oldDataDirectory.listFiles();
|
|
41 |
0
| for (int i=0;i<firstLevel.length;i++) {
|
|
42 |
| |
|
43 |
0
| File zipFile = new File(zipDirectory, firstLevel[i].getName()+".tar");
|
|
44 |
0
| FileOutputStream fos = new FileOutputStream(zipFile);
|
|
45 |
0
| BufferedOutputStream bos = new BufferedOutputStream(fos);
|
|
46 |
0
| TarOutputStream tos = new TarOutputStream(bos);
|
|
47 |
| |
|
48 |
0
| tos.setLongFileMode(2);
|
|
49 |
| |
|
50 |
0
| File[] secondLevel = firstLevel[i].listFiles();
|
|
51 |
0
| for (int j=0;j<secondLevel.length;j++) {
|
|
52 |
| |
|
53 |
0
| File[] dirs = secondLevel[j].listFiles();
|
|
54 |
0
| for (int k=0;k<dirs.length;k++) {
|
|
55 |
| |
|
56 |
0
| BigHash hash = BigHash.createHashFromString(dirs[k].getName());
|
|
57 |
| |
|
58 |
0
| File data = new File(dirs[k], "data");
|
|
59 |
0
| if (data.exists()) {
|
|
60 |
| |
|
61 |
0
| byte[] bytes = IOUtil.getBytes(data);
|
|
62 |
| |
|
63 |
0
| dbu.addData(hash, bytes);
|
|
64 |
| |
|
65 |
| |
|
66 |
0
| String name = firstLevel[i].getName()+ "/" + secondLevel[j].getName() + "/" + dirs[k].getName()+"/data";
|
|
67 |
0
| System.out.println("Adding: "+name);
|
|
68 |
0
| TarEntry te = new TarEntry(name);
|
|
69 |
0
| te.setSize(bytes.length);
|
|
70 |
0
| tos.putNextEntry(te);
|
|
71 |
0
| tos.write(bytes);
|
|
72 |
0
| tos.closeEntry();
|
|
73 |
| } |
|
74 |
| |
|
75 |
0
| File metaData = new File(dirs[k], "metaData");
|
|
76 |
0
| if (metaData.exists()) {
|
|
77 |
| |
|
78 |
0
| byte[] bytes = IOUtil.getBytes(metaData);
|
|
79 |
| |
|
80 |
0
| dbu.addMetaData(hash, bytes);
|
|
81 |
| |
|
82 |
| |
|
83 |
0
| String name = firstLevel[i].getName()+ "/" + secondLevel[j].getName() + "/" + dirs[k].getName()+"/metaData";
|
|
84 |
0
| System.out.println("Adding: "+name);
|
|
85 |
0
| TarEntry ze = new TarEntry(name);
|
|
86 |
0
| ze.setSize(bytes.length);
|
|
87 |
0
| tos.putNextEntry(ze);
|
|
88 |
0
| tos.write(bytes);
|
|
89 |
0
| tos.closeEntry();
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| } |
|
93 |
| |
|
94 |
0
| tos.flush();
|
|
95 |
0
| tos.finish();
|
|
96 |
0
| bos.flush();
|
|
97 |
0
| fos.flush();
|
|
98 |
0
| tos.close();
|
|
99 |
0
| bos.close();
|
|
100 |
0
| fos.close();
|
|
101 |
0
| System.out.println("Finished "+i+" out of "+firstLevel.length+": "+zipFile);
|
|
102 |
| } |
|
103 |
| } |
|
104 |
| } |