-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBlob.java
More file actions
109 lines (85 loc) · 3.19 KB
/
Blob.java
File metadata and controls
109 lines (85 loc) · 3.19 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.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.io.*;
import java.util.zip.Deflater;
//with Help from Mr. Lopez, the internet, Daniel and Aidan
public class Blob {
private String pathName;
String input = "/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Objects/";
public Blob(String name) {
File objects = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Objects/");
if (!objects.exists()) {
objects.mkdir();
}
this.pathName = name;
}
public String getFileName() {
return pathName;
}
// based off Chris' code in fileTOString since his code allows me to retrieve
// multiple lines
public String fileContents() throws IOException // based off Chris' code in fileTOString since his code allows me to
// retrieve multiple lines
{
StringBuilder record = new StringBuilder("");
BufferedReader br = new BufferedReader(new FileReader(pathName));
while (br.ready()) {
record.append((char) br.read());
}
br.close();
String s = record.toString();
return s;
}
public void makeFile() throws NoSuchAlgorithmException, IOException {
String blobFileName = getSha1(fileContents());
PrintWriter pw = new PrintWriter(
"/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/Objects/" + blobFileName); // found
// // out
// // online
// // from Java Oracle
// // and Danny
// =======
// PrintWriter pw = new PrintWriter("./Objects/" + blobFileName); // found out
// online
// from Java Oracle
// Print writer makes a file while File file =
// newe File gets an already made file.
// and Danny
// I
// "C://user/bari/"
// disc
// makes a file under fileName
// <<<<<<< master
// =======
String words = fileContents();
byte[] info = StringCompressor.compressString(words); // files contain the zip compressed version of the
// // original file data instead of the actual original
// // string
// >>>>>>> master
// not sure if I did it right
pw.print(words);
pw.close(); // releases the info
System.out.println(words);
}
public static String getSha1(String input) throws NoSuchAlgorithmException { // credit to
// http://www.sha1-online.com/sha1-java/
MessageDigest mDigest = MessageDigest.getInstance("SHA1");
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
}