Skip to content

Commit 141465f

Browse files
committed
flag to configure printing of errors in FileController
1 parent 553c77b commit 141465f

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/main/java/com/brunoarruda/hyperdcpabe/Client.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public String toString() {
9595
private Map<String, Map<String, PublicKey>> publishedAttributes;
9696

9797
public Client() {
98-
fc = FileController.getInstance().configure(DATA_PATH);
98+
fc = FileController.getInstance().configure(DATA_PATH, false);
9999
this.server = new ServerConnection(SERVER_PORT);
100100
ObjectNode clientData = (ObjectNode) fc.loadAsJSON(getClientDirectory(), "clientData.json");
101101
if (clientData != null) {
@@ -115,7 +115,7 @@ public Client() {
115115
}
116116

117117
public Client(String networkURL, String adminName, String adminEmail, String adminPrivateKey) {
118-
fc = FileController.getInstance().configure(DATA_PATH);
118+
fc = FileController.getInstance().configure(DATA_PATH, false);
119119
this.server = new ServerConnection(SERVER_PORT);
120120
this.blockchain = new BlockchainConnection(networkURL);
121121
gp = DCPABE.globalSetup(160);
@@ -327,7 +327,6 @@ public void encrypt(String file, String policy, String[] authorities) {
327327
}
328328
AccessStructure as = AccessStructure.buildFromPolicy(policy);
329329
Message m = DCPABE.generateRandomMessage(gp);
330-
System.out.println("MESSAGE 358: " + Arrays.toString(m.getM()));
331330
CiphertextJSON ct = new CiphertextJSON(DCPABE.encrypt(m, as, gp, pks));
332331
String path = fc.getUserDirectory(user);
333332
r = new Recording(path, file, ct);
@@ -346,7 +345,6 @@ public void decrypt(String file) {
346345
Message m = null;
347346
try {
348347
m = DCPABE.decrypt(r.getCiphertext(), user.getABEKeys(), gp);
349-
System.out.println("MESSAGE 377: " + Arrays.toString(m.getM()));
350348
} catch (IllegalArgumentException e) {
351349
String msg = "Client - Could not decrypt the file %s. Attributes not Satisfying Policy Access.";
352350
System.out.println(String.format(msg, file));

src/main/java/com/brunoarruda/hyperdcpabe/io/FileController.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public final class FileController {
2626
private static final ObjectMapper mapper = new ObjectMapper();
2727

2828
private String dataFolder;
29+
private boolean printErrorsFlag;
2930

3031
private FileController() {
3132
}
@@ -34,8 +35,9 @@ public static FileController getInstance() {
3435
return INSTANCE;
3536
}
3637

37-
public FileController configure(String path) {
38+
public FileController configure(String path, boolean printErrorsFlag) {
3839
this.dataFolder = path;
40+
this.printErrorsFlag = printErrorsFlag;
3941
File dirFile = new File(path);
4042
if (!dirFile.exists() || !dirFile.isDirectory()) {
4143
dirFile.mkdirs();
@@ -74,7 +76,9 @@ public <T> void writeToDir(String path, String fileName, T obj) {
7476
try {
7577
mapper.writeValue(new File(path), obj);
7678
} catch (IOException e) {
77-
// e.printStackTrace();
79+
if (printErrorsFlag) {
80+
e.printStackTrace();
81+
}
7882
}
7983
}
8084

@@ -90,7 +94,9 @@ public <T extends Object> List<T> readAsList(String path, String file, Class<T>
9094
list.add(mapper.readValue(value, classReference));
9195
}
9296
} catch (Exception e) {
93-
e.printStackTrace();
97+
if (printErrorsFlag) {
98+
e.printStackTrace();
99+
}
94100
}
95101
return list;
96102
}
@@ -113,7 +119,9 @@ public <K extends Object, V extends Object> Map<K, V> readAsMap(String path, Str
113119
map.put((K) entry.getKey(), mapper.readValue(value, valueClass));
114120
}
115121
} catch (Exception e) {
116-
e.printStackTrace();
122+
if (printErrorsFlag) {
123+
e.printStackTrace();
124+
}
117125
}
118126
return map;
119127
}
@@ -134,9 +142,13 @@ public <T> T readFromDir(String path, String fileName, String internalPath, Clas
134142
}
135143
result = mapper.readValue(mapper.writeValueAsString(data), typeReference);
136144
} catch (JsonProcessingException e) {
137-
e.printStackTrace();
145+
if (printErrorsFlag) {
146+
e.printStackTrace();
147+
}
138148
} catch (IOException e) {
139-
e.printStackTrace();
149+
if (printErrorsFlag) {
150+
e.printStackTrace();
151+
}
140152
}
141153
return result;
142154
}
@@ -150,7 +162,9 @@ public JsonNode loadAsJSON(String path, String file) {
150162
try {
151163
obj = mapper.readTree(new File(path, file));
152164
} catch (IOException e) {
153-
// System.out.println("FileController - Could not load " + file + " inside " + path + "as a JSON object.");
165+
if (printErrorsFlag) {
166+
e.printStackTrace();
167+
}
154168
}
155169
return obj;
156170
}

0 commit comments

Comments
 (0)