-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHelper.java
More file actions
90 lines (67 loc) · 2.63 KB
/
Helper.java
File metadata and controls
90 lines (67 loc) · 2.63 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
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.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
public interface Helper {
String introPath = "/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/";
public static String fileContents(File file) throws IOException {
if (file.isFile()) {
StringBuilder record = new StringBuilder("");
BufferedReader br = new BufferedReader(new FileReader(file));
while (br.ready()) {
record.append((char) br.read());
}
br.close();
String s = record.toString();
return s;
} else {
String folderContents = "";
String contents[] = file.list();
for (String s : contents) {
File f = new File("/Users/lilbarbar/Desktop/Honors Topics/Programming-Git/" + s);
if (f.exists()) {
folderContents += Helper.fileContents(f);
}
}
return folderContents;
}
}
public static void writeToFile(String content, String fileName, String introPath) throws IOException {
File file = new File(introPath + fileName);
if (!file.exists()) {
file.createNewFile();
}
PrintWriter pw = new PrintWriter(file);
pw.print(content);
pw.close();
}
public static String getSHA1(String input) throws NoSuchAlgorithmException {
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();
}
public static void audit() throws FileNotFoundException { // credit for sentry for teaching me how to do a for each
// loop
// with a Hashmap
try {
PrintWriter pw = new PrintWriter("AccountAudit.txt");
String s = "";
for (HashMap.Entry<String, Double> entry : accounts.entrySet()) {
s += entry.getKey() + " " + entry.getValue() + "\n";
}
pw.print(s);
pw.close();
System.out.println("done");
} catch (Exception e) {
}
}
}