Skip to content

Commit b37a84f

Browse files
committed
Java I/O: Context-Specific Deserialization Filters
1 parent 28fed4a commit b37a84f

File tree

1 file changed

+6
-9
lines changed
  • Chapter06/P132_ObjectToStringSer/src/main/java/modern/challenge

1 file changed

+6
-9
lines changed

Chapter06/P132_ObjectToStringSer/src/main/java/modern/challenge/Converters.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ private Converters() {
1414
throw new AssertionError("Cannot be instantiated");
1515
}
1616

17-
public static String objectToString(Serializable obj) throws IOException {
18-
19-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
17+
public static String objectToString(Serializable obj) throws IOException {
2018

21-
try ( ObjectOutputStream ois = new ObjectOutputStream(baos)) {
19+
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream();
20+
ObjectOutputStream ois = new ObjectOutputStream(baos)) {
2221
ois.writeObject(obj);
23-
}
24-
25-
baos.close();
26-
27-
return Base64.getEncoder().encodeToString(baos.toByteArray());
22+
23+
return Base64.getEncoder().encodeToString(baos.toByteArray());
24+
}
2825
}
2926

3027
public static Object stringToObject(String obj)

0 commit comments

Comments
 (0)