-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIndex.java
More file actions
109 lines (73 loc) · 2.67 KB
/
Index.java
File metadata and controls
109 lines (73 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
public class Index {
File tree;
String startPath = "/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/";
HashMap<String, String> blobs = new HashMap();
File objects = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Objects/");
File index = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Objects/Index");
public Index() throws IOException {
if (!objects.exists()) {
objects.mkdir();
}
if (!index.exists()) {
index.createNewFile();
}
index.createNewFile();
PrintWriter pw = new PrintWriter(index);
String words = "";
pw.print(words);
pw.close();
}
public void init() throws IOException {
File objects = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Tree-Objects");
if (!objects.exists()) {
objects.mkdirs();
}
}
public void add(String name) throws NoSuchAlgorithmException, IOException {
Blob blob = new Blob(name);
blob.makeFile();
blobs.put(blob.getFileName(), blob.getSha1(blob.fileContents()));
printBlobs();
}
public void remove(String fileName) {
blobs.remove(fileName);
printBlobs();
}
public void printBlobs() {
try {
PrintWriter pw = new PrintWriter(
"/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Tree-Objects/Index");
String s = "";
for (HashMap.Entry<String, String> entry : blobs.entrySet()) {
File file = new File(startPath + entry.getKey());
if (!file.isDirectory()) {
s += "Blob : " + entry.getValue() + " : " + entry.getKey() + "\n";
} else {
s += "Tree : " + entry.getValue() + " : " + entry.getKey() + "\n";
}
}
pw.print(s);
pw.close();
} catch (Exception e) {
}
}
public static String indexContents() throws Exception {
StringBuilder record = new StringBuilder("");
BufferedReader br = new BufferedReader(
new FileReader("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Tree-Objects/Index"));
while (br.ready()) {
record.append((char) br.read());
}
br.close();
String s = record.toString();
return s;
}
}