Skip to content

Commit 2fbe82d

Browse files
committed
Java I/O: Context-Specific Deserialization Filters
1 parent 565a28f commit 2fbe82d

File tree

1 file changed

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

1 file changed

+6
-9
lines changed

Diff for: Chapter06/P131_ObjectToByteArraySer/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 byte[] objectToBytes(Serializable obj) throws IOException {
18-
19-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
17+
public static byte[] objectToBytes(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 baos.toByteArray();
22+
23+
return baos.toByteArray();
24+
}
2825
}
2926

3027
public static Object bytesToObject(byte[] bytes)

0 commit comments

Comments
 (0)