-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
47 lines (36 loc) · 1.26 KB
/
Tree.java
File metadata and controls
47 lines (36 loc) · 1.26 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Tree {
private File tree;
String record;
public Tree() throws IOException {
File file = new File("Tree");
if (!file.exists())
file.createNewFile();
}
public void add(String fileName) throws IOException {
File fileToAdd = new File(fileName);
if (!fileToAdd.exists()) {
String isTree = fileName.substring(0, 6);
if (!isTree.equals("tree: ")) {
throw new FileNotFoundException("Invalid file to add");
}
}
if (fileToAdd.exists()) {
String fileContents = Blob.readFile(fileToAdd);
String hashOfFile = sha1(fileContents);
String newEntryForTree = "blob: " + hashOfFile + " : " + fileName;
// write the entry to the tree
Blob.writeToFile(fileName, fileContents); // write to file and a read to file method- call to it **
}
else {
String newFolderEntryForTree = fileName;
// String fileContents;
Blob.writeToFile(fileName, fileContents);
}
}
public void remove(String target) throws IOException {
Arraylist<String>
}
}